[OpenLayers-Dev] Get lat/lon from user click?

Rodolfo Barriga rodolfo.barriga at gmail.com
Mon Dec 21 15:43:41 EST 2009


you can create a custom openlayer control ... something like this



OpenLayers.Control.
ClickLayerInfo = OpenLayers.Class(OpenLayers.Control, {
    defaultHandlerOptions: {
        'single': true,
        'double': false,
        'pixelTolerance': 0, //tolarance
        'stopSingle': false,
        'stopDouble': 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 = you_map.getLonLatFromViewPortPx(e.xy);

        // you cant transform you lat and lon
        // you can def a pixel buffer with the map resolution
        // you can do a asyn call
    }
});

its work for me !! :-)
gretting Rodolfo B.


2009/12/21 Robert Hicks <robhyx at gmail.com>

> Hey all, is there a way to get the coordinates of a point on the map that a
> user has just clicked on? I see Mouse-position displays the coordinates at
> the bottom of the screen, and I also see you can register muliple mouse
> events to te map, but I need to store coordinates in a javascript var to
> send in a request to my server.
>
> Thanks!
>
> --
> web http://www.hyxspace.com
> aim hyx1138
>
> _______________________________________________
> Dev mailing list
> Dev at openlayers.org
> http://openlayers.org/mailman/listinfo/dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-dev/attachments/20091221/e756457d/attachment.html


More information about the Dev mailing list