org.geotools.map.Layer Java Examples
The following examples show how to use
org.geotools.map.Layer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeometryLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public Layer createLayer(MapContext mapContext, ClientLayerInfo clientLayerInfo) throws GeomajasException { if (!(clientLayerInfo instanceof ClientGeometryLayerInfo)) { throw new IllegalArgumentException( "GeometryLayerFactory.createLayer() should only be called using ClientGeometryLayerInfo"); } ClientGeometryLayerInfo layerInfo = (ClientGeometryLayerInfo) clientLayerInfo; LayerType layerType = layerInfo.getLayerType(); Style style = styleConverterService.convert(layerInfo.getStyle()); GeometryDirectLayer layer = new GeometryDirectLayer(style, converterService.toInternal(layerType)); for (Geometry geom : layerInfo.getGeometries()) { layer.getGeometries().add(converterService.toInternal(geom)); } layer.getUserData().put(USERDATA_KEY_SHOWING, layerInfo.isShowing()); layer.setTitle(layerInfo.getLabel()); List<RuleInfo> ruleInfos = new ArrayList<RuleInfo>(); // all rules are needed for map/legend for (FeatureTypeStyleInfo fts : layerInfo.getStyle().getFeatureTypeStyleList()) { for (RuleInfo rule : fts.getRuleList()) { ruleInfos.add(rule); } } layer.getUserData().put(USERDATA_KEY_STYLE_RULES, ruleInfos); return layer; }
Example #2
Source File: WorldPaintableLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public Layer createLayer(MapContext mapContext, ClientLayerInfo clientLayerInfo) throws GeomajasException { if (!(clientLayerInfo instanceof ClientWorldPaintableLayerInfo)) { throw new IllegalArgumentException( "WorldPaintableLayerFactory.createLayer() should only be called" + " using ClientWorldPaintableLayerInfo"); } ClientWorldPaintableLayerInfo layerInfo = (ClientWorldPaintableLayerInfo) clientLayerInfo; WorldPaintableDirectLayer layer = new WorldPaintableDirectLayer(layerInfo.getPaintables(), this); layer.getUserData().put(USERDATA_KEY_SHOWING, layerInfo.isShowing()); layer.setTitle(layerInfo.getLabel()); List<RuleInfo> ruleInfos = new ArrayList<RuleInfo>(); // all rules are needed for map/legend for (WorldPaintableInfo wp : layerInfo.getPaintables()) { if (wp.isShowInLegend()) { RuleInfo rule = new RuleInfo(); rule.getSymbolizerList().add(wp.getGeometrySymbolizerInfo()); rule.getSymbolizerList().add(wp.getLabelSymbolizerInfo()); rule.setTitle(wp.getLegendTitle()); ruleInfos.add(rule); } } layer.getUserData().put(USERDATA_KEY_STYLE_RULES, ruleInfos); return layer; }
Example #3
Source File: SvgLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public Layer createLayer(MapContext mapContent, ClientLayerInfo clientLayerInfo) throws GeomajasException { if (!(clientLayerInfo instanceof ClientSvgLayerInfo)) { throw new IllegalArgumentException( "SvgLayerFactory.createLayer() should only be called using ClientSvgLayerInfo"); } ClientSvgLayerInfo layerInfo = (ClientSvgLayerInfo) clientLayerInfo; SvgDirectLayer layer = new SvgDirectLayer(mapContent); String finalSvg; finalSvg = addAttributesToSvg(layerInfo.getSvgContent(), layerInfo.getViewBoxScreenBounds()); GraphicsNode graphicsNode = createNode(finalSvg); layer.setGraphicsNode(graphicsNode); layer.setSvgWorldBounds(new ReferencedEnvelope(converterService.toInternal(layerInfo.getViewBoxWorldBounds()), mapContent.getCoordinateReferenceSystem())); Bbox viewBox = layerInfo.getViewBoxScreenBounds(); int w = (int) viewBox.getWidth(); int h = (int) viewBox.getHeight(); int x = (int) viewBox.getX(); int y = (int) viewBox.getY(); layer.setSvgScreenBounds(new Rectangle(x, y, w, h)); layer.getUserData().put(USERDATA_KEY_SHOWING, layerInfo.isShowing()); return layer; }
Example #4
Source File: MapUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates a feature layer based on a map object. */ public static Layer createFeatureLayerFromMapObject( InternalMapObject mapObject ) { Style style = mapObject.getStyle(); SimpleFeatureType featureType = mapObject.getFeatureType(); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder( featureType ); DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); featureBuilder.add( mapObject.getGeometry() ); SimpleFeature feature = featureBuilder.buildFeature( null ); featureCollection.add( feature ); return new FeatureLayer( featureCollection, style ); }
Example #5
Source File: RasterLayerFactory.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public Layer createLayer(MapContext mapContext, ClientLayerInfo clientLayerInfo) throws GeomajasException { if (!(clientLayerInfo instanceof ClientRasterLayerInfo)) { throw new IllegalArgumentException( "RasterLayerFactory.createLayer() should only be called using ClientRasterLayerInfo"); } ClientRasterLayerInfo rasterInfo = (ClientRasterLayerInfo) clientLayerInfo; RasterLayerRasterizingInfo extraInfo = (RasterLayerRasterizingInfo) rasterInfo .getWidgetInfo(RasterLayerRasterizingInfo.WIDGET_KEY); ReferencedEnvelope areaOfInterest = mapContext.getAreaOfInterest(); final RasterLayer layer = configurationService.getRasterLayer(clientLayerInfo.getServerLayerId()); MapViewport port = mapContext.getViewport(); double rasterScale = port.getScreenArea().getWidth() / port.getBounds().getWidth(); List<RasterTile> tiles = rasterLayerService.getTiles(clientLayerInfo.getServerLayerId(), areaOfInterest.getCoordinateReferenceSystem(), areaOfInterest, rasterScale); RasterDirectLayer rasterLayer = new RasterDirectLayer(imageThreadPool, new UrlDownLoader() { @Override public InputStream getStream(String url) throws IOException { return httpService.getStream(url, layer); } }, tiles, layer.getLayerInfo().getTileWidth(), layer.getLayerInfo().getTileHeight(), extraInfo.getCssStyle()); rasterLayer.setTitle(clientLayerInfo.getLabel()); rasterLayer.getUserData().put(USERDATA_KEY_LAYER_ID, layer.getId()); rasterLayer.getUserData().put(USERDATA_KEY_SHOWING, extraInfo.isShowing()); return rasterLayer; }
Example #6
Source File: RenderingServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
public void paintMap(MapContext context, Graphics2D graphics, Map<Object, Object> hints) { List<RenderRequest> renderStack = new ArrayList<RenderRequest>(); VectorRenderRequest vectorRequest = null; for (Layer layer : context.layers()) { if (layer instanceof DirectLayer) { renderStack.add(new DirectRenderRequest(graphics, context, (DirectLayer) layer)); } else { if (vectorRequest == null) { vectorRequest = new VectorRenderRequest(graphics, context, hints); renderStack.add(vectorRequest); } vectorRequest.getMapContext().addLayer(layer); } } for (RenderRequest renderRequest : renderStack) { renderRequest.execute(); } }
Example #7
Source File: OSMFileViewer.java From gama with GNU General Public License v3.0 | 6 votes |
@Override public void saveAsCSV() { final Layer layer = mapLayerTable.getMapLayerTableViewer().getSelectedMapLayer(); if (layer == null) { return; } final HashSet<String> atts = new HashSet<>(); final String layerName = layer.getFeatureSource().getName().toString(); for (final String at : attributes.keySet()) { final String[] dec = at.split(";"); if (layerName.equals(dec[0])) { atts.add(dec[1]); } } final List<IShape> geoms = osmfile.getLayers().get(layerName); final List<String> attsOrd = new ArrayList<>(atts); Collections.sort(attsOrd); saveAsCSV(attsOrd, geoms, layerName); }
Example #8
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Called when a map layer has been removed */ @Override public void layerRemoved(final MapLayerListEvent event) { final Layer layer = event.getElement(); if (layerTable != null) { layerTable.onRemoveLayer(layer); } redrawBaseImage = true; if (content.layers().size() == 0) { clearFields(); } else { setFullExtent(); } if (!isDisposed()) { redraw(); } }
Example #9
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 6 votes |
/** * Called when a new map layer has been added. Sets the layer as selected (for queries) and, if the layer table is * being used, adds the new layer to the table. */ @Override public void layerAdded(final MapLayerListEvent event) { final Layer layer = event.getElement(); if (layerTable != null) { layerTable.onAddLayer(layer); } layer.setSelected(true); redrawBaseImage = true; final boolean atFullExtent = equalsFullExtent(getDisplayArea()); final boolean firstLayer = content.layers().size() == 1; if (firstLayer || atFullExtent) { reset(); if (firstLayer) { setCrs(layer.getBounds().getCoordinateReferenceSystem()); return; } } if (!isDisposed()) { redraw(); } }
Example #10
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Render symbol. * * @param mapContent the map content * @param styledLayer the styled layer * @param style the style */ private void renderSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) { for (Layer layer : mapContent.layers()) { mapContent.removeLayer(layer); } switch (geometryType) { case RASTER: renderRasterSymbol(mapContent, style); break; case POINT: case LINE: case POLYGON: renderVectorSymbol(mapContent, styledLayer, style); break; default: break; } wmsEnvVarValues.setMapBounds(mapBounds); EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues); }
Example #11
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Set the map context for this map pane to display * * @param content * the map context */ public void setMapContent(final MapContent content) { if (this.content != content) { if (this.content != null) { this.content.removeMapLayerListListener(this); } this.content = content; if (content != null) { this.content.addMapLayerListListener(this); this.content.addMapBoundsListener(this); // set all layers as selected by default for the info tool for (final Layer layer : content.layers()) { layer.setSelected(true); } setFullExtent(); } if (renderer != null) { renderer.setMapContent(this.content); } } }
Example #12
Source File: LayerFactoryServiceImpl.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
public Layer createLayer(MapContext mapContext, ClientLayerInfo clientLayerInfo) throws GeomajasException { for (LayerFactory factory : factories) { if (factory.canCreateLayer(mapContext, clientLayerInfo)) { return factory.createLayer(mapContext, clientLayerInfo); } } throw new RasterException(RasterException.MISSING_LAYER_FACTORY, clientLayerInfo.getLabel()); }
Example #13
Source File: HMMapframe.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void setLayer( Layer layer ) { List<Layer> layers = content.layers(); for( Layer l : layers ) { content.removeLayer(l); } content.addLayer(layer); }
Example #14
Source File: HMMapframe.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void addLayerBottom( Layer layer ) { content.addLayer(layer); int index = content.layers().indexOf(layer); content.moveLayer(index, 0); getMapPane().layerMoved(new MapLayerListEvent(content, layer, 0)); }
Example #15
Source File: ImageGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private org.geotools.ows.wms.Layer getWMSLayer( WebMapServer server, String layerName ) { for( org.geotools.ows.wms.Layer layer : server.getCapabilities().getLayerList() ) { if (layerName.equals(layer.getName())) { return layer; } } throw new IllegalArgumentException("Could not find layer " + layerName); }
Example #16
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 5 votes |
void onHideAllLayers() { if (pane != null && pane.getMapContent() != null) { for (final Layer layer : pane.getMapContent().layers()) { if (layer.isVisible()) { layer.setVisible(false); } } mapLayerTableViewer.refresh(); pane.redraw(); } }
Example #17
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Handle a ListDataEvent signallying a drag-reordering of the map layers. The event is published by the list model * after the layers have been reordered there. * * @param ev * the event */ void moveLayer(final int delta) { final Layer selectedMapLayer = mapLayerTableViewer.getSelectedMapLayer(); if (selectedMapLayer == null) { return; } final List<Layer> layersList = mapLayerTableViewer.getLayersList(); final MapContent mapContent = pane.getMapContent(); final int contextIndex = mapContent.layers().indexOf(selectedMapLayer); final int viewerIndex = layersList.indexOf(selectedMapLayer); final int newViewerIndex = viewerIndex + delta; if (newViewerIndex < 0 || newViewerIndex > layersList.size() - 1) { return; } /* * MapLayerTable stores layers in the reverse order to DefaultMapContext (see comment in javadocs for this * class) */ final int newContextIndex = contextIndex - delta; if (newContextIndex < 0 || newContextIndex > mapContent.layers().size() - 1) { return; } if (contextIndex != newContextIndex) { mapContent.moveLayer(contextIndex, newContextIndex); pane.redraw(); Collections.swap(layersList, viewerIndex, newViewerIndex); mapLayerTableViewer.refresh(); } }
Example #18
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public void dataSourceAboutToUnloaded(DataStore dataStore) { if (dataStore == null) { return; } MapContent mapContent = mapPane.getMapContent(); if (mapContent != null) { // Remove all layers for (Layer layer : mapContent.layers()) { mapContent.removeLayer(layer); } } }
Example #19
Source File: RenderPanelImpl.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Render vector map. * * @param features the results * @param imageSize the image size * @param style the style * @param dpi the dpi */ private void renderVectorMap( FeatureSource<SimpleFeatureType, SimpleFeature> features, Rectangle imageSize, Style style, int dpi) { List<Layer> layerList = new ArrayList<>(); if (style != null) { FeatureLayer featureLayer = new FeatureLayer(features, style); layerList.add(featureLayer); } boolean hasGeometry = false; ReferencedEnvelope bounds = null; if (features != null) { bounds = calculateBounds(); wmsEnvVarValues.setMapBounds(bounds); EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues); if (features.getSchema() != null) { hasGeometry = (features.getSchema().getGeometryDescriptor() != null); } } internalRenderMap(layerList, bounds, imageSize, hasGeometry, dpi); }
Example #20
Source File: MaplayerTableViewer.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Show a style dialog to create a new Style for the layer * * @param layer * the layer to be styled * @throws IOException */ private void doSetStyle(final Layer layer) throws IOException { if (layer instanceof StyleLayer) { final StyleLayer styleLayer = (StyleLayer) layer; final Style style = SimpleConfigurator.showDialog(this.getTable().getShell(), layer); if (style != null) { styleLayer.setStyle(style); } } }
Example #21
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Set the map pane that the MapLayerTable will service. * * @param pane * the map pane */ public void setMapPane(final SwtMapPane pane) { this.pane = pane; mapLayerTableViewer.clear(); pane.setMapLayerTable(this); mapLayerTableViewer.setPane(pane); final MapContent mapContent = pane.getMapContent(); final List<Layer> layers = mapContent.layers(); for (final Layer mapLayer : layers) { mapLayerTableViewer.addLayer(mapLayer); } }
Example #22
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 5 votes |
void onShowAllLayers() { if (pane != null && pane.getMapContent() != null) { for (final Layer layer : pane.getMapContent().layers()) { if (!layer.isVisible()) { layer.setVisible(true); } } mapLayerTableViewer.refresh(); pane.redraw(); } }
Example #23
Source File: SimpleConfigurator.java From gama with GNU General Public License v3.0 | 4 votes |
public static Style showDialog(final Shell parent, final Layer layer) throws IOException { final SimpleFeatureSource featureSource = (SimpleFeatureSource) layer.getFeatureSource(); final Style style = layer.getStyle(); showDialog(parent, featureSource, style); return null; }
Example #24
Source File: HMMapframe.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public void addLayer( Layer layer ) { content.addLayer(layer); }
Example #25
Source File: DistributedRenderCallback.java From geowave with Apache License 2.0 | 4 votes |
@Override public Layer beforeLayer(final WMSMapContent mapContent, final Layer layer) { // sanity check the style if ((layer instanceof FeatureLayer) && (layer.getStyle() != null) && (layer.getStyle().featureTypeStyles() != null) && !layer.getStyle().featureTypeStyles().isEmpty()) { final Style layerStyle = layer.getStyle(); final FeatureTypeStyle style = layerStyle.featureTypeStyles().get(0); // check if their is a DistributedRender rendering // transformation if ((style instanceof ProcessFunction) && (style.getTransformation() != null) && (((ProcessFunction) style.getTransformation()).getName() != null) && ((ProcessFunction) style.getTransformation()).getName().equals( DistributedRenderProcess.PROCESS_NAME)) { // if their is a DistributedRender transformation, we need // to provide more information that can only be found final DuplicatingStyleVisitor cloner = new DuplicatingStyleVisitor(); layerStyle.accept(cloner); layer.getQuery().getHints().put( DistributedRenderProcess.OPTIONS, new DistributedRenderOptions(wms, mapContent, layerStyle)); // now that the options with the distributed render style // have been set the original style will be used with // distributed rendering // now, replace the style with a direct raster symbolizer, // so the GridCoverage result of the distributed rendering // process is directly rendered to the map in place of the // original style final Style directRasterStyle = (Style) cloner.getCopy(); directRasterStyle.featureTypeStyles().clear(); Processors.addProcessFactory(new InternalProcessFactory()); directRasterStyle.featureTypeStyles().add( getDirectRasterStyle( layer.getFeatureSource().getSchema().getGeometryDescriptor().getLocalName(), DistributedRenderProcessUtils.getRenderingProcess())); ((FeatureLayer) layer).setStyle(directRasterStyle); } } return layer; }
Example #26
Source File: RenderPanelImpl.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Internal render map. * * @param layers the layers * @param bounds the bounds * @param imageSize the image size * @param hasGeometry the has geometry * @param dpi the dpi */ private void internalRenderMap( List<Layer> layers, ReferencedEnvelope bounds, Rectangle imageSize, boolean hasGeometry, int dpi) { MapContent map = new MapContent(); map.addLayers(layers); try { Map<Object, Object> hints = new HashMap<>(); if (OVERRIDE_DPI) { hints.put(StreamingRenderer.DPI_KEY, dpi); } // This ensures all the labelling is cleared hints.put(StreamingRenderer.LABEL_CACHE_KEY, new LabelCacheImpl()); renderer.setRendererHints(hints); renderer.setMapContent(map); BufferedImage image = new BufferedImage( imageSize.width, imageSize.height, BufferedImage.TYPE_INT_ARGB); Graphics2D graphics = image.createGraphics(); if (useAntiAlias) { graphics.setRenderingHints( new RenderingHints( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)); } try { if (!hasGeometry) { graphics.setColor(Color.BLACK); int y = imageSize.height / 2; Font font = new Font(Font.SERIF, Font.BOLD, 14); graphics.setFont(font); graphics.drawString( Localisation.getString(RenderPanelImpl.class, "RenderPanelImpl.error1"), 10, y - 14); } else { renderer.paint(graphics, imageSize, bounds); this.bImage = image; } } finally { graphics.dispose(); } } finally { map.dispose(); } }
Example #27
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 2 votes |
/** * Add a new layer to those listed in the table. This method will be called by the associated map pane automatically * as part of the event sequence when a new MapLayer is added to the pane's MapContext. * * @param layer * the map layer */ public void onAddLayer(final Layer layer) { mapLayerTableViewer.addLayer(layer); }
Example #28
Source File: MaplayerTableViewer.java From gama with GNU General Public License v3.0 | 2 votes |
/** * * @param layer * the layer to remove. */ public void removeLayer(final Layer layer) { layersList.remove(layer); refresh(); }
Example #29
Source File: MaplayerTableViewer.java From gama with GNU General Public License v3.0 | 2 votes |
/** * * @param layer * the layer to add. */ public void addLayer(final Layer layer) { layersList.add(0, layer); refresh(); }
Example #30
Source File: MapLayerComposite.java From gama with GNU General Public License v3.0 | 2 votes |
/** * Remove a layer from those listed in the table. This method will be called by the associated map pane * automatically as part of the event sequence when a new MapLayer is removed from the pane's MapContext. * * @param layer * the map layer */ public void onRemoveLayer(final Layer layer) { mapLayerTableViewer.removeLayer(layer); }