[OpenLayers-Users] only one rectangle draw in single Map

Phil Scadden p.scadden at gns.cri.nz
Sun May 12 14:51:19 PDT 2013


You arent tell us that much what you want to do with the rectangle, but 
I am assuming that you want the lat/lon coordinates of the corners when 
drawing complete.

I would create a vector layer. eg
selectedLayer = new OpenLayers.Layer.Vector("Selected Layer", {
     wrapDateLine: true,
     displayOutsideMaxExtent: true,
     displayInLayerSwitcher: false,
});
map.addLayer(selectedLayer);

I would use DrawFeature on that selectedLayer, with a Box Handler.
eg
boxControl = new OpenLayers.Control.DrawFeature(selectedLayer, 
OpenLayers.Handler.Box,{});

I would then register a featureadded event to
             boxControl.events.register("featureadded", this, function (e) {
                // add your code here to deal with the event. 
e.feature.geometry will have to corner verticies.
               selectedLayer.destroyFeatures; // clear the vector layer 
after you are finished with it.
            }

Note that the geometry will be in the map projection. You may need to 
unproject to get lat/long.

Caveat - I havent done this with box, only with polyogin.

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