[OpenLayers-Users] Rectangle (box-like) drawing tool?

Schuyler Erle sderle at metacarta.com
Wed Apr 4 16:56:06 EDT 2007


On Wed, 2007-04-04 at 15:50 -0400, Christopher Schmidt wrote:
> On Wed, Apr 04, 2007 at 12:46:36PM -0700, Mike Quentel wrote:
> > Has anyone implemented a rectangle drawing tool?  As in something that draws polygons like the sandbox examples, but restricts mouse movements so that only rectangles are drawn?  I see there is an OpenLayers.Handler.Box class and an OpenLayers.Handler.Polygon class.  I want to have a rectangle drawing tool, so I'm thinking I'd want to inherit from Polygon and/or Box.  Has anyone already implemented such a class?  Would be nice to not "re-invent the wheel".  I searched the API and the Nabble archives (thank you so much for this very useful resource).  Any advice on how to make a rectangle drawing tool appreciated.  Thank you.
> 
> Handler.Box will allow you to draw a div (like the zoombox does):
> 
> http://openlayers.org/dev/examples/custom-control.html
> 
> Hold shift and drag.
> 
> Right now, it doesn't stick. You could take the points from the
> Handler.Box (in a custom control) and cause it to create a vector
> feature, or a Marker.Box, depending on what you're looking for.

Just to amplify this, the "up" callback on Control.Box will call your
callback function with an OpenLayers.Bounds object containing the pixel
corners of the box on the map container element. You can use
map.getLonLatFromPixel() to convert the corners to OpenLayers.LonLat
pairs, and then create Marker.Box objects using them, and add the Box
object to a Layer.Box. If you wind up with questions, let us know.

SDE




More information about the Users mailing list