[OpenLayers-Users] storing mouse click during vector drawing

Alexandre Dube adube at mapgears.com
Thu Mar 19 08:48:37 EDT 2009


Hi,

  If all that matters to you is to have each of your points after 
drawing a feature, then you could register events to your DrawFeatures 
controls like this :

  controls['point'].events.register("featureadded",'' , featureAdded);

function featureAdded(evt){
    var feature = evt.feature;

    // then you have access to your geometry
    var geometry = feature.geometry;

    // you could write a function that gets all points of a geometry 
object depending on the CLASS_NAME value
}

  Use Firebug to help.

  Hope this helps,

Alexandre

wrap map wrote:
> how can i get the coordinates value on drawing of polygon at each 
> mouse click , actually i want to store each coordinates i clicked  
> during vector drawing.
>
>  currently i use this for vector drawing controls but at time of 
> drawing i cannot get the coordinates at each point i clicked during 
> drawing.
>
>     controls = {
>         point: new OpenLayers.Control.DrawFeature(vectors,
>                                 OpenLayers.Handler.Point),
>         line: new OpenLayers.Control.DrawFeature(vectors,
>                                 OpenLayers.Handler.Path),
>         polygon: new OpenLayers.Control.DrawFeature(vectors,
>                                 OpenLayers.Handler.Polygon),
>         drag: new OpenLayers.Control.DragFeature(vectors),
>        select: select,
>         regular: new OpenLayers.Control.DrawFeature(vectors,
>                             OpenLayers.Handler.RegularPolygon,
>                             { handlerOptions: { sides: 5} }),
>         modify: new OpenLayers.Control.ModifyFeature(vectors)
>            };
>
>     for (var key in controls) {
>         map.addControl(controls[key]);
>     }
>
> and for reading mouse i use :
>     map.addControl(new 
> OpenLayers.Control.MousePosition({element:document.getElementById("longlats"), 
> numdigits:3}));
>
> if it is in navigation only mode i can read and store mouse click as :
> OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
>     defaultHandlerOptions: {
>         'single': true,
>         'pixelTolerance': 0 //,       // 'stopSingle': false   
>     },
>     initialize: function(options) {
>         this.handlerOptions = OpenLayers.Util.extend(
>                         {}, this.defaultHandlerOptions
>                     );
>         OpenLayers.Control.prototype.initialize.apply(
>                         this, arguments
>                     );
>         this.handler = new OpenLayers.Handler.Click(
>                         this, { 'click': this.trigger }, 
> this.handlerOptions
>                     );
>     },
>     trigger: function(e) {
>         var lonlat = map.getLonLatFromViewPortPx(e.xy);
>         var pos = "Longitude: " + lonlat.lon + " E, <br/>Latitude: " + 
> lonlat.lat + "N";        // alert("You clicked near " + lonlat.lat + " 
> N, " +lonlat.lon + " 
> E");//OpenLayers.Util.getElement("longval").innerHTML = pos;
>         document.data1.longval.value = lonlat.lon;
>         document.data1.latval.value = lonlat.lat;
>
> but i don't got idea how can i combine these all to function together 
> while drawing vector point, line and polygon
>
>
> /nabin,
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>   


-- 
Alexandre Dubé
Mapgears
www.mapgears.com




More information about the Users mailing list