// this snippet is set in the app init // where: // wfsURL==String var // campusMapParams.geoserver == your WFS server // qLayers==Array holding layer names you want to query // srs==spatial reference that applies to the WFS server you want to query, for geoserver its EPSG references wfsURL=campusMapParams.geoserver+"wfs?request=GetFeature&version=1.1.0&typeName="+qLayers.toString()+"&srs="+srs; protected function doIdentifyAll(event:MapMouseEvent): void { var getWFS:HTTPService=new HTTPService; // we'll use a DWITHIN filter to grab any features that are within 25 meters or so // NOTE DWITHIN units MUST match the point coords, ie degrees!! var idPoint:String=String(event.latLng.lng())+","+String(event.latLng.lat()); // google's coords are all geographic so we'll stick w/EPSG:4326 getWFS.url=wfsURL+'&FILTER=<Filter xmlns="http://www.opengis.net/ogc" xmlns:gml="http://www.opengis.net/gml">' + '<DWithin><PropertyName>the_geom</PropertyName>' + '<gml:Point srsName="EPSG:4326"><gml:coordinates>' +idPoint +'</gml:coordinates></gml:Point><Distance units="deg">0.000050</Distance></DWithin></Filter>'; getWFS.method="GET"; getWFS.resultFormat="e4x"; getWFS.addEventListener("result", identifyAllFeaturesHandler); getWFS.addEventListener("fault", httpServiceFault); getWFS.useProxy=false; try { getWFS.send(); } catch (error:Error) { informUser("Fatal error: Unable to perform identify features on geoserver " + error,"WFS identify all","error"); } } protected function identifyAllFeaturesHandler(event:ResultEvent):void { var results:XML=event.result as XML; var features:XMLList=results.gml::featureMembers.children(); var gid:String=""; var featureAttributes:ArrayCollection=new ArrayCollection(); for (var i:int = 0; i < features.length(); i++) { gid=features.@gml::id; var thisFeature:Object=parseAttributes(features); for (var x:String in thisFeature) { featureAttributes.addItem({layer:gid,attribute:x,value:thisFeature}); } } if (featureAttributes.length==0) informUser("No features found at that point","Identify"); else { if (idResultWindow) // get rid of last one no matter what PopUpManager.removePopUp(idResultWindow); // clean slate idResultWindow=IdentifyResultWindow(PopUpManager.createPopUp(this,IdentifyResultWindow,false)); idResultWindow.dataSource=featureAttributes; } } protected function parseAttributes(xmlNode:XML):Object { var nodes:XMLList = xmlNode.children(); var attributes:Object = {}; for(var i:int = 0; i < nodes.length(); i++) { var name:String = nodes.localName(); var value:Object = nodes.valueOf(); if(name == null || name=="the_geom") continue; // Check for a leaf node if((nodes.children().length() == 1) && !(nodes.children().children()[0] is XML)) attributes[name] = value.children()[0].toXMLString(); extend(attributes, this.parseAttributes(nodes)); } return attributes; }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.