public static String getFeedURL(WMSMapContent context) { return WMSRequests.getGetMapUrl(context.getRequest(), null, 0, null, null) .replace(' ', '+'); }
protected boolean browserSupportsOL3(WMSMapContent mc) { String agent = mc.getRequest().getHttpRequestHeader("USER-AGENT"); if (agent == null) { // play it safe return false; } Pattern MSIE_PATTERN = Pattern.compile(".*MSIE (\\d+)\\..*"); Matcher matcher = MSIE_PATTERN.matcher(agent); if (!matcher.matches()) { return true; } else { return Integer.valueOf(matcher.group(1)) > 8; } }
private List<String> styleNames(WMSMapContent mapContent) { if (mapContent.layers().size() != 1 || mapContent.getRequest() == null) return Collections.emptyList(); MapLayerInfo info = mapContent.getRequest().getLayers().get(0); return info.getOtherStyleNames(); }
private static String guessCharset(WMSMapContent mapContent) { GetMapRequest request = mapContent.getRequest(); if (request != null && request.getRequestCharset() != null) { String requestCharset = request.getRequestCharset(); return requestCharset; } return "UTF-8"; }
boolean isVectorLayer(Layer layer) { int index = mapContent.layers().indexOf(layer); MapLayerInfo info = mapContent.getRequest().getLayers().get(index); return (info.getType() == MapLayerInfo.TYPE_VECTOR || info.getType() == MapLayerInfo.TYPE_REMOTE_VECTOR); }
CoordinateReferenceSystem crs = mapContent.getRequest().getCrs();
private FeatureTypeInfo getFeatureTypeInfo(Layer layer) { for (MapLayerInfo info : mapContent.getRequest().getLayers()) if (info.getName().equals(layer.getTitle())) return info.getFeature(); return null; }
protected boolean isOL3Enabled(WMSMapContent mapContent) { GetMapRequest req = mapContent.getRequest(); // check format options Object enableOL3 = Converters.convert(req.getFormatOptions().get(ENABLE_OL3), Boolean.class); if (enableOL3 == null) { // check system property enableOL3 = GeoServerExtensions.getProperty(ENABLE_OL3); } // enable by default return enableOL3 == null || Converters.convert(enableOL3, Boolean.class); } }
/** * OL3 does support a very limited set of unit types, we have to try and return one of those, * otherwise the scale won't be shown. * * @param request */ @Override protected String getUnits(WMSMapContent mapContent) { CoordinateReferenceSystem crs = mapContent.getRequest().getCrs(); // first rough approximation, meters for projected CRS, degrees for the // others String result = crs instanceof ProjectedCRS ? "m" : "degrees"; try { String unit = crs.getCoordinateSystem().getAxis(0).getUnit().toString(); // use the unicode escape sequence for the degree sign so its not // screwed up by different local encodings if ("ft".equals(unit) || "feets".equals(unit)) result = "feet"; } catch (Exception e) { LOGGER.log(Level.WARNING, "Error trying to determine unit of measure", e); } return result; } }
public static String getEntryURL(WMS wms, SimpleFeature feature, WMSMapContent context) { try { return featureTemplate.link(feature); } catch (IOException ioe) { String nsUri = feature.getType().getName().getNamespaceURI(); String nsPrefix = wms.getNameSpacePrefix(nsUri); HashMap<String, String> params = new HashMap<String, String>(); params.put("format", "application/atom+xml"); params.put("layers", nsPrefix + ":" + feature.getType().getTypeName()); params.put("featureid", feature.getID()); return ResponseUtils.buildURL( context.getRequest().getBaseUrl(), "wms/reflect", params, URLType.SERVICE); } }
String getGroundOverlayHRef(Layer layer) { WMSMapContent mapContent = context.getMapContent(); if (context.isKmz()) { // embed the ground overlay in the kmz archive int mapLayerOrder = mapContent.layers().indexOf(layer); String href = "images/layers_" + mapLayerOrder + ".png"; context.addKmzGroundOverlay(href, layer); return href; } else { // refer to a GetMap request return WMSRequests.getGetMapUrl(mapContent.getRequest(), layer, 0, mapContent.getRenderingArea(), new String[] { "format", "image/png", "transparent", "true" }); } }
/** @see org.geoserver.wms.GetMapOutputFormat#produceMap(org.geoserver.wms.WMSMapContent) */ public XMLTransformerMap produceMap(WMSMapContent mapContent) throws ServiceException, IOException { AtomGeoRSSTransformer tx = new AtomGeoRSSTransformer(wms); GetMapRequest request = mapContent.getRequest(); String geometryEncoding = (String) request.getFormatOptions().get("encoding"); if ("gml".equals(geometryEncoding)) { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.GML); } else if ("latlong".equals(geometryEncoding)) { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.LATLONG); } else { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.SIMPLE); } Charset encoding = wms.getCharSet(); tx.setEncoding(encoding); XMLTransformerMap result = new XMLTransformerMap(mapContent, tx, mapContent, getMimeType()); return result; }
/** @see org.geoserver.wms.GetMapOutputFormat#produceMap(org.geoserver.wms.WMSMapContent) */ public XMLTransformerMap produceMap(WMSMapContent map) throws ServiceException, IOException { RSSGeoRSSTransformer tx = new RSSGeoRSSTransformer(wms); GetMapRequest request = map.getRequest(); String geometryEncoding = (String) request.getFormatOptions().get("encoding"); if ("gml".equals(geometryEncoding)) { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.GML); } else if ("latlong".equals(geometryEncoding)) { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.LATLONG); } else { tx.setGeometryEncoding(GeoRSSTransformerBase.GeometryEncoding.SIMPLE); } Charset encoding = wms.getCharSet(); tx.setEncoding(encoding); XMLTransformerMap result = new XMLTransformerMap(map, tx, map, getMimeType()); // REVISIT: is was setting "inline; filename=geoserver.xml", now it's gonna be the requested // layer names, is it ok? result.setContentDispositionHeader(map, ".xml"); return result; }
@Override protected void checkAttribute(WMSMapContent con, SimpleFeatureType ft) { // find out which attribute we're going to use Map options = con.getRequest().getFormatOptions(); attribute = (String) options.get("regionateAttr"); if (attribute == null) { attribute = MapLayerInfo.getRegionateAttribute(featureType); } if (attribute == null || ft.getDescriptor(attribute) == null) { LOGGER.log(Level.FINER, "No attribute specified, falling " + "back on geometry attribute"); attribute = ft.getGeometryDescriptor().getLocalName(); } else { // Make sure the attribute is actually there AttributeType attributeType = ft.getType(attribute); if (attributeType == null) { throw new ServiceException("Could not find regionating attribute " + attribute + " in layer " + featureType.getName()); } } // geometry size is a double h2Type = "DOUBLE"; }
/** * Force the output to be in WGS84 * @param mc * @return */ private WMSMapContent fixViewport(WMSMapContent mc) { MapViewport viewport = mc.getViewport(); if(!CRS.equalsIgnoreMetadata(viewport.getCoordinateReferenceSystem(), DefaultGeographicCRS.WGS84)) { viewport.setCoordinateReferenceSystem(DefaultGeographicCRS.WGS84); GetMapRequest req = mc.getRequest(); req.setSRS("EPSG:4326"); req.setBbox(viewport.getBounds()); } return mc; }
protected void checkAttribute(WMSMapContent con, SimpleFeatureType ft) { // find out which attribute we're going to use Map options = con.getRequest().getFormatOptions(); attribute = (String) options.get("regionateAttr"); if (attribute == null) attribute = checkAttribute(featureType); if (attribute == null) throw new ServiceException( "Regionating attribute has not been specified"); // Make sure the attribute is actually there AttributeDescriptor ad = ft.getDescriptor(attribute); if (ad == null) { throw new ServiceException("Could not find regionating attribute " + attribute + " in layer " + featureType.getName()); } // Make sure we know how to turn that attribute into a H2 type h2Type = getH2DataType(ad); if (h2Type == null) throw new ServiceException("Attribute type " + ad.getType() + " is not " + "supported for external sorting on " + featureType.getName() + "#" + attribute); }
void encodeKMLLink(Folder container, Layer layer, String name, int drawOrder, Envelope box) { // copy the format options CaseInsensitiveMap fo = new CaseInsensitiveMap(new HashMap()); fo.putAll(mapContent.getRequest().getFormatOptions()); // we want to pass through format options except for superoverlay, we need to // turn it off so we get actual placemarks back, and not more links fo.remove("superoverlay"); // get the regionate mode String overlayMode = (String) fo.get("overlayMode"); if ("overview".equalsIgnoreCase(overlayMode)) { // overview mode, turn off regionation fo.remove("regionateBy"); } else { // specify regionateBy=auto if not specified if (!fo.containsKey("regionateBy")) { fo.put("regionateBy", "auto"); } } String foEncoded = WMSRequests.encodeFormatOptions(fo); // encode the link NetworkLink nl = container.createAndAddNetworkLink(); nl.setName(name); addRegion(nl, box, 128, -1); nl.setVisibility(true); Link link = nl.createAndSetLink(); String url = WMSRequests.getGetMapUrl(request, layer, 0, box, new String[] { "width", "256", "height", "256", "format_options", foEncoded, "superoverlay", "true"}); link.setHref(url); }
public static void setupEnvironmentVariables(WMSMapContent mapContent) { // setup some SLD variable substitution environment used by rendering transformations EnvFunction.setLocalValue("wms_bbox", mapContent.getRenderingArea()); EnvFunction.setLocalValue( "wms_crs", mapContent.getRenderingArea().getCoordinateReferenceSystem()); EnvFunction.setLocalValue("wms_srs", mapContent.getRequest().getSRS()); EnvFunction.setLocalValue("wms_width", mapContent.getMapWidth()); EnvFunction.setLocalValue("wms_height", mapContent.getMapHeight()); try { double scaleDenominator = mapContent.getScaleDenominator(true); EnvFunction.setLocalValue("wms_scale_denominator", scaleDenominator); } catch (Exception e) { LOGGER.log( Level.SEVERE, "Failed to compute the scale denominator, wms_scale_denominator env variable is unset", e); } } }
@Override protected String getDatabaseName(WMSMapContent con, Layer layer) throws Exception { fs = layer.getFeatureSource(); SimpleFeatureType type = (SimpleFeatureType) fs.getSchema(); // find out which attribute we're going to use Map options = con.getRequest().getFormatOptions(); attribute = (String) options.get("regionateAttr"); if (attribute == null) attribute = MapLayerInfo.getRegionateAttribute( featureType ); if (attribute == null) throw new ServiceException("Regionating attribute has not been specified"); // Make sure the attribute is actually there AttributeType attributeType = type.getType(attribute); if (attributeType == null) { throw new ServiceException("Could not find regionating attribute " + attribute + " in layer " + featureType.getName()); } // check we can actually sort on that attribute if(!fs.getQueryCapabilities().supportsSorting(new SortBy[] {ff.sort(attribute, SortOrder.DESCENDING)})) throw new ServiceException("Native sorting on the " + attribute + " is not possible for layer " + featureType.getName()); // make sure a special db for this layer and attribute will be created return super.getDatabaseName(con, layer) + "_" + attribute; }
protected void setLiveIconStyle(Style style, org.geotools.styling.Style sld, IconProperties properties, KmlEncodingContext context) { final Double opacity = properties.getOpacity(); final Double scale = properties.getScale(); final Double heading = properties.getHeading(); IconStyle is = style.createAndSetIconStyle(); if (opacity != null) { is.setColor(colorToHex(Color.WHITE, opacity)); } if (scale != null) { is.setScale(scale); } if (heading != null) { is.setHeading(heading); } // Get the name of the workspace WorkspaceInfo ws = context.getWms().getCatalog().getStyleByName(sld.getName()).getWorkspace(); String wsName = null; if(ws!=null) wsName = ws.getName(); Icon icon = is.createAndSetIcon(); icon.setHref(properties.href(context.getMapContent().getRequest().getBaseUrl(), wsName, sld.getName())); }