0
votes

I'm using Leaflet (v 0.7.7). It expects setting L_PREFER_CANVAS as a script tag, which is global. I wish to create 2 maps on same page, one with L_PREFER_CANVAS flag ON and once with OFF. How can I do that ?

1) I've tried setting window.L_PREFER_CANVAS before the map creation.

2) I've tried creating my layers with extended classes like this

var MyCircle = L.Circle.extend({
            statics: {
                CANVAS: true,
                SVG: false
            }
        });

then using 'new MyCircle' instead of 'L.circle'.

Neither of the two methods have the desired effect, even though the map is rendered successfully

I'm looking into leaflet code but i'm not very comfortable with its inner workings yet, due to lack of js sorcery know-how i believe

Edit: A thing that partly works is cloning the entire leaflet source under a new object (M.* instead of L.), and keep my desired flag enabled for it. But its clumsy and breaks with plugins which add their functionality to L. classes. Thereby requiring more duplication to fix, which i'm trying to avoid

1
Are you able to setup a fiddle showcasing your problem? - Matt Way

1 Answers

3
votes

Would recommend you look into migrating onto Leaflet 1.0, where preferCanvas is now a traditional option inside the map constructor...Among many other significant improvements.

http://leafletjs.com/reference-1.0.0.html#map-prefercanvas