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

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
                );
                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.getLonLatFromPixel(e.xy);
                alert("You clicked near " + lonlat.lat + " N, " +
                                          + lonlat.lon + " E");
            }

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

            var ol_wms = new OpenLayers.Layer.WMS( "OpenLayers WMS",
                "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} );

        var jpl_wms = new OpenLayers.Layer.WMS( "NASA Global Mosaic",
            "http://t1.hypercube.telascience.org/cgi-bin/landsat7", 
            {layers: "landsat7"});

            jpl_wms.setVisibility(false);

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

            var click = new OpenLayers.Control.Click();
            map.addControl(click);
            click.activate();

        }
share|improve this question
1  
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

 
discard

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

Browse other questions tagged or ask your own question.