1

I would like to create points while I draw a line on my map in OpenLayers. That is, at each vertices of a line and at the end points there is a shape like a square, circle, or diamond.

I have this partially working. I can add points at the vertices of a line while I'm drawing it but they are one off. The point/shape doesn't render at the beginning of the line but at the second point in the line as you can see below. Also, the end of the line has two points/shapes; you can't see it since they are stacked.

enter image description here

Here is my code that adds the point/shape as I'm drawing my line (see the point callback in my DrawFeature control setup).

var path_control = new OpenLayers.Control.DrawFeature(
     vector_layer,
     OpenLayers.Handler.Path,
     {
          callbacks: {
               point: function( point ) {

                    console.log(point);

                    point_collection.push(point);
                    var feature = new OpenLayers.Feature.Vector( point );

                    vector_layer.addFeatures([feature]);
                    vector_layer.redraw();

               }

          }
     }
);

console.log(point) gets called at all the correct times. When I output my point_collection variable that I setup to figure out what is going on, the points are different than those output by console.log(point) from with the point callback.

I have a feeling that it has something to do with when I'm actually adding the points to the vector layer but can't figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.