[OpenLayers-Users] Drawfeature question

Robert Sanson Robert.Sanson at asurequality.com
Sun Feb 26 15:21:27 EST 2012


Hui Ryan

The button is on a GeoExt toolbar on the map panel. I have tried with and without including displayClass and title, and the result is the same - map's pointer is not updated till after my first click. After each polygon is added, I lose the draw symbol again.

//Here is the button code:

var fstartbut = new Ext.Button({
        xtype: 'tbbutton',
        cls: 'x-btn-icon',
        icon: 'img/fence_start.png',
        toggleGroup: "draw",
        tooltip: "Digitise / Draw new crops",
        //group: "draw",
        handler: function(){
	  mapmode="digi";
	  if (cropsLoaded == true){
	    newcrop();
	  }
	  else {
	    alert("Need to load Crops layer first!");
	  }
        }
    });
    toolbar.push(fstartbut);

//Here is the cropControls:

      cropControls = {
                dpoly: new OpenLayers.Control.DrawFeature(crops,OpenLayers.Handler.Polygon//,
			//{displayClass: "olControlDrawFeaturePoint", title: "Draw Features", handlerOptions: {holeModifier: "altKey"}}
			),
                modify: new OpenLayers.Control.ModifyFeature(crops,{displayClass: "olControlModifyFeature", title: "Modify Features"}),
                delf: new OpenLayers.Control.SelectFeature(crops, {onSelect: function(feature) {feature.attributes.pstate = "del";
                                                                                                 feature.style = del_style;
                                                                                                 crops.drawFeature(feature);
                                                                                                 }
											}
									)
      };

//Here is the full newcrop function:

function newcrop() {
    var val = "dpoly";
    for(key in measureControls) {
	var mcontrol = measureControls[key];
	mcontrol.deactivate();
    }
    for(key in cropControls) {
                var crcontrol = cropControls[key];
                if(val == key) {
                    crcontrol.activate();
                } else {
                    crcontrol.deactivate();
                }
    }
    crops.onFeatureInsert = function(feature) {
	if (insertstatus == true){
		//alert("onFeatureInsert triggered");
		feature.attributes.id = 0;
		feature.attributes.pstate = 'new'; 
		var cropa = feature.geometry.getArea();
		//name is used to store area of crop in sqm
		feature.attributes.name = roundNumber(cropa, 2);
		crops.drawFeature(feature);
		var wkt_out = wkt_format.write(feature);
		var data1 = escape(feature.attributes.id + "|" + feature.attributes.name + "|" + feature.attributes.pstate + "|" + feature.state + "|" + wkt_out);
		var postdata = "farmid=" + farmid + "&data=" + data1;
		var url = "../cgi-bin/savecrop_qa.py";
		var request = OpenLayers.Request.POST({
                      url: url,
		      data: postdata,
                      async: false,
		      headers: {"Content-Type": "application/x-www-form-urlencoded"},
                      callback: function(response) {feature.attributes.id = (+response.responseText);feature.attributes.pstate = 'pre';feature.state = null;}
                    });
		alert("New crop #" + feature.attributes.id + ", " + feature.attributes.name + "sqm inserted");
	}
    }
}

Many thanks,

Robert

>>> Ryan Williams <rwilliams at paqinteractive.com> 25/02/2012 4:36 a.m. >>>
Hi Robert,

What are you using to call the function newcrop()?
A button in the body, defined in html like... <input type="button" 
........   ?, or radio buttons in a similar way?
Or from a button or handler in Ext, GeoExt?
My guess is that the map isn't getting the style for the mouse pointer 
updated when you activate the tool, but once you click on the map the 
style gets updated.
Everything I've done with adding an editing / draw tool is activated 
from an ext.button or GeoExt.Action. Each of those activate the draw 
feature and the mouse pointer looks like the editing tool immediately.

Looking at the OpenLayers examples, there's a really similar one at 
http://openlayers.org/dev/examples/draw-feature.html , and another at 
http://openlayers.org/dev/examples/donut.html 
What I see different there is that they don't define displayClass or title.
I suppose it could be related to the displayClass setting since it looks 
like that displayClass is intended for use when you add the control to a 
panel (like a custom toolbar). That's really just a guess though.
Generally though it looks like the code should work; and it sounds like 
it is, it just isn't updating the map's mouse pointer style when the 
pointer enters the map again after activating the control?

- Ryan



This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.

This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com


More information about the Users mailing list