Search in sources :

Example 1 with MapServer

use of de.fhg.igd.mapviewer.server.MapServer 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)

Example 2 with MapServer

use of de.fhg.igd.mapviewer.server.MapServer in project hale by halestudio.

the class ConfigurationMapServerFactory method createExtensionObject.

/**
 * @see AbstractConfigurationFactory#createExtensionObject()
 */
@Override
public MapServer createExtensionObject() throws Exception {
    MapServer server = super.createExtensionObject();
    // set name
    server.setName(getDisplayName());
    // configure map server
    IConfigurationElement[] properties = conf.getChildren();
    for (IConfigurationElement property : properties) {
        // $NON-NLS-1$
        String name = property.getAttribute("name");
        // $NON-NLS-1$
        String value = property.getAttribute("value");
        BeanUtils.setProperty(server, name, value);
    }
    return server;
}
Also used : MapServer(de.fhg.igd.mapviewer.server.MapServer) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 3 with MapServer

use of de.fhg.igd.mapviewer.server.MapServer in project hale by halestudio.

the class MapFileServerFactory method loadServer.

/**
 * Load a map file server with the given name
 *
 * @param name the server name
 * @return the map server or null
 */
private MapServer loadServer(String name) {
    String filename = mapFiles.get(name, null);
    if (filename == null) {
        mapFiles.remove(name);
    } else {
        File file = new File(filename);
        if (file.exists()) {
            TileProvider tp;
            try {
                tp = MapFileTileProvider.createMapFileTileProvider(file);
                MapServer server = new TileProviderMapServer(tp);
                server.setName(name);
                prefServers.put(server, name);
                return server;
            } catch (MalformedURLException e) {
                log.error("Invalid file name", e);
            } catch (IOException e) {
                log.error("Error loading map file", e);
            }
        } else {
            log.info("Map file not found, removing map: " + filename);
        }
    }
    return null;
}
Also used : TileProviderMapServer(de.fhg.igd.mapviewer.server.TileProviderMapServer) MalformedURLException(java.net.MalformedURLException) MapServer(de.fhg.igd.mapviewer.server.MapServer) TileProviderMapServer(de.fhg.igd.mapviewer.server.TileProviderMapServer) IOException(java.io.IOException) File(java.io.File) TileProvider(org.jdesktop.swingx.mapviewer.TileProvider)

Example 4 with MapServer

use of de.fhg.igd.mapviewer.server.MapServer in project hale by halestudio.

the class BasicMapKit method setTileCache.

/**
 * Set the tile cache
 *
 * @param cache the tile cache to use
 */
public void setTileCache(TileCache cache) {
    this.cache = cache;
    // re-set current map
    MapServer server = getServer();
    setServer(server, false);
}
Also used : MapServer(de.fhg.igd.mapviewer.server.MapServer)

Aggregations

MapServer (de.fhg.igd.mapviewer.server.MapServer)4 TileProviderMapServer (de.fhg.igd.mapviewer.server.TileProviderMapServer)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 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 QName (javax.xml.namespace.QName)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 GeoPosition (org.jdesktop.swingx.mapviewer.GeoPosition)1 TileProvider (org.jdesktop.swingx.mapviewer.TileProvider)1