Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I've been playing around with the OpenLayers click event handler example, which you can see here. It tell you the coordinates where you have clicked but I am trying to change this to be in decimal degrees, I believe this is epsg:900913. I've tried adding in transformation but it seems to have just made them coordinates all messed up

var tranlonlat = lonlat.transform(
                      new OpenLayers.Projection("EPSG:4326"),
                      new OpenLayers.Projection("EPSG:900913")  

this is the original code:

OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {                
            defaultHandlerOptions: {
                'single': true,
                'double': false,
                'pixelTolerance': 0,
                'stopSingle': false,
                'stopDouble': false

            initialize: function(options) {
                this.handlerOptions = OpenLayers.Util.extend(
                    {}, this.defaultHandlerOptions
                    this, arguments
                this.handler = new OpenLayers.Handler.Click(
                    this, {
                        'click': this.trigger
                    }, this.handlerOptions

            trigger: function(e) {
                var lonlat = map.getLonLatFromPixel(e.xy);
                alert("You clicked near " + + " N, " +
                                          + lonlat.lon + " E");

        var map;
        function init(){
            map = new OpenLayers.Map('map');

            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "", {layers: 'basic'} );

        var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
            {layers: "landsat7"});


            map.addLayers([ol_wms, jpl_wms]);
            map.addControl(new OpenLayers.Control.LayerSwitcher());
            // map.setCenter(new OpenLayers.LonLat(0, 0), 0);

            var click = new OpenLayers.Control.Click();

share|improve this question
Before and after coords example? In the transform function, I would expect that you list the two coordinate ref systems in from, to order, so shouldn't they be reversed? I don't know the sw, but I may recognize the crs values. –  mkennedy Jul 12 '13 at 15:57
you're absolutely right. I thought that that order was the only logical way but I must be wrong. Thanks! –  whatahitson Jul 12 '13 at 16:02

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.