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; }
if (request == null) { GeoServerApplication app = GeoServerApplication.get(); request = new GetMapRequest(); Catalog catalog = app.getCatalog(); List<MapLayerInfo> layers = expandLayers(catalog); request.setLayers(layers); request.setFormat("application/openlayers"); request.setBbox(bounds); String epsgCode = GML2EncodingUtils.epsgCode(bounds.getCoordinateReferenceSystem()); if (epsgCode != null) request.setSRS("EPSG:" + epsgCode);
params.put("format", req.getFormat()); for (int i = 0; i < req.getLayers().size(); i++) { if (layer != null && layer.equals(req.getLayers().get(i).getName())) { ++count; styles.append(req.getLayers().get(layerIndex).getDefaultStyle().getName()); } else { for (int i = 0; i < req.getLayers().size(); i++) { if (layer.equals(req.getLayers().get(i).getName())) { styles.append(req.getLayers().get(i).getDefaultStyle().getName()); for (int i = 0; i < req.getLayers().size(); i++) { MapLayerInfo mapLayer = req.getLayers().get(i); Style s = (Style) req.getStyles().get(0); Map<String, String> kvpMap = req.getRawKvp(); if (layer != null) { index = layerIndex; } else { for (; index < req.getLayers().size(); index++) { if (req.getLayers().get(index).getName().equals(layer)) { break; if (req.getRawKvp().get("filter") != null) { (String) req.getRawKvp().get("filter"), KvpUtils.OUTER_DELIMETER); params.put("filter", (String) filters.get(index));
/** * True if the request has the tiled hint, is 256x256 image, and the raw delegate is a raster * one * * @param request * @param delegate */ public static boolean isRequestTiled(GetMapRequest request, GetMapOutputFormat delegate) { boolean tiled = request.isTiled(); Point2D tilesOrigin = request.getTilesOrigin(); int width = request.getWidth(); int height = request.getHeight(); if (tiled && tilesOrigin != null && width == 256 && height == 256 && delegate instanceof RenderedImageMapOutputFormat) { return true; } return false; }
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; } }
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; }
GetMapRequest request = new GetMapRequest(); request.setSRS("EPSG:41001"); request.setCrs(CRS.decode("EPSG:41001")); request.setLayers(mockGMR.getLayers()); request.setFormat("image/gif"); reflector.autoSetBoundsAndSize(request); CoordinateReferenceSystem crs = request.getCrs(); String srs = request.getSRS(); Envelope bbox = request.getBbox(); String format = request.getFormat(); int width = request.getWidth(); int height = request.getHeight();
getMap.setRawKvp(rawKvp); getMap.setSRS((String) kvp.get("crs")); String epsgCode = getMap.getSRS(); epsgCode = WMS.toInternalSRS(epsgCode, WMS.version(getMap.getVersion())); getMap.setSRS(epsgCode); getMap.setCrs(mapcrs); } catch (Exception e) { "Error occurred decoding the espg code " + epsgCode, e, WMSErrorCode.INVALID_CRS.get(getMap.getVersion())); String remoteOwsType = getMap.getRemoteOwsType(); remoteOwsType = remoteOwsType != null ? remoteOwsType.toUpperCase() : null; if (remoteOwsType != null && !"WFS".equals(remoteOwsType)) { URL remoteOwsUrl = getMap.getRemoteOwsURL(); if (remoteOwsUrl != null && remoteOwsType == null) { throw new ServiceException("REMOTE_OWS_URL specified, but REMOTE_OWS_TYPE is missing"); ((getMap.getFilter() != null) ? new ArrayList<Filter>(getMap.getFilter()) : Collections.emptyList()); List<Filter> cqlFilters = ((getMap.getCQLFilter() != null) ? new ArrayList<Filter>(getMap.getCQLFilter())
@Test public void testWMSGetFeatureInfo() throws Exception { GetFeatureInfoRequest gfi = new GetFeatureInfoRequest(); GetMapRequest gm = new GetMapRequest(); gm.setHeight(330); gm.setWidth(780); Envelope env = new ReferencedEnvelope(-126.81851,-115.818992,44.852958,49.5066,null); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326",true); CoordinateReferenceSystem logCrs = CRS.decode("EPSG:4326",false); gm.setBbox(env); gm.setCrs(crs); gfi.setGetMapRequest(gm); gfi.setXPixel(260); gfi.setYPixel(63); gfi.setVersion("1.1.1"); gfi.setQueryLayers(Arrays.asList(createMapLayer("foo", "acme"), createMapLayer("bar", "acme"))); callback.operationDispatched(new Request(), op("GetFeatureInfo", "WMS", "1.1.1", gfi)); assertEquals("acme:foo", data.getResources().get(0)); assertEquals("acme:bar", data.getResources().get(1)); BBoxAsserts.assertEqualsBbox(new ReferencedEnvelope(48.62,48.62,-123.15,-123.15,logCrs),data.getBbox(), 0.01); }
/** 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()); }
public void testDispatchGetMapDoesntMatchTileCache() throws Exception { GetMapRequest request = new GetMapRequest(); request.setRawKvp(rawKvp); request.setFormat("badFormat"); assertDispatchMismatch(request, "not a GWC supported format"); request.setFormat("image/gif"); assertDispatchMismatch(request, "no tile cache for requested format"); request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType()); request.setSRS("EPSG:4326"); request.setBbox(new Envelope(10, 10, 20, 20)); assertDispatchMismatch(request, "request does not align to grid"); request.setSRS("EPSG:23036"); assertDispatchMismatch(request, "no cache exists for requested CRS"); request.setSRS("badCRS"); assertDispatchMismatch(request, "exception occurred"); request.setSRS("EPSG:4326"); request.setWidth(128); request.setHeight(256); assertDispatchMismatch(request, "request does not align to grid"); request.setWidth(256); request.setHeight(128); assertDispatchMismatch(request, "request does not align to grid");
@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)); }
boolean containsRasterData = false; boolean isRegionatingFriendly = true; for (int i = 0; i < request.getLayers().size(); i++) { MapLayerInfo layer = request.getLayers().get(i); String name = layer.getName(); Map<String, String> rawKvp = request.getRawKvp(); String mode = KvpUtils.caseInsensitiveParam(rawKvp, "mode", wmsConfiguration.getKmlReflectorMode()); String submode = KvpUtils.caseInsensitiveParam(request.getRawKvp(), "superoverlay_mode", wmsConfiguration.getKmlSuperoverlayMode()); Map fo = request.getFormatOptions(); boolean refreshMode = mode.equals("refresh"); if (request.getWidth() < 1) { request.setWidth(refreshMode || containsRasterData ? DEFAULT_OVERLAY_SIZE : 256); fo.put("autofit", "true"); if (request.getHeight() < 1) { request.setHeight(refreshMode || containsRasterData ? DEFAULT_OVERLAY_SIZE : 256); fo.put("autofit", "true"); request.setSRS("EPSG:4326"); organizeFormatOptionsParams(request.getRawKvp(), fo); request.setFormat(NetworkLinkMapOutputFormat.KML_MIME_TYPE); } else if (!Arrays.asList(KMZMapOutputFormat.OUTPUT_FORMATS).contains(request.getFormat())) {
List<Object> elevations) throws IOException { final Envelope envelope = request.getBbox(); final List<MapLayerInfo> layers = request.getLayers(); final List<Map<String, String>> viewParams = request.getViewParams(); final Style[] styles = request.getStyles().toArray(new Style[] {}); final Filter[] filters = buildLayersFilters(request.getFilter(), layers); final List<SortBy[]> sorts = request.getSortByArrays(); final CoordinateReferenceSystem mapcrs = request.getCrs(); mapContent.setMapWidth(request.getWidth()); mapContent.setMapHeight(request.getHeight()); mapContent.setAngle(request.getAngle()); mapContent.setBgColor(request.getBgColor()); mapContent.setTransparent(request.isTransparent()); mapContent.setBuffer(request.getBuffer()); mapContent.setPalette(request.getPalette()); if ((request.getWidth() <= 0) || (request.getHeight() <= 0) || (mapContent.getRenderingArea().getSpan(0) <= 0) || (mapContent.getRenderingArea().getSpan(1) <= 0)) { boolean cachingPossible = request.isGet(); final String featureVersion = request.getFeatureVersion(); int maxAge = Integer.MAX_VALUE; for (int i = 0; i < layers.size(); i++) {
@Test public void testWMSGetMap() throws Exception { GetMapRequest gm = new GetMapRequest(); gm.setLayers(Arrays.asList(createMapLayer("foo", "acme"))); Envelope env = new Envelope(100,110,70,80); CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true); CoordinateReferenceSystem logCrs = CRS.decode("EPSG:4326"); gm.setBbox(env); gm.setCrs(crs); callback.operationDispatched(new Request(), op("GetMap", "WMS", "1.1.1", gm)); assertEquals("acme:foo", data.getResources().get(0)); BBoxAsserts.assertEqualsBbox(new ReferencedEnvelope(env,crs).toBounds(logCrs), data.getBbox(), 0.1); }
public void testDispatchGetMapWithMatchingParameterFilters() throws Exception { GetMapRequest request = new GetMapRequest(); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS("EPSG:900913"); request.setWidth(256); request.setHeight(256); rawKvp.put("layers", tileLayer.getName()); request.setBbox(reqBbox); request.setEnv(ImmutableMap.of("envKey", "envValue")); updateStringParameterFilter(tileLayerInfo, "ENV", true, "def:devVal", "envKey:envValue", "envKey2:envValue2"); request.setAngle(60); testParameterFilter(request, rawKvp, "angle", "60.0"); request.setAngle(61.1); testParameterFilter(request, rawKvp, "angle", "61.1");
private void initRenderer(final SimpleFeatureType type) { currentRenderer = new DistributedRenderMapOutputFormat(options); final WMSMapContent mapContent = new WMSMapContent(); final GetMapRequest request = new GetMapRequest(); mapContent.setBgColor(options.getBgColor()); request.setBgColor(options.getBgColor()); mapContent.setPalette(options.getPalette()); request.setPalette(options.getPalette()); mapContent.setAngle(options.getAngle()); request.setAngle(options.getAngle()); mapContent.setBuffer(options.getBuffer()); request.setBuffer(options.getBuffer()); mapContent.setMapWidth(options.getMapWidth()); request.setWidth(options.getMapWidth()); mapContent.setMapHeight(options.getMapHeight()); request.setHeight(options.getMapHeight()); mapContent.setTransparent(options.isTransparent()); request.setTransparent(options.isTransparent()); mapContent.setViewport(new MapViewport(options.getEnvelope())); request.setBbox(options.getEnvelope()); request.setInterpolations(options.getInterpolations()); final Map formatOptions = new HashMap<>(); formatOptions.put("antialias", options.getAntialias()); Boolean.toString(DistributedRenderOptions.isUseGlobalRenderPool())); new DefaultWebMapService(null).setApplicationContext(null); request.setFormatOptions(formatOptions); request.setWidth(options.getMapWidth()); request.setHeight(options.getMapHeight()); request.setTiled(options.isMetatile());
List<MapLayerInfo> layers = getMap.getLayers(); String reqSRS = getMap.getSRS(); Envelope aggregateBbox = getMap.getBbox(); boolean specifiedBbox = true; double bbratio = bbwidth / bbheight; double mheight = getMap.getHeight(); double mwidth = getMap.getWidth(); if ("application/openlayers".equalsIgnoreCase(getMap.getFormat()) || "openlayers".equalsIgnoreCase(getMap.getFormat())) { if (mheight < MIN_OL_HEIGHT) { mheight = MIN_OL_HEIGHT; getMap.setBbox(aggregateBbox); getMap.setWidth((int) mwidth); getMap.setHeight((int) mheight);
if (request.getFormat() == null) { request.setFormat(GIF_ANIMATED_FORMAT); List<MapLayerInfo> layers = parser.parseLayerInfos( layers0, request.getRemoteOwsURL(), request.getRemoteOwsType()); request.setLayers(layers); Envelope bbox = request.getBbox(); request.getRawKvp() .put( "BBOX", bbox.getMinX() + "," + request.getBbox().getMinY() + "," + request.getBbox().getMaxX() + "," + request.getBbox().getMaxY()); request.getRawKvp().put("WIDTH", String.valueOf(request.getWidth())); request.getRawKvp().put("HEIGHT", String.valueOf(request.getHeight()));
protected WMSMapContent createMapContent(double dpi) { GetMapRequest request = new GetMapRequest(); request.setWidth(1000); request.setHeight(1000); request.setRawKvp(new HashMap<String, String>()); if (dpi > 0) { request.getFormatOptions().put("dpi", dpi); } WMSMapContent map = new WMSMapContent(request); map.setMapWidth(request.getWidth()); map.setMapHeight(request.getHeight()); map.getViewport() .setBounds( new ReferencedEnvelope( new Envelope(0, 0.01, 0, 0.01), DefaultGeographicCRS.WGS84)); return map; }