org.geotools.map.MapContent Java Examples
The following examples show how to use
org.geotools.map.MapContent.
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: GridCoverageNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private static GTRenderer getRenderer( File rasterFile ) { AbstractGridFormat format = GridFormatFinder.findFormat(rasterFile); AbstractGridCoverage2DReader coverageReader = format.getReader(rasterFile); MapContent mapContent = new MapContent(); try { Style rasterStyle = SldUtilities.getStyleFromFile(rasterFile); if (rasterStyle == null) { RasterSymbolizer sym = SldUtilities.sf.getDefaultRasterSymbolizer(); rasterStyle = SLD.wrapSymbolizers(sym); } GridReaderLayer layer = new GridReaderLayer(coverageReader, rasterStyle); mapContent.addLayer(layer); mapContent.getViewport().setCoordinateReferenceSystem(CrsUtilities.WGS84); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #2
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 #3
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Render vector symbol. * * @param mapContent the map content * @param styledLayer the styled layer * @param style the style */ private void renderVectorSymbol(MapContent mapContent, StyledLayer styledLayer, Style style) { FeatureSource<SimpleFeatureType, SimpleFeature> tmpFeatureList = null; if (styledLayer instanceof UserLayer) { if (userLayerFeatureListMap != null) { tmpFeatureList = userLayerFeatureListMap.get(styledLayer); } } else { tmpFeatureList = featureList; } if (tmpFeatureList != null) { mapContent.addLayer( new FeatureLayer(tmpFeatureList, (org.geotools.styling.Style) style)); try { mapPane.setDisplayArea(tmpFeatureList.getBounds()); } catch (IOException e) { ConsoleManager.getInstance().exception(this, e); } } }
Example #4
Source File: RasterizedShapefilesFolderNwwLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer(File shapeFilesFolder) { File[] shpFiles = shapeFilesFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.toLowerCase().endsWith(".shp"); } }); MapContent mapContent = new MapContent(); for (File shpFile : shpFiles) { try { SimpleFeatureCollection readFC = NwwUtilities.readAndReproject(shpFile.getAbsolutePath()); ReferencedEnvelope tmpBounds = readFC.getBounds(); if (tmpBounds.getWidth() == 0 || tmpBounds.getHeight() == 0) { System.err.println("Ignoring: " + shpFile); continue; } // if (bounds == null) { // bounds = new ReferencedEnvelope(tmpBounds); // } else { // bounds.expandToInclude(tmpBounds); // } Style style = SldUtilities.getStyleFromFile(shpFile); if (style == null) style = SLD.createSimpleStyle(readFC.getSchema()); FeatureLayer layer = new FeatureLayer(readFC, style); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #5
Source File: RasterizedFeatureCollectionLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer( SimpleFeatureCollection featureCollectionLL, Style style ) { MapContent mapContent = new MapContent(); try { FeatureLayer layer = new FeatureLayer(featureCollectionLL, style); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #6
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
@Execute public void displayMaps() throws Exception { sf = CommonFactoryFinder.getStyleFactory(GeoTools.getDefaultHints()); ff = CommonFactoryFinder.getFilterFactory(GeoTools.getDefaultHints()); sb = new StyleBuilder(sf, ff); final MapContent map = new MapContent(); map.setTitle("Maps Viewer"); addImageMosaic(map); addCoverages(map); addFeatureCollections(map); map.getViewport().setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); // Create a JMapFrame with a menu to choose the display style for the final JMapFrame frame = new JMapFrame(map); frame.setSize(1800, 1200); frame.enableStatusBar(true); frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET); frame.enableToolBar(true); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ public void windowClosing( WindowEvent e ) { frame.setVisible(false); } }); while( frame.isVisible() ) { Thread.sleep(300); } }
Example #7
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 #8
Source File: RasterizedSpatialiteLayer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private static GTRenderer getRenderer( ASpatialDb db, String tableName, int featureLimit, Style style ) { MapContent mapContent = new MapContent(); // read data and convert it to featurecollection try { long t1 = System.currentTimeMillis(); System.out.println("STARTED READING: " + tableName); String databasePath = db.getDatabasePath(); File dbFile = new File(databasePath); File parentFolder = dbFile.getParentFile(); if (style == null) { File sldFile = new File(parentFolder, tableName + ".sld"); if (sldFile.exists()) { style = SldUtilities.getStyleFromFile(sldFile); } } DefaultFeatureCollection fc = SpatialDbsImportUtils.tableToFeatureFCollection(db, tableName, featureLimit, NwwUtilities.GPS_CRS_SRID, null); long t2 = System.currentTimeMillis(); System.out.println("FINISHED READING: " + tableName + " -> " + ((t2 - t1) / 1000) + "sec"); if (style == null) { style = SLD.createSimpleStyle(fc.getSchema()); } FeatureLayer layer = new FeatureLayer(fc, style); long t3 = System.currentTimeMillis(); System.out.println("FINISHED BUILDING: " + tableName + " -> " + ((t3 - t2) / 1000) + "sec"); mapContent.addLayer(layer); } catch (Exception e) { e.printStackTrace(); } GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent(mapContent); return renderer; }
Example #9
Source File: SwtMapPane.java From gama with GNU General Public License v3.0 | 5 votes |
/** * Constructor - creates an instance of JMapPane with the given renderer and map context. * * @param renderer * a renderer object * */ public SwtMapPane(final Composite parent, final int style, final GTRenderer renderer, final MapContent content) { super(parent, style); white = getDisplay().getSystemColor(SWT.COLOR_WHITE); yellow = getDisplay().getSystemColor(SWT.COLOR_YELLOW); addListener(SWT.Paint, this); addListener(SWT.MouseDown, this); addListener(SWT.MouseUp, this); imageOrigin = new Point(0, 0); redrawBaseImage = true; setRenderer(renderer); setMapContent(content); this.addMouseListener(this); this.addMouseMoveListener(this); addControlListener(new ControlAdapter() { @Override public void controlResized(final ControlEvent e) { curPaintArea = getVisibleRect(); doSetDisplayArea(SwtMapPane.this.content.getViewport().getBounds()); } }); }
Example #10
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 #11
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 #12
Source File: ShapeFileViewer.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void init(final IEditorSite site, final IEditorInput input) throws PartInitException { setSite(site); final FileEditorInput fi = (FileEditorInput) input; file = fi.getFile(); final IPath path = fi.getPath(); final File f = path.makeAbsolute().toFile(); try { pathStr = f.getAbsolutePath(); final ShapefileDataStore store = new ShapefileDataStore(f.toURI().toURL()); store.setCharset(Charset.forName("UTF8")); content = new MapContent(); featureSource = store.getFeatureSource(); style = Utils.createStyle2(featureSource); layer = new FeatureLayer(featureSource, style); mode = determineMode(featureSource.getSchema(), "Polygon"); final List<FeatureTypeStyle> ftsList = style.featureTypeStyles(); if (ftsList.size() > 0) { fts = ftsList.get(0); } else { fts = null; } if (fts != null) { this.setFillColor(PreferencesHelper.SHAPEFILE_VIEWER_FILL.getValue(), mode, fts); this.setStrokeColor(PreferencesHelper.SHAPEFILE_VIEWER_LINE_COLOR.getValue(), mode, fts); ((StyleLayer) layer).setStyle(style); } content.addLayer(layer); } catch (final IOException e) { DEBUG.ERR("Unable to view file " + path); } this.setPartName(path.lastSegment()); setInput(input); }
Example #13
Source File: SvgDirectLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Override public void draw(Graphics2D graphics, MapContent map, MapViewport viewport) { try { AffineTransform svgToScreen = getSvgToScreen(); graphics.transform(svgToScreen); } catch (NoninvertibleTransformException e) { log.error("Could not draw svg layer"); } graphicsNode.paint(graphics); }
Example #14
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 #15
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Render raster symbol. * * @param mapContent the map content * @param style the style */ private void renderRasterSymbol(MapContent mapContent, Style style) { GridReaderLayer gridLayer = new GridReaderLayer(gridCoverage, (org.geotools.styling.Style) style); mapContent.addLayer(gridLayer); mapContent.getViewport().setBounds(gridLayer.getBounds()); if (gridCoverage != null) { mapPane.setDisplayArea(gridCoverage.getOriginalEnvelope()); } }
Example #16
Source File: MapRender.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** * Render updated style. * * @param mapContent the map content */ private void renderUpdatedStyle(MapContent mapContent) { StyledLayerDescriptor sld = SelectedSymbol.getInstance().getSld(); if (sld != null) { List<StyledLayer> styledLayerList = sld.layers(); for (StyledLayer styledLayer : styledLayerList) { List<org.geotools.styling.Style> styleList = SLDUtils.getStylesList(styledLayer); for (Style style : styleList) { renderSymbol(mapContent, styledLayer, style); } } } }
Example #17
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 5 votes |
/** {@inheritDoc}. */ @Override public void setMapContent(MapContent content) { super.setMapContent(content); if (content != null && renderer != null) { // If the new map content had layers to draw, and this pane is visible, // then the map content will already have been set with the renderer // if (renderer.getMapContent() != content) { // just check reference equality renderer.setMapContent(mapContent); } } }
Example #18
Source File: HMMapframe.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public HMMapframe( String title ) { super(); content = new MapContent(); content.setTitle(title); setMapContent(content); }
Example #19
Source File: SvgDirectLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public DirectLayerAssert(DirectLayer layer, MapContent mapContent) { super(IMAGE_CLASS_PATH); this.layer = layer; this.mapContent = mapContent; }
Example #20
Source File: SvgDirectLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
public SvgDirectLayer(MapContent mapContent) { this.mapContent = mapContent; }
Example #21
Source File: SvgDirectLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 4 votes |
private AffineTransform getSvgToWorld() { MapContent m = new MapContent(); m.getViewport().setBounds(svgWorldBounds); m.getViewport().setScreenArea(svgScreenBounds); return m.getViewport().getScreenToWorld(); }
Example #22
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void addCoverages( final MapContent map ) throws Exception { if (inRasters == null) { return; } RasterSymbolizer rasterSym = sf.createRasterSymbolizer(); ColorMap colorMap = sf.createColorMap(); for( String rasterPath : inRasters ) { GridCoverage2D readRaster = OmsRasterReader.readRaster(rasterPath); RenderedImage renderedImage = readRaster.getRenderedImage(); double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; RectIter iter = RectIterFactory.create(renderedImage, null); do { do { double value = iter.getSampleDouble(); if (value > max) { max = value; } if (value < min) { min = value; } } while( !iter.nextPixelDone() ); iter.startPixels(); } while( !iter.nextLineDone() ); // red to blue Color fromColor = Color.blue; Color midColor = Color.green; Color toColor = Color.red; Expression fromColorExpr = sb .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255)); Expression midColorExpr = sb .colorExpression(new java.awt.Color(midColor.getRed(), midColor.getGreen(), midColor.getBlue(), 255)); Expression toColorExpr = sb .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255)); Expression fromExpr = sb.literalExpression(min); Expression midExpr = sb.literalExpression(min + (max - min) / 2); Expression toExpr = sb.literalExpression(max); ColorMapEntry entry = sf.createColorMapEntry(); entry.setQuantity(fromExpr); entry.setColor(fromColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(midExpr); entry.setColor(midColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(toExpr); entry.setColor(toColorExpr); colorMap.addColorMapEntry(entry); rasterSym.setColorMap(colorMap); Style rasterStyle = SLD.wrapSymbolizers(rasterSym); GridCoverageLayer layer = new GridCoverageLayer(readRaster, rasterStyle); map.addLayer(layer); } }
Example #23
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void addFeatureCollections( MapContent map ) throws Exception { if (inVectors == null) { return; } for( String path : inVectors ) { SimpleFeatureCollection fc = OmsVectorReader.readVector(path); GeometryDescriptor geometryDescriptor = fc.getSchema().getGeometryDescriptor(); EGeometryType type = EGeometryType.forGeometryDescriptor(geometryDescriptor); File file = new File(path); Style style = SldUtilities.getStyleFromFile(file); switch( type ) { case MULTIPOLYGON: case POLYGON: if (style == null) { Stroke polygonStroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(2)); Fill polygonFill = sf.createFill(ff.literal(Color.BLUE), ff.literal(0.0)); Rule polygonRule = sf.createRule(); PolygonSymbolizer polygonSymbolizer = sf.createPolygonSymbolizer(polygonStroke, polygonFill, null); polygonRule.symbolizers().add(polygonSymbolizer); FeatureTypeStyle polygonFeatureTypeStyle = sf.createFeatureTypeStyle(); polygonFeatureTypeStyle.rules().add(polygonRule); style = sf.createStyle(); style.featureTypeStyles().add(polygonFeatureTypeStyle); style.setName("polygons"); } break; case MULTIPOINT: case POINT: if (style == null) { Mark circleMark = sf.getCircleMark(); Fill fill = sf.createFill(ff.literal(Color.RED)); circleMark.setFill(fill); // circleMark.setStroke(null); Graphic gr = sf.createDefaultGraphic(); gr.graphicalSymbols().clear(); gr.graphicalSymbols().add(circleMark); Expression size = ff.literal(6); gr.setSize(size); Rule pointRule = sf.createRule(); PointSymbolizer pointSymbolizer = sf.createPointSymbolizer(gr, null); pointRule.symbolizers().add(pointSymbolizer); FeatureTypeStyle pointsFeatureTypeStyle = sf.createFeatureTypeStyle(); pointsFeatureTypeStyle.rules().add(pointRule); style = sf.createStyle(); style.featureTypeStyles().add(pointsFeatureTypeStyle); style.setName("points"); } break; case MULTILINESTRING: case LINESTRING: if (style == null) { Stroke lineStroke = sf.createStroke(ff.literal(Color.RED), ff.literal(2)); Rule lineRule = sf.createRule(); LineSymbolizer lineSymbolizer = sf.createLineSymbolizer(lineStroke, null); lineRule.symbolizers().add(lineSymbolizer); FeatureTypeStyle lineFeatureTypeStyle = sf.createFeatureTypeStyle(); lineFeatureTypeStyle.rules().add(lineRule); style = sf.createStyle(); style.featureTypeStyles().add(lineFeatureTypeStyle); style.setName("lines"); } break; default: break; } FeatureLayer layer = new FeatureLayer(fc, style); map.addLayer(layer); } }
Example #24
Source File: OmsMapsViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private void addImageMosaic( MapContent map ) throws Exception { if (inImageMosaics != null) { RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); Style style = SLD.wrapSymbolizers(sym); final ParameterValue<Color> inTransp = AbstractGridFormat.INPUT_TRANSPARENT_COLOR.createValue(); inTransp.setValue(Color.white); final ParameterValue<Color> outTransp = ImageMosaicFormat.OUTPUT_TRANSPARENT_COLOR.createValue(); outTransp.setValue(Color.white); final ParameterValue<Color> backColor = ImageMosaicFormat.BACKGROUND_COLOR.createValue(); backColor.setValue(Color.RED); final ParameterValue<Boolean> fading = ImageMosaicFormat.FADING.createValue(); fading.setValue(true); final ParameterValue<Interpolation> interpol = ImageMosaicFormat.INTERPOLATION.createValue(); interpol.setValue(new javax.media.jai.InterpolationBilinear()); final ParameterValue<Boolean> resol = ImageMosaicFormat.ACCURATE_RESOLUTION.createValue(); resol.setValue(true); final ParameterValue<Boolean> multiThread= ImageMosaicFormat.ALLOW_MULTITHREADING.createValue(); multiThread.setValue(true); final ParameterValue<Boolean> usejai = ImageMosaicFormat.USE_JAI_IMAGEREAD.createValue(); usejai.setValue(false); final ParameterValue<double[]> bkg = ImageMosaicFormat.BACKGROUND_VALUES.createValue(); bkg.setValue(new double[]{0}); GeneralParameterValue[] gp = new GeneralParameterValue[]{inTransp, multiThread}; for( String imageMosaicPath : inImageMosaics ) { ImageMosaicReader imr = new ImageMosaicReader(new File(imageMosaicPath)); GridReaderLayer layer = new GridReaderLayer(imr, style, gp); map.addLayer(layer); } } }
Example #25
Source File: OmsCoverageViewer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void viewCoverage() throws Exception { StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); // RasterSymbolizer sym = sf.getDefaultRasterSymbolizer(); // Style rasterStyle = SLD.wrapSymbolizers(sym); StyleBuilder sB = new StyleBuilder(sf); RasterSymbolizer rasterSym = sf.createRasterSymbolizer(); ColorMap colorMap = sf.createColorMap(); RenderedImage renderedImage = raster.getRenderedImage(); double max = Double.NEGATIVE_INFINITY; double min = Double.POSITIVE_INFINITY; RectIter iter = RectIterFactory.create(renderedImage, null); do { do { double value = iter.getSampleDouble(); if (value > max) { max = value; } if (value < min) { min = value; } } while( !iter.nextPixelDone() ); iter.startPixels(); } while( !iter.nextLineDone() ); // red to blue Color fromColor = Color.blue; Color toColor = Color.red; Expression fromColorExpr = sB .colorExpression(new java.awt.Color(fromColor.getRed(), fromColor.getGreen(), fromColor.getBlue(), 255)); Expression toColorExpr = sB .colorExpression(new java.awt.Color(toColor.getRed(), toColor.getGreen(), toColor.getBlue(), 255)); Expression fromExpr = sB.literalExpression(min); Expression toExpr = sB.literalExpression(max); ColorMapEntry entry = sf.createColorMapEntry(); entry.setQuantity(fromExpr); entry.setColor(fromColorExpr); colorMap.addColorMapEntry(entry); entry = sf.createColorMapEntry(); entry.setQuantity(toExpr); entry.setColor(toColorExpr); colorMap.addColorMapEntry(entry); rasterSym.setColorMap(colorMap); Style rasterStyle = SLD.wrapSymbolizers(rasterSym); // Set up a MapContext with the two layers final MapContent map = new MapContent(); map.setTitle("Coverage Viewer"); map.addLayer(new GridCoverageLayer(raster, rasterStyle)); // Create a JMapFrame with a menu to choose the display style for the final JMapFrame frame = new JMapFrame(map); frame.setSize(800, 600); frame.enableStatusBar(true); frame.enableTool(JMapFrame.Tool.ZOOM, JMapFrame.Tool.PAN, JMapFrame.Tool.RESET); frame.enableToolBar(true); frame.setVisible(true); frame.addWindowListener(new WindowAdapter(){ public void windowClosing( WindowEvent e ) { frame.setVisible(false); } }); while( frame.isVisible() ) { Thread.sleep(300); } }
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: SwtMapPane.java From gama with GNU General Public License v3.0 | 2 votes |
/** * Get the map content associated with this map pane * * @return a live reference to the current map context */ public MapContent getMapContent() { return content; }
Example #28
Source File: MapUtils.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 2 votes |
public static BufferedImage render( InternalMap map, Integer maxWidth, Integer maxHeight ) { MapContent mapContent = new MapContent(); // Convert map objects to features, and add them to the map for ( InternalMapLayer mapLayer : map.getLayers() ) { for ( InternalMapObject mapObject : mapLayer.getMapObjects() ) { mapContent.addLayer( createFeatureLayerFromMapObject( mapObject ) ); } } // Create a renderer for this map GTRenderer renderer = new StreamingRenderer(); renderer.setMapContent( mapContent ); // Calculate image height ReferencedEnvelope mapBounds = mapContent.getMaxBounds(); double widthToHeightFactor = mapBounds.getSpan( 0 ) / mapBounds.getSpan( 1 ); int[] widthHeight = getWidthHeight( maxWidth, maxHeight, LegendSet.LEGEND_TOTAL_WIDTH, TITLE_HEIGHT, widthToHeightFactor ); //LegendSet.LEGEND_TOTAL_WIDTH; Rectangle imageBounds = new Rectangle( 0, 0, widthHeight[0], widthHeight[1] ); // Create an image and get the graphics context from it BufferedImage image = new BufferedImage( imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB ); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON ); renderer.paint( graphics, imageBounds, mapBounds ); mapContent.dispose(); return image; }
Example #29
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Creates a new map pane. Any or all arguments may be {@code null} * * @param content the map content containing the layers to display * @param executor the rendering executor to manage drawing * @param renderer the renderer to use for drawing layers */ public SLDMapPane(MapContent content, RenderingExecutor executor, GTRenderer renderer) { super(content, executor); doSetRenderer(renderer); }
Example #30
Source File: SLDMapPane.java From sldeditor with GNU General Public License v3.0 | 2 votes |
/** * Creates a new map pane. * * @param content the map content containing the layers to display (may be {@code null}) */ public SLDMapPane(MapContent content) { this(content, null, null); }