@Test public void testExecuteNoFormat() { request.setFormat(null); assertInvalidMandatoryParam("InvalidFormat"); }
public static GetMapRequest autoSetMissingProperties(GetMapRequest getMap) { // set the defaults if (getMap.getFormat() == null) { getMap.setFormat(FORMAT); } if ((getMap.getStyles() == null) || getMap.getStyles().isEmpty()) { // set styles to be the defaults for the specified layers // TODO: should this be part of core WMS logic? is so lets throw // this // into the GetMapKvpRequestReader if ((getMap.getLayers() != null) && (getMap.getLayers().size() > 0)) { ArrayList<Style> styles = new ArrayList<Style>(getMap.getLayers().size()); for (int i = 0; i < getMap.getLayers().size(); i++) { styles.add(getMap.getLayers().get(i).getDefaultStyle()); } getMap.setStyles(styles); } else { getMap.setStyles(STYLES); } } // auto-magic missing info configuration autoSetBoundsAndSize(getMap); return getMap; }
@Test public void testExecuteInvalidFormat() { request.setFormat("non-existent-output-format"); assertInvalidMandatoryParam("InvalidFormat"); }
private BufferedImage getLayer(Layer l) { GetMapRequest getMapRequest = wms.createGetMapRequest(); getMapRequest.addLayer(l); getMapRequest.setBBox(l.getEnvelope(DefaultGeographicCRS.WGS84)); getMapRequest.setDimensions(200, 400); getMapRequest.setFormat("image/png"); getMapRequest.setSRS("CRS:84"); System.out.println(getMapRequest.getFinalURL()); try { GetMapResponse response = wms.issueRequest(getMapRequest); BufferedImage image = ImageIO.read(response.getInputStream()); return image; } catch (ServiceException | IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
@Override public RenderedImage call() throws Exception { org.geoserver.wms.WebMap wmsResponse; // Making a shallow copy of the original request and replacing param's values GetMapRequest frameRequest = replaceRequestParams(this.request, this.aparam, this.avalue); // set rest of the wms defaults frameRequest = DefaultWebMapService.autoSetMissingProperties(frameRequest); // Setup Frame OUTputFormat String outFormat = frameRequest.getFormat(); // the capabilities of this produce are actually linked to the map response that is going to // be used, this class just generates a rendered image final Collection<RenderedImageMapResponse> responses = this.wmsConfiguration.getAvailableMapResponses(); for (RenderedImageMapResponse response : responses) { if (response.getOutputFormats().contains(outFormat)) { MapProducerCapabilities cap = response.getCapabilities(outFormat); if (cap != null && cap.getFramesMimeType() != null) { frameRequest.setFormat(cap.getFramesMimeType()); } else { frameRequest.setFormat(GIF_FORMAT); } } } wmsResponse = this.wms.getMap(frameRequest); return ((RenderedImageMap) wmsResponse).getImage(); }
@SuppressWarnings("unchecked") private GetMapRequest initGetMapRequest(QName... names) { GetMapRequest request = createGetMapRequest(names); request.setRawKvp(new KvpMap(request.getRawKvp())); String layers = request.getLayers() .stream() .map(MapLayerInfo::getName) .collect(Collectors.joining(",")); request.getRawKvp().put("layers", layers); request.setFormat(DefaultWebMapService.FORMAT); DefaultWebMapService.autoSetBoundsAndSize(request); return request; }
request.setFormat("application/openlayers");
List<MapLayerInfo> layers = expandLayers(catalog); request.setLayers(layers); request.setFormat("application/openlayers");
public GetMapRequest createRequest() { GetMapRequest request; request = new GetMapRequest(); request.setFormat(DummyRasterMapProducer.MIME_TYPE); request.setWidth(512); request.setHeight(256); Envelope envelope = new Envelope(-180, 180, -90, 90); request.setBbox(envelope); request.setSRS("EPSG:4326"); request.setCrs(DefaultGeographicCRS.WGS84); try { request.setStyles(Collections.singletonList(defaultStyle.getStyle())); } catch (IOException e) { throw new RuntimeException("shouldn't happen", e); } request.setRawKvp(new HashMap<String, String>()); request.setBaseUrl("http://example.geoserver.org/geoserver"); return request; }
@Test public void testSingleVectorLayer() throws IOException { request.setFormat(DummyRasterMapProducer.MIME_TYPE); MapLayerInfo layer = mockData.addFeatureTypeLayer("testSingleVectorLayer", Point.class); request.setLayers(Arrays.asList(layer)); final DummyRasterMapProducer producer = new DummyRasterMapProducer(); final WMS wms = new WMS(mockData.getGeoServer()) { @Override public GetMapOutputFormat getMapOutputFormat(final String mimeType) { if (DummyRasterMapProducer.MIME_TYPE.equals(mimeType)) { return producer; } return null; } }; getMapOp = new GetMap(wms); getMapOp.run(request); assertTrue(producer.produceMapCalled); }
@Before public void setUp() { GetMapRequest request = new GetMapRequest(); request.setFormat("image/png"); this.map = new WMSMapContent(); this.map.setMapWidth(256); this.map.setMapHeight(256); this.map.setTransparent(true); this.map.setRequest(request); }
request.setCrs(CRS.decode("EPSG:41001")); request.setLayers(mockGMR.getLayers()); request.setFormat("image/gif"); reflector.autoSetBoundsAndSize(request);
/** Test hitArea does not overflow out of painted area. */ @Test public void testHitAreaSize() throws Exception { GetFeatureInfoRequest request = new GetFeatureInfoRequest(); GetMapRequest getMapRequest = new GetMapRequest(); List<MapLayerInfo> layers = new ArrayList<>(); layers.add(new MapLayerInfo(getCatalog().getLayerByName(MockData.BRIDGES.getLocalPart()))); getMapRequest.setLayers(layers); getMapRequest.setSRS("EPSG:4326"); getMapRequest.setBbox(new Envelope(0.0001955, 0.0002035, 0.000696, 0.000704)); getMapRequest.setWidth(100); getMapRequest.setHeight(100); getMapRequest.setFormat("image/png"); request.setGetMapRequest(getMapRequest); request.setQueryLayers(layers); // point is almost centered, but on the other side of the middle point request.setXPixel(45); request.setYPixel(45); FeatureInfoRequestParameters params = new FeatureInfoRequestParameters(request); VectorRenderingLayerIdentifier vrli = new VectorRenderingLayerIdentifier(getWMS(), null); assertEquals(0, vrli.identify(params, 10).size()); }
@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); }
/** * This test is incomplete because I (arneke) had trouble finding mock data with proper bounding * boxes */ @Test public void testAutoSetWidthHeightOL() throws Exception { DefaultWebMapService reflector = new DefaultWebMapService(getWMS()); // request too stretched east/west GetMapRequest request = createGetMapRequest(MockData.BRIDGES); request.setBbox(new Envelope(-180, 180, 0, 10)); request.setFormat("application/openlayers"); reflector.autoSetBoundsAndSize(request); assertEquals(768, request.getWidth()); assertEquals(330, request.getHeight()); // request too stretched south/north request = createGetMapRequest(MockData.BRIDGES); request.setBbox(new Envelope(-0, 10, -90, 90)); request.setFormat("application/openlayers"); reflector.autoSetBoundsAndSize(request); assertEquals(330, request.getWidth()); assertEquals(768, request.getHeight()); }
Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS("EPSG:900913"); request.setWidth(256);
request.setFormat(DefaultWebMapService.FORMAT); reflector.autoSetBoundsAndSize(request);
request.setWidth(mapWidth); request.setSRS("urn:x-ogc:def:crs:EPSG:4326"); request.setFormat("image/png"); request.setTransparent(true);
@Test public void testGetMapOnByteNodataGrayScale() throws Exception { GetMapRequest request = new GetMapRequest(); CoordinateReferenceSystem crs = DefaultGeographicCRS.WGS84; ReferencedEnvelope bbox = new ReferencedEnvelope(new Envelope(145, 146, -43, -41), crs); request.setBbox(bbox); request.setHeight(768); request.setWidth(384); request.setSRS("urn:x-ogc:def:crs:EPSG:4326"); request.setFormat("image/png"); request.setTransparent(true); final WMSMapContent map = new WMSMapContent(request); map.setMapHeight(768); map.setMapWidth(384); map.setBgColor(BG_COLOR); map.setTransparent(true); map.getViewport().setBounds(bbox); addRasterToMap(map, TAZ_BYTE); map.getViewport().setBounds(bbox); RenderedImageMap imageMap = this.rasterMapProducer.produceMap(map); RenderedOp op = (RenderedOp) imageMap.getImage(); BufferedImage image = op.getAsBufferedImage(); imageMap.dispose(); // check that a pixel in nodata area is transparent assertEquals(0, image.getRaster().getSample(40, 400, 0)); assertEquals(0, image.getRaster().getSample(40, 400, 1)); }