1

I want to display the mouseposition in Degree Decimal rather than in meters.

enter image description here

See my code:

    <script type="text/javascript">
    var map, ia_wms;
    function init(){
        map = new OpenLayers.Map('map', {zoomDuration: 1,projection: 'EPSG:3857'});
    var esr_all = new OpenLayers.Layer.WMS("ESR_Boundary","http://localhost/cgi-bin/mapserv?map=/var/www/mstest/test_sr.map",{'layers':"ESR_outline",'transparent':true,'format':'image/png'}
           ,{
            isBaseLayer: false,opacity: 100
            }
            );
    var mslayer = new OpenLayers.Layer.WMS( "MapServer Layer",
                                          "http://localhost/cgi-bin/mapserv?map=/var/www/osm-demo/mapserver-utils-svn/osm-google_test.map&",
                                          {'layers': "land0 borders0 places0 land1 borders1 places1 land2 borders2 places2 land3 borders3 places3 land4 landuse4 transport_areas4 waterarea4 borders4 places4 land5 landuse5 transport_areas5 waterarea5 roads5 borders5 places5 land6 landuse6 transport_areas6 waterarea6 waterways6 roads6 borders6 places6 land7 landuse7 transport_areas7 waterarea7 waterways7 roads7 borders7 places7 land8 landuse8 transport_areas8 waterarea8 waterways8 railways8 roads8 borders8 places8 land9 landuse9 transport_areas9 waterarea9 waterways9 railways9 roads9 borders9 places9 land10 landuse10 transport_areas10 waterarea10 waterways10 railways10 roads10 aeroways10 borders10 places10 land11 landuse11 transport_areas11 waterarea11 waterways11 railways11 roads11 aeroways11 borders11 places11 land12 landuse12 transport_areas12 waterarea12 waterways12 railways12 roads12 aeroways12 borders12 places12 land13 landuse13 transport_areas13 waterarea13 waterways13 railways13 roads13 aeroways13 borders13 places13 land14 landuse14 transport_areas14 waterarea14 waterways14 railways14 roads14 aeroways14 borders14 places14 land15 landuse15 transport_areas15 waterarea15 waterways15 railways15 roads15 aeroways15 borders15 places15 land16 landuse16 transport_areas16 waterarea16 waterways16 railways16 roads16 aeroways16 borders16 places16 land17 landuse17 transport_areas17 waterarea17 waterways17 railways17 roads17 aeroways17 borders17 places17 land18 landuse18 transport_areas18 waterarea18 waterways18 railways18 roads18 aeroways18 borders18 places18"}
                                           );    
    map.addLayers([esr_all, mslayer]);
    map.addControl(new OpenLayers.Control.MousePosition(
    {
                prefix: 'coordinates: ',
                separator: ' | ',
                //numDigits: 2,
                //emptyString: 'Mouse is not over map.'
            })
                );      
    map.addControl(new OpenLayers.Control.LayerSwitcher());
    map.zoomToExtent(new OpenLayers.Bounds(69.00,21.00,70.00,22.00));
    map.setCenter(new OpenLayers.LonLat(69.57,21.55).transform(
    new OpenLayers.Projection('EPSG:4326', 'EPSG:3857'),
    map.getProjectionObject()
    ), 14);
    }
</script>

In mapfile I have given:

WEB
IMAGEPATH '/opt/fgs/tmp/ms_tmp/' 
IMAGEURL  '/ms_tmp/'
TEMPLATE  '/var/www/mstest/templatesample.html'
    METADATA
        "wms_enable_request"    "*"
        #"ows_enable_request" "*"
        "wms_srs" "EPSG:4326 EPSG:900913 EPSG:3857 EPSG:2154 EPSG:310642901 EPSG:4171 EPSG:310024802 EPSG:310915814 EPSG:310486805 EPSG:310702807 EPSG:310700806 EPSG:310547809 EPSG:310706808 EPSG:310642810 EPSG:310642801 EPSG:310642812 EPSG:310032811 EPSG:310642813 EPSG:2986"
        "labelcache_map_edge_buffer" "-10"
        "wms_title" "osm"
    END
 END

DEBUG 1 CONFIG "MS_ERRORFILE" "stderr" CONFIG "PROJ_LIB" "/var/www/osm-demo/mapserver-utils-svn" PROJECTION "init=epsg:900913" END

I tried to change the init=epsg to 4326 , But few layers(osm data from postgres db) ended up not drawing.

How to tackle this?

1 Answer 1

3

You can change the projection of the mouse coordinates very simply using the OpenLayers.Control.MousePosition 'displayProjection' parameter (see the documentation). For example, I have a map in EPSG900913 but can display my coordinates in EPSG:4326 like this:

new OpenLayers.Control.MousePosition({
    prefix: 'You are here: ',
    separator: ' | ',
    numDigits: 5,
    emptyString: 'Mouse is not over map.',
    displayProjection: "EPSG:4326"
});

My eyes are maybe not following your indentations and code too well, but you may also have one too many brackets at the end of your MousePosition block.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.