[OpenLayers-Users] Obtain info from the user defined polygon

Phil Scadden p.scadden at gns.cri.nz
Tue Jun 12 17:13:54 PDT 2012


Here is how I do it. Sorry, but there is a lot of application-specific 
stuff in it. (I have a structure that stores a lot of metadata about how 
a layer is to be displayed and queried).

                 pySelCtrl = new 
OpenLayers.Control.DrawFeature(selectedLayer, OpenLayers.Handler.Polygon, {
                     geodesic: true,
                     handlerOptions: {
                         citeCompliant: false
                     }
                 }); // selected layer is an empty vector layer that use 
for drawing selected feature on and for drawing control

                 pySelCtrl.events.register("featureadded", this, 
function (e) {
                     clearData(); // housekeeping (clean up previous 
queries, delete all vectors from selectedLayer)
                     var pfilter = new OpenLayers.Filter.Spatial({
                             type: OpenLayers.Filter.Spatial.INTERSECTS,
                             value: e.feature.geometry
                         });
//                    This next piece of code is using application logic 
to find out which fields to fetch back from the server. If you dont 
specify properynames, it will return all of them
                     var propNames = [];
                     var layerNode = getLayerNode(combo.value); // this 
returns application metadata about the layer to query
                     var spatialQueryNode =layerNode.spatialQuery[0]; // 
get the list of fields to return from application metadata
                     for (var i = 0; i < spatialQueryNode.fields.length; 
i++) {
                         propNames.push(spatialQueryNode.fields[i].id);
                     }
//
                    if (spatialQueryNode.highlightOnMap) 
propNames.push("SHAPE");     // fetch back geometryif I am going to draw 
the on the map

// This read queries the server.
                     wfsProtocol[combo.value].read({
                         filter:  pfilter,
                         propertyNames:propNames,
                         callback: processSpatialQuery,
                         scope: strategy
                     });
                 });
The processSpatialQuery callback unpacks the returned GML to populate a 
popup, draws the selected features in selectedLayer etc.


Notice: This email and any attachments are confidential. If received in error please destroy and immediately notify us. Do not copy or disclose the contents.



More information about the Users mailing list