Skip to main content
3 of 5
naming; removed helpme and thanks
Vince
  • 20.3k
  • 16
  • 48
  • 65

How do I switch the coordinate system in Leaflet?

I am using Leaflet to work with the map. I have a WMS server: L.tileLayer.wms.

function setWMSLayer(theme) {
    if (!theme.includes("SeaChart_")) theme = "SeaChart_" + theme;
    const url = `http://${FLASK_HOST}/cgi-bin/mapserv?map=/var/www/s57demo/data/map/${theme}.map`;
    wmsLocal.setUrl(url);
    wmsLocal.setParams({
        layers: theme
    });
}

const wmsLocal = L.tileLayer.wms('', {
    noWrap: false
});

It uploads .map files with the configuration of my map layers. Each .map file looks something like this:

MAP
    NAME SeaChart_DAY_BLACKBACK
    SIZE 1000 1000
    UNITS dd
    EXTENT -180 -90 180 90
    MAXSIZE 32768
    # CONFIG "MS_OPENLAYERS_JS_URL" "http://localhost/LocalOpenLayers/OpenLayers-ms60.js"
    CONFIG "MS_ERRORFILE" "/tmp/SeaChart_DAY_BLACKBACK.log"
    DEBUG 5
    CONFIG "ON_MISSING_DATA" "LOG"
    #RESOLUTION 96
    #DEFRESOLUTION 96

    PROJECTION
         'init=epsg:4326'
    END

    IMAGETYPE png
    FONTSET './fonts/fontset.lst'
    SYMBOLSET "./symbols/symbols-day.map"
    OUTPUTFORMAT
        NAME 'AGG'
        DRIVER AGG/PNG
        IMAGEMODE RGB
    END

    SHAPEPATH "../chart"

    WEB
        IMAGEPATH '/tmp/'
        IMAGEURL '/tmp/'

        METADATA
          "ows_enable_request"   "*"
          'ows_title'           'SeaChart_DAY_BLACKBACK'
          # 'ows_onlineresource'  'http://localhost/cgi-bin/mapserv.fcgi?map=/app/output/map/SeaChart_DAY_BLACKBACK.map&'
          "wms_srs" "EPSG:4326 EPSG:3857 EPSG:2950 EPSG:2949 EPSG:32188 EPSG:32187 EPSG:42403 EPSG:3857 EPSG:3979"
          "wfs_srs" "EPSG:4326 EPSG:3857 EPSG:2950 EPSG:2949 EPSG:32188 EPSG:32187 EPSG:42403 EPSG:3857 EPSG:3979"
          "labelcache_map_edge_buffer" "10"
          "wms_bbox_extended" "true"
        END
    END

    #
    #   Dummy layer to create a layer group for the color mode
    #
    LAYER
        NAME "DAY_BLACKBACK"
        GROUP "default"
        TYPE POINT
        TRANSFORM FALSE
        STATUS ON
        FEATURE
            POINTS 1 1 END
        END
    END

    #INCLUDE_GSHHS_HERE

END # Map

I use MapServer to load map tiles at this path - http://${FLASK_HOST}/cgi-bin/mapserv?map=/var/www/s57demo/data/map/${theme}.map.

Leaflet uses 3857 by default. I want to understand how I can switch the coordinate system. I understand that I can use the proj4.js and proj4leaflet.js plugins. I use them, understand how they work. But I'm not clear on how exactly I can switch my coordinate system. Additionally, I have my .map files, which also have their own projection parameters:

PROJECTION
    'init=epsg:4326'
END

I have read a lot of information on the internet about this, but everywhere the information is different and unclear to me. Can someone explain the most important points so that I understand how I can change the coordinate system?

bobr
  • 21
  • 2