@Override public WMSMapContent beforeRender(WMSMapContent mapContent) { mapContent.addLayer(layer); return super.beforeRender(mapContent); } };
@Test public void testChannelDescription() throws Exception { WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.BASIC_POLYGONS)); map.addLayer(createMapLayer(MockData.BASIC_POLYGONS)); map.layers().get(0).getUserData().put("abstract", "Test Abstract"); Document document; try { document = getRSSResponse(map, AtomGeoRSSTransformer.GeometryEncoding.LATLONG); } finally { map.dispose(); } Element element = document.getDocumentElement(); assertEquals("rss", element.getNodeName()); Element channel = (Element) element.getElementsByTagName("channel").item(0); NodeList description = channel.getElementsByTagName("description"); assertEquals("Test Abstract", description.item(0).getChildNodes().item(0).getNodeValue()); }
@Test public void testLinkTemplate() throws Exception { WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.BASIC_POLYGONS)); map.addLayer(createMapLayer(MockData.BASIC_POLYGONS));
@Test public void testSimpleInternal() throws Exception { WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.BASIC_POLYGONS)); map.addLayer(createMapLayer(MockData.BASIC_POLYGONS)); Document document; try { // print(document); document = getRSSResponse(map, GeoRSSTransformerBase.GeometryEncoding.SIMPLE); } finally { map.dispose(); } Element element = document.getDocumentElement(); assertEquals("rss", element.getNodeName()); NodeList entries = element.getElementsByTagName("item"); int n = getFeatureSource(MockData.BASIC_POLYGONS).getCount(Query.ALL); assertEquals(n, entries.getLength()); for (int i = 0; i < entries.getLength(); i++) { Element entry = (Element) entries.item(i); assertEquals(1, entry.getElementsByTagName("georss:polygon").getLength()); } }
private void addToMap(final WMSMapContent map, final QName typeName) throws IOException { final FeatureTypeInfo ftInfo = getCatalog() .getFeatureTypeByName(typeName.getNamespaceURI(), typeName.getLocalPart()); List<LayerInfo> layers = getCatalog().getLayers(ftInfo); StyleInfo defaultStyle = layers.get(0).getDefaultStyle(); Style style = defaultStyle.getStyle(); map.addLayer(new FeatureLayer(ftInfo.getFeatureSource(null, null), style)); }
@Test public void testLatLongInternal() throws Exception { WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.BASIC_POLYGONS)); map.addLayer(createMapLayer(MockData.BASIC_POLYGONS)); Document document; try { document = getRSSResponse(map, AtomGeoRSSTransformer.GeometryEncoding.LATLONG); } finally { map.dispose(); } Element element = document.getDocumentElement(); assertEquals("rss", element.getNodeName()); NodeList items = element.getElementsByTagName("item"); int n = getFeatureSource(MockData.BASIC_POLYGONS).getCount(Query.ALL); assertEquals(n, items.getLength()); for (int i = 0; i < items.getLength(); i++) { Element item = (Element) items.item(i); assertEquals(1, item.getElementsByTagName("geo:lat").getLength()); assertEquals(1, item.getElementsByTagName("geo:long").getLength()); } }
private CoverageInfo addRasterToMap(QName typeName) throws Exception { CoverageInfo coverageInfo = getCatalog().getCoverageByName(typeName.getNamespaceURI(), typeName.getLocalPart()); GridCoverage2DReader reader = (GridCoverage2DReader) coverageInfo.getGridCoverageReader(null, null); Style style = getCatalog().getStyleByName("rainfall").getStyle(); this.map.addLayer(new GridReaderLayer(reader, style)); return coverageInfo; }
@Before public void initializeMap() throws Exception { map = new WMSMapContent(createGetMapRequest(MockData.BASIC_POLYGONS)); map.addLayer(createMapLayer(MockData.BASIC_POLYGONS)); }
private void addRasterToMap(final WMSMapContent map, final QName typeName) throws IOException, FactoryRegistryException, TransformException, SchemaException { final CoverageInfo coverageInfo = getCatalog().getCoverageByName(typeName.getNamespaceURI(), typeName.getLocalPart()); List<LayerInfo> layers = getCatalog().getLayers(coverageInfo); StyleInfo defaultStyle = layers.get(0).getDefaultStyle(); Style style = defaultStyle.getStyle(); SimpleFeatureCollection fc = FeatureUtilities.wrapGridCoverageReader( (GridCoverage2DReader) coverageInfo.getGridCoverageReader(null, null), new GeneralParameterValue[] {}); map.addLayer(new FeatureLayer(fc, style)); }
@Test public void testReproject() throws Exception { // Set up a map context with a projected layer WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.LINES)); map.addLayer(createMapLayer(MockData.LINES)); Document document; try { document = getRSSResponse(map, AtomGeoRSSTransformer.GeometryEncoding.LATLONG); } finally { map.dispose(); } NodeList items = document.getDocumentElement().getElementsByTagName("item"); // check all items are there assertEquals(1, items.getLength()); // check coordinates are in wgs84, originals aren't for (int i = 0; i < items.getLength(); i++) { Element item = (Element) items.item(i); double lat = Double.parseDouble(getOrdinate(item, "geo:lat")); double lon = Double.parseDouble(getOrdinate(item, "geo:long")); assertTrue("Expected valid latitude value: " + lat, lat >= -90 && lat <= 90); assertTrue("Expected valid longitude value: " + lon, lon >= -180 && lon <= 180); } }
mapContent.addLayer(createMapLayer(MockData.STREAMS, "big-local-image"));
private WMSMapContent createMapContent( ReferencedEnvelope mapBounds, Rectangle renderingArea, Integer buffer, Layer... layers) throws Exception { GetMapRequest mapRequest = createGetMapRequest(mapBounds, renderingArea, buffer); WMSMapContent map = new WMSMapContent(mapRequest); map.getViewport().setBounds(mapBounds); if (layers != null) { for (Layer l : layers) { map.addLayer(l); } } map.setMapWidth(renderingArea.width); map.setMapHeight(renderingArea.height); if (Objects.nonNull(buffer)) { map.setBuffer(buffer); } mapContents.add(map); return map; }
@Test public void testFilter() throws Exception { // Set up a map context with a filtered layer WMSMapContent map = new WMSMapContent(createGetMapRequest(MockData.BUILDINGS)); Document document; try { FeatureLayer layer = (FeatureLayer) createMapLayer(MockData.BUILDINGS); Filter f = ff.equals(ff.property("ADDRESS"), ff.literal("215 Main Street")); layer.setQuery(new Query(MockData.BUILDINGS.getLocalPart(), f)); map.addLayer(layer); document = getRSSResponse(map, AtomGeoRSSTransformer.GeometryEncoding.LATLONG); } finally { map.dispose(); } NodeList items = document.getDocumentElement().getElementsByTagName("item"); assertEquals(1, items.getLength()); }
@Test public void testExternalImageSize() throws Exception { GetMapRequest req = createGetMapRequest(MockData.STREAMS); req.setWidth(256); req.setHeight(256); WMSMapContent mapContent = new WMSMapContent(req); mapContent.addLayer(createMapLayer(MockData.STREAMS, "big-local-image")); mapContent .getViewport() .setBounds(new ReferencedEnvelope(-180, 0, -90, 90, DefaultGeographicCRS.WGS84)); mapContent.setMapHeight(256); mapContent.setMapWidth(256); KMLMapOutputFormat of = new KMLMapOutputFormat(getWMS()); KMLMap map = of.produceMap(mapContent); ByteArrayOutputStream bout = new ByteArrayOutputStream(); new KMLEncoder().encode(map.getKml(), bout, null); Document document = dom(new ByteArrayInputStream(bout.toByteArray())); assertEquals("kml", document.getDocumentElement().getNodeName()); assertEquals(1, document.getElementsByTagName("Style").getLength()); XMLAssert.assertXpathExists("//kml:IconStyle/kml:scale", document); XPath xPath = XPathFactory.newInstance().newXPath(); initXPath(xPath); Double scale = (Double) xPath.evaluate( "//kml:IconStyle/kml:scale", document.getDocumentElement(), XPathConstants.NUMBER); assertEquals(42d / 16d, scale, 0.01); }
private WMSMapContent createMapContent(ReferencedEnvelope mapBounds, Rectangle renderingArea, Layer... layers) throws Exception { GetMapRequest mapRequest = createGetMapRequest(mapBounds, renderingArea); WMSMapContent map = new WMSMapContent(mapRequest); map.getViewport().setBounds(mapBounds); if (layers != null) { for (Layer l : layers) { map.addLayer(l); } } map.setMapWidth(renderingArea.width); map.setMapHeight(renderingArea.height); return map; }
FeatureLayer layer = new FeatureLayer(fs, basicStyle); layer.setTitle("Title"); map.addLayer(layer); request.setFormat("application/openlayers"); String htmlDoc = getAsHTML(map);
WMSMapContent createMapContext(QName layer, String style) throws Exception { // create a map context WMSMapContent mapContent = new WMSMapContent(); mapContent.addLayer(createMapLayer(layer, style)); mapContent.setMapHeight(256); mapContent.setMapWidth(256); GetMapRequest getMapRequest = createGetMapRequest(new QName[] {layer}); getMapRequest.setWidth(256); getMapRequest.setHeight(256); mapContent.setRequest(getMapRequest); mapContent .getViewport() .setBounds(new ReferencedEnvelope(-180, 180, -90, 90, DefaultGeographicCRS.WGS84)); return mapContent; }
@Test public void testSimpleGetMapQuery() throws Exception { Catalog catalog = getCatalog(); final FeatureSource fs = catalog.getFeatureTypeByName( MockData.BASIC_POLYGONS.getPrefix(), MockData.BASIC_POLYGONS.getLocalPart()) .getFeatureSource(null, null); final Envelope env = fs.getBounds(); LOGGER.info("about to create map ctx for BasicPolygons with bounds " + env); GetMapRequest request = new GetMapRequest(); final WMSMapContent map = new WMSMapContent(); map.getViewport().setBounds(new ReferencedEnvelope(env, DefaultGeographicCRS.WGS84)); map.setMapWidth(300); map.setMapHeight(300); map.setBgColor(Color.red); map.setTransparent(false); map.setRequest(request); StyleInfo styleByName = catalog.getStyleByName("Default"); Style basicStyle = styleByName.getStyle(); map.addLayer(new FeatureLayer(fs, basicStyle)); request.setFormat(getMapFormat()); RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map); BufferedImage image = (BufferedImage) imageMap.getImage(); imageMap.dispose(); assertNotBlank("testSimpleGetMapQuery", image); }
GetMapRequest request = new GetMapRequest(); map.setRequest(request); map.addLayer(new FeatureLayer(fSource, style)); map.getViewport().setBounds(new ReferencedEnvelope(env, DefaultGeographicCRS.WGS84)); map.setMapWidth(w);
map.addLayer(dl);