Select to view content in your preferred language

Identify on WMS Layer

3626
4
04-18-2011 01:55 PM
by Anonymous User
Not applicable
Are there any snippets out there for this? Samples, etc.?

Thanks in advance....

rGibson
Tags (2)
0 Kudos
4 Replies
MattiasEkström
Frequent Contributor
This was posted pretty long ago, is there anyone who has been able to do an identify on a WMS layer from flex since then?
I've search the forums och documentation for ArcGIS API for flex as well as ArcGIS Viewer for Flex but haven't found anything.
If WMS layers is supposed to be supported, I don't think it's too much to ask to be able to perform an identify on them...
0 Kudos
PaulHastings1
Deactivated User
it's easy enough to do yourself in the meantime. do you need a sample?
0 Kudos
MattiasEkström
Frequent Contributor
I have been able to write some code that provides an url that will work if I copy and paste it into a new browser. I've tried using this url with a httpRequest without any succes so far. A sample would be great!
0 Kudos
PaulHastings1
Deactivated User
in the interests of a quick reply, this is for WFS identify all from a project i have on disk that is based on google maps & geoserver. you'll have to change the map mouse event to ESRI's & build your own display as well as the cleanup routine to remove the event handlers.

when i get a chance i'll dig up a proper WMS getFeatures example.


// 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;
}
0 Kudos