PDA

View Full Version : Modeling OpenLayers code to GeoExt Action



Sam007
11 Sep 2012, 10:02 AM
I am new to ExtJS and I have the following openlayers code and I am trying to model it into GeoExt Action. The purpose of the code is to create a user drawn Vector Layer polygon, which will fetch the feature attributes of all the WMS feature layer, contained in the user defined polygon.


Here is the code,



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
});
});


I do have the Polygon Draw Action Tool, not sure where to add the eventListener and the rest of the code. Here is my code for the Polygon Draw Tool,



action = new GeoExt.Action({
text: "draw poly",
control: new OpenLayers.Control.DrawFeature(
features, OpenLayers.Handler.Polygon
),
map: map,
// button options
toggleGroup: "draw",
allowDepress: false,
tooltip: "draw polygon",
// check item options
group: "draw"
});
actions["draw_poly"] = action;
toolbarItems.push(action);

scottmartin
11 Sep 2012, 11:49 AM
Are you offering this code, or do you need info?

Scott.

Sam007
11 Sep 2012, 11:57 AM
I have the code but I am confused as to how I should place it in the GeoExt.Action so that I can call it when the tool draws the desired polygon. I am using the ExtJS for the first time, so needed some assistance.:s

scottmartin
11 Sep 2012, 2:15 PM
I am not sure you provided enough information .. let me take a stab ;)

You created an instance : var action = new GeoExt.Action({ .. }); // with properties set

Does this evaluate in console?
console.log(action);

Do you have the library included in your uses? Are you receiving errors?

Scott.

Sam007
11 Sep 2012, 7:30 PM
hey Scott sorry about the incomplete code. Here is the complete code (http://dpaste.de/z3wBV/) (The action object is on line 79). You can also see the live demo on this link, http://128.196.142.12/geo/test/prac.html

The console.log(action) returns a object. It is really big one. Even u can see it now in the the link I sent. The short version of the object looks like this,
Object { control={...}, activateOnEnable=false, deactivateOnDisable=false, more...}