[OpenLayers-Users] Re: drawing a box or circle
wls
wls at wwco.com
Tue May 17 10:45:24 EDT 2011
Ulao,
I ran into this a while back, and here's my understanding of what's going on
with OpenLayers, though I'm willing to defer to any experts that state
otherwise.
In order to manipulate an OpenLayers map, you need to "
http://dev.openlayers.org/docs/files/OpenLayers/Map-js.html#OpenLayers.Map.addControl
add " a http://dev.openlayers.org/docs/files/OpenLayers/Control-js.html
Control to it. Controls sit dormant until
http://dev.openlayers.org/docs/files/OpenLayers/Control-js.html#OpenLayers.Control.activate
activated , then they do their thing, and stop when
http://dev.openlayers.org/docs/files/OpenLayers/Control-js.html#OpenLayers.Control.deactivate
deactivated .
The control you're interested in is the
http://dev.openlayers.org/docs/files/OpenLayers/Control/DrawFeature-js.html
DrawFeature control which adds
http://dev.openlayers.org/docs/files/OpenLayers/Feature-js.html features to
a map.
A map consists of
http://dev.openlayers.org/docs/files/OpenLayers/Layer-js.html layers , so
you'll need to tell the control which layer the feature will be drawn to,
usually done by specifying the layer in the constructor.
What kind of shape is determined by the
http://dev.openlayers.org/docs/files/OpenLayers/Handler-js.html Handler you
pass to the DrawFeature control. While it is possible to write your own,
it's more than likely one already exists that does what you want.
A handler watches mouse events and interprets them a certain way. Two
separate clicks could be a line segment, a rectangle's opposite corners, or
several ways to define a circle. Often the same handler can perform
different tasks just based on the options passed to it.
This http://openlayers.org/dev/examples/modify-feature.html drawing example
has a superb number of shapes, all produced fairly simply. You'll note that
a "circle" is actual a
http://dev.openlayers.org/docs/files/OpenLayers/Handler/RegularPolygon-js.html
regular polygon with 40+ sides.
Hope this helps,
Walt Stoneburner
--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/drawing-a-box-or-circle-tp6373056p6373359.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20110517/ad568b18/attachment-0001.html
More information about the Users
mailing list