I have an OpenLayers control to draw a line on my map. That works fine. Now I added a form where the coordinates of the line are displayed. The user should be able to edit there the coordinates and on submitting the form the line should be updated.
The problem is that I end up with two lines visible. After some debugging I found out that, although I specify for DrawFeature which layer to use, the handler creates a new layer called "OpenLayers.Handler.Path". So everything I draw with the mouse is drawn on that, while the line created by submitting the form is drawn on "My Layer".
I have the following code:
layer = new OpenLayers.Layer.Vector("My Layer");
geoExtMap.map.addLayer(layer);
Control = {
line: new OpenLayers.Control.DrawFeature(layer,
OpenLayers.Handler.Path, {
callbacks: {
"point": pointHandler,
"done": doneHandler
},
handlerOptions: {
persist: true,
maxVertices: 2,
freehand: false,
layerOptions: {
styleMap: styleMapControls
}
}
})
};
geoExtMap.map.addControl(Control.line);
var points = new Array(
new OpenLayers.Geometry.Point(x1, y1).transform(EPSG, projectData.crs),
new OpenLayers.Geometry.Point(x2, y2).transform(EPSG, projectData.crs)
);
var line = new OpenLayers.Geometry.LineString(points);
var lineFeature = new OpenLayers.Feature.Vector(line, null, sketchSymbolizersControls.Line);
layer.removeAllFeatures();
layer.addFeatures([lineFeature]);
So why does the handler creates a new layer and not use the one specified?