[OpenLayers-Users] how to limit to 1 the number of points of a
vector layer
Bart van den Eijnden (OSGIS)
bartvde at osgis.nl
Tue Aug 31 07:03:55 EDT 2010
Hi,
you could do something like:
1) use sketchstarted event to limit the number of features to 1
2) use the featureadded event to set your form field
Example code (just for reference, copy/paste from another project):
new OpenLayers.Layer.Vector("Sketch", {
displayInLayerSwitcher: false,
eventListeners: {
sketchstarted: function(evt) {
// make sure there is only 1 feature at a time
vector.destroyFeatures();
},
featureadded: setFormValues,
scope: this
}
});
var setFormValues = function(evt) {
var geometry = evt.feature.geometry;
var form = document.forms[this.formid];
var toProjection = new
OpenLayers.Projection(form.elements["epsg"].value);
geometry =
geometry.clone().transform(map.getProjectionObject(),
toProjection);
var points = geometry.getVertices();
var x = points[0].x;
var y = points[0].y;
form.elements["x"].value = x.toFixed(2);
form.elements["y"].value = y.toFixed(2);
form.elements["directionAngle"].value =
this.calculateAngle(geometry);
}
Best regards,
Bart
> hi all,
> starting from the Drag-feature example (
> http://openlayers.org/dev/examples/drag-feature.html) I need to limit to 1
> the number of points which can be added to the vector layer
> if the user, after having added one point, clicks again, the first point
> is
> deleted and only the newly created remains.
> I need this for localization purpose: i.e. "Dear User, tell me where
> THAT_THING is" so the position must be unique.
>
> I also need to extract coordinates from the point
> (document.getElementById("x_coord").value = ???)
>
> Can anyone help me?
>
> thank you in advance!
> alberto
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list