change the crs property of map dynamically
See original GitHub issueRecently one of our project need to change the crs at run-time(during we change the base layer of the map), and I found someone have meet the same requirement through #1818 , I have tried the manner it mentioned(by using the baselayerchange event, however the author use leaflet 0.5 while I am using 0.7.2 . Which means that it does not work.
So I tried to make it myself, this is what I tried:
layer.on('add',function(){
var crs=getCrsByLayer(this);
map.options.crs=crs; //reset the crs of the map
//we have to clear this two properties, or the coord of the tile would be re-wrapped wrongly by the former crs of the map
layer._wrapLng=null;
layer._wrapLat=null;
//it seems that the tiles calculation procedure have been done before the add event fired, so hack it to redraw the layer.
layer.redraw();
});
However it does not work, so I tried to dig into the codes, and finally I found that the _initialTopLeftPoint property of the map does not changed when I reset the crs through map.options.crs, which means the tiles bounds will not calculated correctly. Since this is a private property, I do not think set it outside is a good idea.
So I think if you can re-consider this feature? It does not cause more codes, you just make the crs related property can be re-initialized.
Thank you.
Issue Analytics
- State:
- Created 10 years ago
- Reactions:2
- Comments:38 (14 by maintainers)

Top Related StackOverflow Question
It’s the same problem at /issues/2553.And I use the baselayerchange Layer events to change multiple maps,Baidu use the CRS EPSG:900913,other map use EPSG3857.This is my demo:https://lhywell.github.io/map/example/example2/leaf2.html
@Hashedhash, I have found a solution, it works but as not well as I’d like to. Something like this: