Change map image and reposition new map so markers are on correct spots.

27 views
Skip to first unread message

MrDummy

unread,
Jan 14, 2017, 7:55:41 AM1/14/17
to Leaflet
Hello users,

I am busy with leaflet map. I have still unanswered problem and i checked many examples, but no one is clear enough how it works. There is no good example found how it works.

Here is my problem:
I build a map site, with this code:

    var mapAttrib = 'Map data 2016 ©';
    var mapUrl = 'images/map/{z}/{x}/{y}.png';

    var map = new L.TileLayer(
            mapUrl, {
            attribution: mapAttrib,
            tms: true,
            continuousWorld: true,
            maxZoom: 7,
            minZoom: 3
            }
        );
    map.addLayer(map);
    map.setView(new L.LatLng(-39.3683,-67.5), 3);

It works and i have added many markers ... in latlng coords. Not in pixels coords!

Now, after a while, i found better map image. I want use new map image in my site, but there is problem: the tiles have slight different zoom (+1 diff) and also not exact same area. That causes the new map is not lined up (or calibrated) to old markers. Everything is now out of position, more moved to wrong position.

Thus, to fix the problem, i have seen methods:
- unproject code
- crs: L.CRS.Simple
- setMaxBounds
- custom projection with http://jdduarte.com/stories/2013/06/06/leaflet-js-with-custom-projection/

I need only zoom fix and align the new map to old map, so markers will back on correct spots on map with new map image.
What is easy and best method to fix the problem.
It can moved with new latlng 0,0 position or pixels position. Remember my markers are in latlng coords stored.

I need a code example to fix the problem. Then i can understand it which code is needed for my problem.
Thank you very much.

MrDummy

unread,
Jan 14, 2017, 3:01:32 PM1/14/17
to Leaflet
I need only new 0,0 origin, and for that, i need Project4Leaflet.
But the script is not easy as pie due many numbers for each zoomlevel.
The maps are both equal in scale, but second map is bigger compared to first map. If i do nothing, the new map has another 0,0 origin and that is not what i want. The zoomlevels are also equal.

The origin spot for CRS need moved in second map, to match zones.
Which methode is easy to fix my problem?

Op zaterdag 14 januari 2017 13:55:41 UTC+1 schreef MrDummy:

k_man_au

unread,
Jan 17, 2017, 3:05:37 AM1/17/17
to Leaflet
Where do your tiles come from? Could you just run some math on {z} if zoom levels are equal but the map is out of step?
Reply all
Reply to author
Forward
0 new messages