📄 wmcwriter.java
字号:
/**
*
*/
package com.esri.solutions.jitk.data.wmc;
/*
*
*#1 For <Server version=""> attribute, the version of ArcGIS Server/ArcIMS should be stored (if known), i.e., 9.3.0.1770, 9.2.5.1888, etc Format <Major Version>.<Minor Version>.<Service Pack>.<Build Number>
*#2 For <Server service=""> attribute, the PDF on the OGC website states that any xs:string can be used, but the XSD states that only WMS and WFS are supported. See: http://schemas.opengis.net/context/1.1.0/context.xsd
MVS will use the mappings below for the service attribute (from non-WMS and non-WFS services),
it will be configurable in the viewer to change the mapping from service type to xs:string outputted in the WMC file in case a particular customer uses a different mapping:
OGC:WMS - WMS
OGC:WFS - WFS
OGC:WCS - WCS
ESRI:AIMS:HTTP - ArcIMS HTTP Connect
ESRI:AIMS:TCP - ArcIMS TCP Connect
ESRI:AGS:MAP:REST - ArcGIS Server Map Service exposed as REST
ESRI:AGS:MAP:SOAP - ArcGIS Server Map Service exposed as SOAP
ESRI:AGS:MAP:LOCAL - ArcGIS Server Map Service exposed as DCOM
ESRI:AGS:GEOCODE:REST - ArcGIS Server Geocode Service exposed as REST
ESRI:AGS:GEOCODE:SOAP - ArcGIS Server Geocode Service exposed as SOAP
ESRI:AGS:GEOCODE:LOCAL - ArcGIS Server Geocode Service exposed as DCOM
*ESRI:AGS:NA:REST - ArcGIS Server Network Analyst Service exposed as REST
*ESRI:AGS:NA:SOAP - ArcGIS Server Network Analyst Service exposed as SOAP
*ESRI:AGS:NA:LOCAL - ArcGIS Server Network Analyst Service exposed as DCOM
ESRI:AGS:GP:SOAP - ArcGIS Server Geoprocessing Service exposed as SOAP
ESRI:AGS:GP:REST - ArcGIS Server Geoprocessing Service exposed as REST
ESRI:AGS:GP:LOCAL - ArcGIS Server Geoprocessing exposed as DCOM
GOOGLE:KML - KML
* denotes design may change as this is a capability, not a service type.
* #3 For <Name>, we should only use the resource alias (resource name that appears in the Viewer TOC node).
* #4 For <Title>, we should only use the layer alias (layer name that appears in the Viewer TOC node).
* #5 For secure services, the XSD <LayerType> has an element <Extension> of type "context:ExtensionType", which is a sequence of <xs:any namespace="##any"/>, this means we can place additional, non-OGC tags here to support secure services. (It would make more sense to place this tag in the <ServerType> element, but the OGC XSD has no facility to do this).
In MVS, our outputted WMC XML file will contain a reference to the MVS XSD for mvs_resource_types.xsd.
In this file we have the following tag definition to support secure services:
<xs:complexType name="IdentityType">
<xs:sequence>
<xs:element ref="mvs:Attributes" minOccurs="0" maxOccurs="1"></xs:element> </xs:sequence> <xs:attribute name="Password" type="xs:string" use="required" /> <xs:attribute name="UserName" type="xs:string" use="required" /> <xs:attribute name="Domain" type="xs:string" use="optional" /> <xs:attribute name="IsEncrypted" type="xs:boolean" use="optional" /> </xs:complexType>
Example:
<Layer ...>
....
<mrt:Identity Password="Xdfdf=dfs" UserName="will4769" Domain="AVWORLD" IsEncrypted="true" />
</Layer>
*/
import java.util.Map;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import com.esri.adf.web.data.GISResource;
import com.esri.adf.web.data.WebContext;
import com.esri.adf.web.data.WebMap;
import com.esri.adf.web.data.geometry.WebExtent;
/**
* @author vlad2928
*
*/
public class WMCWriter extends BasicXMLWriter {
private static Logger _logger = LogManager.getLogger(WMCWriter.class.getName());
public WMCWriter(WebContext webContext) {
super(webContext);
}
private StringBuffer writeGeneralTag(String mapName, String mapDescription) {
StringBuffer buf = new StringBuffer();
Tag generalTag = new Tag("General", null, null, true);
buf.append(generalTag.open());
buf.append(valueTag("Title", chkStr(mapName, webContext.getName())));
if(chkStr(mapDescription, "").length() != 0) {
buf.append(valueTag("Abstract", mapDescription));
}
WebMap map = webContext.getWebMap();
WebExtent extent = map.getFullExtent();
buf.append(attsTag("Window", new String[][]{{"width", map.getWidth() + ""},
{"height", map.getHeight() + ""}}));
buf.append(attsTag("BoundingBox", new String[][]{{"minx", extent.getMinX() + ""},
{"miny", extent.getMinY() + ""},
{"maxx", extent.getMaxX() + ""},
{"maxy", extent.getMaxY() + ""},
{"SRS", getSRS(extent.getSpatialReference()) + ""}}));
buf.append(generalTag.close());
return buf;
}
private StringBuffer writeGISResources() {
StringBuffer buf = new StringBuffer();
Map<String, GISResource> resources = webContext.getResources();
GISResource resource = null;
for(java.util.Iterator<String> i = resources.keySet().iterator(); i.hasNext();) {
try {
resource = resources.get(i.next());
buf.append(WMCGISResourceWriterFactory.getInstance(resource).write());
} catch(WMCResourceWriterNotExistException ex) {
_logger.warn(ex.toString());
} catch(Exception ex) {
_logger.warn("ERROR exporting " + resource.getClass().getName() + " ('" + resource.getAlias() + "')...");
_logger.warn(ex.toString());
} catch(Throwable ex) {
_logger.warn("ERROR exporting " + resource.getClass().getName() + " ('" + resource.getAlias() + "')...");
_logger.warn(ex.toString());
}
}
return buf;
}
public StringBuffer write(String mapName, String mapDescription) {
StringBuffer buf = new StringBuffer();
Tag vcTag = new Tag("ViewContext", new String[][] {{ "version", "1.1.0" },
{ "id", webContext.getName() },
{ "xmlns", "http://www.opengeospatial.net/context" },
{ "xmlns:xlink", "http://www.w3.org/1999/xlink" },
{ "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance" },
{ "xsi:schemaLocation", "http://www.opengeospatial.net/context context.xsd" }}, null, true);
Tag llTag = new Tag("LayerList", null, null, true);
// Start outputting WMC...
buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append(nl);
buf.append(vcTag.open());
buf.append(writeGeneralTag(mapName, mapDescription));
buf.append(llTag.open());
buf.append(writeGISResources());
buf.append(llTag.close());
buf.append(vcTag.close());
return buf;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -