[OpenLayers-Users] Automatically Starting Line Drawing
Tim Schaub
tschaub at opengeo.org
Tue Oct 28 01:11:56 EDT 2008
Hey-
dizzle wrote:
> I have markers on a map, and when a marker is selected a popup opens with a
> button. When that button is clicked, a line DrawFeature is activated. I
> was wondering if it was possible to have the first point in the line
> automatically clicked where the original marker's location is. The point of
> this is to create a path for the marker. The user can select a marker and
> insert way-points that the marker will eventually travel across and I want
> to make sure that the line begins exactly where the marker is. Thanks in
> advance.
There is not an API (supported) method of doing what you are interested
in. Though it seems useful, and perhaps their should be.
If you can keep up with changes that may break your application, you can
hack together a solution with something like the following.
1) Open http://openlayers.org/dev/examples/modify-feature.html
2) Click on the "draw line" radio to activate the draw feature control
3) Run the following in the Firebug console:
var evt = {xy: new OpenLayers.Pixel(100, 100)};
controls.line.handler.mousedown(evt);
controls.line.handler.mouseup(evt);
In your application, you would substitute 100, 100 with the real pixel
location of your click. And you'd have to have a reference to the draw
feature control to get to its handler. This basically mocks up the
mousedown, mouseup sequence that draws the first point.
Again, this is not part of the control or handler API - you should not
expect it always to work from now until the end of OpenLayers 2.x - we
may change any non-API stuff at our leisure.
Tim
--
Tim Schaub
OpenGeo - http://opengeo.org
Expert service straight from the developers.
More information about the Users
mailing list