⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wfsmapresource.java

📁 esri的ArcGIS Server超级学习模板程序(for java)
💻 JAVA
字号:
package com.esri.solutions.jitk.web.wfs.data;

import java.util.HashMap;
import java.util.List;
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.geometry.WebExtent;
import com.esri.adf.web.data.geometry.WebSpatialReference;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSCapabilities;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSClient;
import com.esri.solutions.jitk.datasources.ogc.wfs.WFSFeatureDescriptions;
import com.esri.solutions.jitk.web.wfs.adapters.WFSGetCapabilitiesAdapter;

public class WFSMapResource extends GISResource {
	private static final long serialVersionUID = 8500463819671341241L;
	private static final Logger _logger = LogManager.getLogger(WFSMapResource.class);
	protected String _endPointURL = "";
	protected List<WFSWebLayerInfo> _layers = null;
	protected Map<Integer, WFSWebLayerInfo> _layerMap;
	protected WebSpatialReference _defaultSpatRef = null;
	protected WebExtent _serviceExtent = null;
	
	public WFSMapResource() {
		super();
	}
	
	public WFSMapResource(String resource) {
		super();
	}
	
	/**
	 * Returns the resource default spatial reference. If this value can not be derived
	 * from the WFS GetCapabilities XML file, then the base class GISResource.getDefaultSpatialReference()
	 * method is delegated to.
	 */
	@Override
	public WebSpatialReference getDefaultSpatialReference() {
		init();
		
		return _defaultSpatRef;
	}
	
	/**
	 * Returns full extent of the service. The full extent is calculated by returning the extent
	 * of the first service in the GetCapabilities response.
	 * @return Full {@link WebExtent} of service
	 */
	public WebExtent getFullExtent() {
		return _serviceExtent;
	}
	
	public void setEndPointURL(String endPointURL) {
		_logger.debug("URL endpoint: " + endPointURL);
		_endPointURL = endPointURL;
	}
	
	public String getEndPointURL(){
		return _endPointURL;
	}
	
	public List<WFSWebLayerInfo> getLayers() {
		_logger.debug("getLayers called");
		init();
		return _layers;
	}
	
	public WFSWebLayerInfo getLayerInfoByIndex(int index) {
		return _layerMap.get(index);
	}
	
	/**
	 * Returns the {@link WFSWebLayerInfo} reference for the layer with the
	 * name associated by the passed parameter. If more then one layer has
	 * the same name, the first encountered layer is passed.
	 * @param name The name of the layer
	 * @return The {@link WFSWebLayerInfo} reference to the desired layer.
	 */
	public WFSWebLayerInfo getLayerInfoByLayerName(String name) {
		WFSWebLayerInfo desiredLayer = null;
		
		for (WFSWebLayerInfo layer : _layers) {
			if (layer.getName().equals(name)) {
				desiredLayer = layer;
			}
		}
		
		return desiredLayer;
	}	
	
	/**
	 * Return the {@link WFSWebLayerInfo} index in the {@link WFSWebLayerInfo} List<>
	 * by indexing the array by the layer name. If the name is not found, -1 is returned.
	 * If more than one layer has the same name, the first encountered layer is passed.
	 * @param name
	 * @return Index of the {@link WFSWebLayerInfo} in the {@link WFSWebLayerInfo} List<>
	 */
	public int getLayerInfoIndexFromLayerName(String name) {
		int index = 0;
		int iReturnIndex = -1;
		
		for (WFSWebLayerInfo layer : _layers) {
			if (layer.getName().equals(name)) {
				iReturnIndex = index;
				break;
			}
			
			index++;
		}
		
		return iReturnIndex;
	}		
	
	protected void init() {
		if (_layers == null) {
			String url = getEndPointURL();
			WFSClient wfsClient = new WFSClient(url);
			
			try {
				_logger.debug("Sending get capabilities request to " + url);
				WFSCapabilities cap = wfsClient.getCapabilities();
				WFSGetCapabilitiesAdapter capabilitiesAdapter = new WFSGetCapabilitiesAdapter(cap);
				
				_defaultSpatRef = capabilitiesAdapter.getDefaultSpatialReference();
				_serviceExtent = capabilitiesAdapter.getServiceFullExtent(_defaultSpatRef);
				_layers = getLayerListFromService(wfsClient, cap);
			} catch (Exception ex) {
				_logger.error("Could not get layer info for WFS", ex);
			}
		} else {
			_logger.debug("returning cached layer list");
		}		
	}
	
	protected List<WFSWebLayerInfo> getLayerListFromService(WFSClient wfsClient, WFSCapabilities cap) {
		_layerMap = new HashMap<Integer, WFSWebLayerInfo>();
		List<WFSWebLayerInfo> layers = null;
		
		try {			
			_logger.debug("Sending describe feature type request to " + wfsClient.getURL());
			WFSFeatureDescriptions wfd = wfsClient.describeFeatures(cap.getFeatureTypesAsMap());

			WFSWebLayerInfosBuilder infosBuilder = new WFSWebLayerInfosBuilder();
			layers = infosBuilder.buildWebLayerInfos(cap, wfd, this);
			
			for (WFSWebLayerInfo info : layers) {
				_layerMap.put(info.getId(), info);
			}
		} catch (Exception ex) {
			_logger.error("Could not query layers from WFS Service", ex);
		}		
		
		return layers;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -