public void testLabelLineOrientation() throws Exception { Style style = RendererBaseTest.loadStyle(this, "textLineOrientation.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs, style); renderer.setContext(mc); RendererBaseTest.showRender("Lines with circl stroke", renderer, TIME, bounds); } }
/** Test DefaultMapContext handles layers that return null bounds. */ @Test public void testNPELayerBounds() throws IOException { MapLayer mapLayerBoundsNull = new MapLayer( new Layer() { public ReferencedEnvelope getBounds() { return null; } }); DefaultMapContext mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); mapContext.addLayer(mapLayerBoundsNull); ReferencedEnvelope layerBounds = mapContext.getLayerBounds(); assertNull(layerBounds); ReferencedEnvelope maxBounds = mapContext.getMaxBounds(); assertNotNull(maxBounds); assertEquals(DefaultGeographicCRS.WGS84, maxBounds.getCoordinateReferenceSystem()); assertTrue(maxBounds.isEmpty()); } }
/** * Remove the given layer from this context, if present, and trigger a {@linkplain * MapLayerListEvent} * * @param layer the layer to be removed * @return true if the layer was present; false otherwise */ public boolean removeLayer(MapLayer layer) { int index = indexOf(layer); // getLayerBounds(); if (index == -1) { return false; } else { removeLayer(index); return true; } }
@Test public void testDispose() { DefaultMapContext mapContext = new DefaultMapContext(); mapContext.dispose(); mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); mapContext.dispose(); }
/** * Add the given feature source as a new layer to the end of the list of layers held by this * context and trigger a {@linkplain MapLayerListEvent}. This is a convenience method equivalent * to {@linkplain #addLayer}(new DefaultMapLayer(featureSource, style). * * <p>If a coordinate reference system has not been set for the context an attempt is made to * retrieve one from the new layer and use that as the context's CRS. * * <p>If {@code style} is null, a default style is created using {@linkplain * SLD#createSimpleStyle(org.opengis.feature.simple.SimpleFeatureType)}. * * @param featureSource the source of the features for the new layer * @param style a Style object to be used in rendering this layer. */ public void addLayer(FeatureSource featureSource, Style style) { // checkCRS(featureSource); Style layerStyle = checkStyle(style, featureSource.getSchema()); addLayer(new DefaultMapLayer(featureSource, layerStyle, "")); }
@Override protected void setUp() throws Exception { // setup data File property = new File(TestData.getResource(this, "square.properties").toURI()); PropertyDataStore ds = new PropertyDataStore(property.getParentFile()); squareFS = ds.getFeatureSource("square"); bounds = new ReferencedEnvelope(0, 10, 0, 10, DefaultGeographicCRS.WGS84); renderer = new StreamingRenderer(); context = new DefaultMapContext(DefaultGeographicCRS.WGS84); renderer.setContext(context); Map hints = new HashMap(); hints.put("maxFiltersToSendToDatastore", 2); hints.put("optimizedDataLoadingEnabled", true); renderer.setRendererHints(hints); // System.setProperty("org.geotools.test.interactive", "true"); }
BufferedImage render(FeatureSource[] sources, Style[] styles) throws Exception { DefaultMapContext map = new DefaultMapContext(); ReferencedEnvelope env = sources[0].getBounds(); for (int i = 1; i < sources.length; i++) { env.expandToInclude(sources[i].getBounds()); } map.setAreaOfInterest(env); map.setCoordinateReferenceSystem(env.getCoordinateReferenceSystem()); for (int i = 0; i < sources.length; i++) { if (styles[i] != null) { map.addLayer(sources[i], styles[i]); } } try { StreamingRenderer r = new StreamingRenderer(); r.setJava2DHints(new RenderingHints(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON)); r.setContext(map); return RendererBaseTest.showRender("testPointLabeling", r, 5000, env); } finally { map.dispose(); } }
public void setMapContent( MapContent mapContent ) { DefaultMapContext newContext = null; if (mapContent != null) { newContext = new DefaultMapContext(); newContext.setCoordinateReferenceSystem(mapContent.getCoordinateReferenceSystem()); for (Layer layer : mapContent.layers()) { newContext.addLayer(layer); } } setContext( newContext ); }
public MapContext duplicateContext(MapContext context) { if (context != null) { DefaultMapContext copycontext = new DefaultMapContext(context.getCoordinateReferenceSystem()); MapLayer[] layers = duplicateLayers(context.getLayers()); copycontext.addLayers( layers ); copycontext.setTitle(context.getTitle()); return copycontext; } else { return null; } }
/** * Add the given collection as a new layer to the end of the list of layers held by this context * and trigger a {@linkplain MapLayerListEvent}. This is a convenience method equivalent to * {@linkplain #addLayer}(new DefaultMapLayer(collection, style). * * @param collection the collection of features for the new layer * @param style a Style object to be used in rendering this layer */ @SuppressWarnings("unchecked") public void addLayer(Collection collection, Style style) { if (collection instanceof FeatureCollection) { FeatureCollection featureCollection = (FeatureCollection) collection; addLayer(featureCollection, style); } else { throw new IllegalArgumentException("FeatureCollection required"); } }
@Override public synchronized MapViewport getViewport() { if (viewport == null) { viewport = new MapViewport(); try { ReferencedEnvelope layerBounds = getLayerBounds(); if (layerBounds != null) { viewport.setBounds(layerBounds); viewport.setCoordinateReferenceSystem( layerBounds.getCoordinateReferenceSystem()); } } catch (IOException e) { } } return viewport; } }
/** * Add a new layer and trigger a {@link LayerListEvent}. * * @param layer * Then new layer that has been added. * * @return DOCUMENT ME! */ public boolean addLayer(MapLayer layer) { if (layerList.contains(layer)) { return false; } layerList.add(layer); // getLayerBounds(); layer.addMapLayerListener(layerListener); bounds = null; fireMapLayerListListenerLayerAdded(new MapLayerListEvent(this, layer, indexOf(layer))); return true; }
private void renderEmptyGeometry(SimpleFeature f, Style style) { SimpleFeatureCollection fc = DataUtilities.collection(f); MapContext mc = new DefaultMapContext(); mc.addLayer(fc, style); StreamingRenderer sr = new StreamingRenderer(); sr.setContext(mc); BufferedImage bi = new BufferedImage(640, 480, BufferedImage.TYPE_4BYTE_ABGR); sr.addRenderListener( new RenderListener() { public void featureRenderer(SimpleFeature feature) {} public void errorOccurred(Exception e) { java.util.logging.Logger.getGlobal() .log(java.util.logging.Level.INFO, "", e); fail( "Got an exception during rendering, this should not happen, " + "not even with emtpy geometries"); } }); sr.paint( (Graphics2D) bi.getGraphics(), new Rectangle(640, 480), new ReferencedEnvelope(new Envelope(0, 10, 0, 10), DefaultGeographicCRS.WGS84)); mc.dispose(); } }
/** * Add the given collection as a new layer to the end of the list of layers held by this context * and trigger a {@linkplain MapLayerListEvent}. This is a convenience method equivalent to * {@linkplain #addLayer}(new DefaultMapLayer(collection, style). * * @param collection * the collection of features for the new layer * @param style * a Style object to be used in rendering this layer */ @SuppressWarnings("unchecked") public void addLayer(Collection collection, Style style) { if (collection instanceof FeatureCollection) { FeatureCollection featureCollection = (FeatureCollection) collection; addLayer( featureCollection, style); } else { throw new IllegalArgumentException("FeatureCollection required"); } }
/** * Add the given feature source as a new layer to the end of the list of layers held by this * context and trigger a {@linkplain MapLayerListEvent}. This is a convenience method equivalent * to {@linkplain #addLayer}(new DefaultMapLayer(featureSource, style). * <p> * If a coordinate reference system has not been set for the context an attempt is made to * retrieve one from the new layer and use that as the context's CRS. * <p> * If {@code style} is null, a default style is created using * {@linkplain SLD#createSimpleStyle(org.opengis.feature.simple.SimpleFeatureType)}. * * @param featureSource * the source of the features for the new layer * * @param style * a Style object to be used in rendering this layer. */ public void addLayer(FeatureSource featureSource, Style style) { //checkCRS(featureSource); Style layerStyle = checkStyle(style, featureSource.getSchema()); addLayer(new DefaultMapLayer(featureSource, layerStyle, "")); }
/** * Gets the current area of interest. If no area of interest is the, the * default is to fall back on the layer bounds * * @return Current area of interest * */ public ReferencedEnvelope getAreaOfInterest() { if (areaOfInterest == null) { try { final Envelope e = getLayerBounds(); if (e != null) areaOfInterest = new ReferencedEnvelope(e, this.crs); else return null; } catch (IOException e) { LOGGER .log( Level.SEVERE, "Can't get layer bounds, and area of interest is not set", e); return null; } } if (areaOfInterest == null) { return null; } else { return this.areaOfInterest; } }
public void testLabelNatural() throws Exception { Style style = RendererBaseTest.loadStyle(this, "textNaturalOrientation.sld"); DefaultMapContext mc = new DefaultMapContext(DefaultGeographicCRS.WGS84); mc.addLayer(fs, style); renderer.setContext(mc); RendererBaseTest.showRender("Lines with circle stroke", renderer, TIME, bounds); }
public void testSkipProjectionErrors() throws Exception { MapContext mapContext = new DefaultMapContext(DefaultGeographicCRS.WGS84); mapContext.addLayer(createLineCollection(), createLineStyle());