shramov / leaflet-plugins

Plugins for Leaflet library
http://psha.org.ru/b/leaflet-plugins.html
MIT License
722 stars 288 forks source link

Not working with https://github.com/Igor-Vladyka/leaflet.browser.print #278

Open ramblerswebs opened 5 years ago

ramblerswebs commented 5 years ago

I have version 3.0.3 working fine but I am trying to get a map print option working. I have added https://github.com/Igor-Vladyka/leaflet.browser.print as a print option. This is working fine with OSM and the topo version of the maps. I am using Bing maps, aerial and OS options. They work fine until I try and print them. It appears to fail in leaflet.js where leaflet is trying to replace subdomain and quadkey in the map tile url I am using leaflet 1.3.1 and the errors appear in line 178 in the function template(str, data) where the variable value is undefined.

I am not sure how to proceed or what diagnostic information I can provide.

ramblerswebs commented 5 years ago

I have made progress on this and got it working but with a fix. Firstly I was not registering BingLayer with the print software, my fault.. Once I had done that I found that the BingLayer did not know what url to use to access the tiles. I hence ended up with this additional code.

if (ramblersMap.options.bing) { L.Control.BrowserPrint.Utils.registerLayer( L.BingLayer, "L.BingLayer", function (layer) { bing = L.bingLayer(layer.key, layer.options); bing._url = ramblersMap.currentLayer._url; return bing; } ); } } ramblersMap.map.on('baselayerchange', function (e) { ramblersMap.currentLayer=e.layer; //alert('Changed to ' + e.name); });

I had to add the line bing._url = ramblersMap.currentLayer._url; to set the url correctly. When the print software calls this function the BingLayer does not seem to be initialized correctly. I don't know if this is the Print software's fault or BingLayer. The fix above works fine. It is taking the url from the current tilelayer and using that. (Not sure why the Print software sets up another tileLayer)