import java.awt.Color;
import java.awt.Frame;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import javax.jcr.Node;
import org.argeo.geotools.jcr.GeoJcrMapper;
+import org.argeo.geotools.styling.StylingUtils;
import org.argeo.gis.ui.AbstractMapViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.awt.SWT_AWT;
import org.eclipse.swt.widgets.Composite;
import org.geotools.data.FeatureSource;
+import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
+import org.geotools.map.DefaultMapLayer;
+import org.geotools.map.MapLayer;
import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.styling.Style;
import org.geotools.swing.JMapPane;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
+/** Map viewer implementation based on GeoTools Swing components. */
public class SwingMapViewer extends AbstractMapViewer {
private Composite embedded;
private JMapPane mapPane;
private VersatileZoomTool versatileZoomTool;
+ private Map<String, MapLayer> mapLayers = Collections
+ .synchronizedMap(new HashMap<String, MapLayer>());
+
public SwingMapViewer(Node context, GeoJcrMapper geoJcrMapper,
Composite parent) {
super(context, geoJcrMapper);
}
@Override
- protected void addFeatureSource(String path,
- FeatureSource<SimpleFeatureType, SimpleFeature> featureSource) {
- // TODO: deal with style and rasters
- mapPane.getMapContext().addLayer(featureSource, null);
- mapPane.reset();
+ protected void addFeatureSource(String layerId,
+ FeatureSource<SimpleFeatureType, SimpleFeature> featureSource,
+ Object style) {
+ if (style == null)
+ style = StylingUtils.createLineStyle("BLACK", 1);
+
+ MapLayer mapLayer = new DefaultMapLayer(featureSource, (Style) style);
+ addMapLayer(layerId, mapLayer);
+ }
+
+ protected void addMapLayer(String layerId, MapLayer mapLayer) {
+ mapLayers.put(layerId, mapLayer);
+ mapPane.getMapContext().addLayer(mapLayer);
+ }
+
+ public void addLayer(String layerId, Collection<?> collection, Object style) {
+ if (style == null)
+ style = StylingUtils.createLineStyle("BLACK", 1);
+ MapLayer mapLayer = new DefaultMapLayer(collection, (Style) style);
+ addMapLayer(layerId, mapLayer);
+ }
+
+ public void setStyle(String layerId, Object style) {
+ mapLayers.get(layerId).setStyle((Style) style);
+ }
+
+ public void setAreaOfInterest(ReferencedEnvelope areaOfInterest) {
+ // mapPane.getMapContext().setAreaOfInterest(areaOfInterest);
+ mapPane.setDisplayArea(areaOfInterest);
}
}