About CRS and map origin setting, What is their relation and math equation in leaflet.js via using proj4leaflet.js

93 Views Asked by At

I meet a problem about CRS function and map origin setting in leaflet. I use proj4leaflet.js as the basic CRS function, and then after setting the origin of crs and resolution, I can get the correct maps in leaflet.js map screen, the code snippet is as following:

var resolutions = [
    66.1459656252646,
    26.458386250105836,
    13.229193125052918,
    6.614596562526459,
    2.6458386250105836,
    1.3229193125052918,
    0.6614596562526459,
    0.26458386250105836,
];
var origin = [-9799999, -1692600.0];
var epsg3826 = new L.Proj.CRS(
    "EPSG:3826",
    '+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs',
    {
        resolutions: resolutions,
        origin: origin
    });
    
var map = L.map('mmap', {
            crs: epsg3826
        });

The problem comes from the more detail design for system. When I need to set a point(longitude,latitude) which format on EPSG:4326, then , after using proj4js, the result coordinate data can not directed match to the map on EPSG:3826 format. The code snippet I used is as below:

var origin = [-9799999, -1692600.0];  //the CRS origin
proj4.defs('EPSG:3826', '+proj=tmerc +lat_0=0 +lon_0=121 +k=0.9999 +x_0=250000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs +type=crs');
proj4.defs('EPSG:3857', '+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs +type=crs');
proj4.defs("EPSG:4326", "+proj=longlat +datum=WGS84 +no_defs +type=crs");
let inputCoordinates = [-52.23412404523799, 41.318099360192335];
let transformedCoordinates6 = proj4('EPSG:4326', 'EPSG:3826').forward(inputCoordinates);
Transformed Coordinates6: -316615.0671949112,15404344.837179212

I got a immense number of coordinate:-316615.0671949112,15404344.837179212, however it can not show the correct map position via minus the origin[-9799999, -1692600.0]. I need a correct point on map in EPSG:3826 format, and then using proj4js to turn it on EPSG:4326 format, so that I could use L.marker or some other tool to draw the map in correct location in leaflet.js map screen, like following:

new L.marker([-52.21990315, 41.36829856], { icon: parkIcon }).addTo(map);

To do that, I need a correct math equation to describe origin(from the CRS origin) and map coordinate of points. What I seen now is project and unproject function in leaflet.js, and how proj4leaflet.js rewrite them , as following:

project: function (latlng) {
        var point = this._proj.forward([latlng.lng, latlng.lat]);
        return new L.Point(point[0], point[1]);
    },

unproject: function (point, unbounded) {
        var point2 = this._proj.inverse([point.x, point.y]);
        return new L.LatLng(point2[1], point2[0], unbounded);
    },

but it still not enough to solve my problem. Does any one have good idea or any material for that? any instruction is highly appreciated, thanks a lot.

0

There are 0 best solutions below