Search in sources :

Example 1 with FeatureTypeInfo

use of eu.esdihumboldt.hale.io.wfs.capabilities.FeatureTypeInfo 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();
}
Also used : QName(javax.xml.namespace.QName) Color(java.awt.Color) ArrayList(java.util.ArrayList) ClippingMapServer(eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer) CustomTileMapServer(de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer) BBox(eu.esdihumboldt.hale.io.wfs.capabilities.BBox) MapServer(de.fhg.igd.mapviewer.server.MapServer) ClippingMapServer(eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer) CustomTileMapServer(de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer) GeoPosition(org.jdesktop.swingx.mapviewer.GeoPosition) FeatureTypeInfo(eu.esdihumboldt.hale.io.wfs.capabilities.FeatureTypeInfo) HashSet(java.util.HashSet)

Aggregations

MapServer (de.fhg.igd.mapviewer.server.MapServer)1 CustomTileMapServer (de.fhg.igd.mapviewer.server.tiles.CustomTileMapServer)1 BBox (eu.esdihumboldt.hale.io.wfs.capabilities.BBox)1 FeatureTypeInfo (eu.esdihumboldt.hale.io.wfs.capabilities.FeatureTypeInfo)1 ClippingMapServer (eu.esdihumboldt.hale.io.wfs.ui.getfeature.internal.ClippingMapServer)1 Color (java.awt.Color)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)1