use of de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer in project hale by halestudio.
the class BBOXPage method updateMap.
/**
* Update the map (i.e. set the map server).
*
* @param caps the WFS capabilities
*/
private void updateMap(WFSCapabilities caps) {
CustomTileMapServer tileServer = new CustomTileMapServer();
// use Stamen Terrain as default map here
tileServer.setUrlPattern("http://tile.stamen.com/terrain/{z}/{x}/{y}.jpg");
tileServer.setAttributionText("Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under CC BY SA.");
tileServer.setZoomLevel(16);
MapServer server = tileServer;
Set<GeoPosition> positions = null;
if (caps != null) {
/*
* TODO optimal solution would be using the WMS that serves the
* layers corresponding to the feature types
*/
// collect BBs from feature types
Set<QName> types = new HashSet<>(getWizard().getConfiguration().getTypeNames());
if (types.isEmpty()) {
// no features will be selected
} else {
List<BBox> bbs = new ArrayList<>();
for (QName type : types) {
FeatureTypeInfo info = caps.getFeatureTypes().get(type);
if (info != null && info.getWgs84BBox() != null) {
bbs.add(info.getWgs84BBox());
}
}
if (!bbs.isEmpty()) {
double minX, maxX, minY, maxY;
Iterator<BBox> it = bbs.iterator();
BBox bb = it.next();
minX = bb.getX1();
minY = bb.getY1();
maxX = bb.getX2();
maxY = bb.getY2();
while (it.hasNext()) {
bb = it.next();
minX = Math.min(minX, bb.getX1());
minY = Math.min(minY, bb.getY1());
maxX = Math.max(maxX, bb.getX2());
maxY = Math.max(maxY, bb.getY2());
}
GeoPosition topLeft = new GeoPosition(minX, maxY, 4326);
GeoPosition bottomRight = new GeoPosition(maxX, minY, 4326);
Color back = mapKit.getBackground();
server = new ClippingMapServer(server, topLeft, bottomRight, new Color(back.getRed(), back.getGreen(), back.getBlue(), 170));
positions = new HashSet<>();
positions.add(topLeft);
positions.add(bottomRight);
} else {
// ignore BBs, provide full map
}
}
}
mapKit.setServer(server, true);
if (positions != null) {
try {
mapKit.zoomToPositions(positions);
} catch (Exception e) {
// ignore error
}
}
mapKit.refresh();
}
Aggregations