PluginProbe
Leaflet Map / 2.10.0
Leaflet Map v2.10.0
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / scripts / construct-leaflet-map.js

construct-leaflet-map.js in Leaflet Map 2.10.0, at scripts/construct-leaflet-map.js

79 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function() {
2 // holds a function queue to call once page is loaded
3 function Main() {
4 var init_functions = [];
5
6 // this function iterates all map creation functions
7 this.init = function() {
8 for (var i = 0, len = init_functions.length; i < len; i++) {
9 var fnc = init_functions[i];
10 fnc();
11 }
12 };
13
14 // this is the function we use to create all map objects
15 this.add = function(fnc) {
16 init_functions.push(fnc);
17 };
18
19 this.getCurrentMap = function() {
20 // maps are created iteratively, so the last map is the current map
21 return this.maps[this.maps.length - 1];
22 };
23
24 this.getCurrentMarkerGroup = function() {
25 // marker groups are mapid -> feature group
26 var mapid = this.maps.length;
27 if (!this.markergroups[mapid]) {
28 this.markergroups[mapid] = this.newMarkerGroup(this.maps[mapid - 1]);
29 }
30 return this.markergroups[mapid];
31 };
32
33 this.newMarkerGroup = function(map) {
34 var mg = new L.FeatureGroup().addTo(map);
35
36 mg.timeout = null;
37
38 // custom attribute
39 if (map.fit_markers) {
40 mg.on('layeradd', function(d) {
41 // needs a timeout so that it doesn't
42 // opt out of a bound change
43 window.clearTimeout(this.timeout);
44 this.timeout = window.setTimeout(function() {
45 map.fitBounds(mg.getBounds());
46 }, 100);
47 }, mg);
48 }
49
50 return mg;
51 };
52
53 // these accessible properties hold map objects
54 this.maps = [];
55 this.images = [];
56 this.markergroups = {};
57 this.markers = [];
58 this.lines = [];
59 }
60
61 Main.prototype.unescape = function(str) {
62 var div = document.createElement('div');
63 div.innerHTML = str;
64 return div.innerText;
65 };
66
67 window.WPLeafletMapPlugin = new Main();
68
69 // initialize the function
70 if (window.addEventListener) {
71 window.addEventListener('load', window.WPLeafletMapPlugin.init, false);
72 } else if (window.attachEvent) {
73 window.attachEvent('onload', function() {
74 // hopefully this helps any references to `this`
75 window.WPLeafletMapPlugin.init();
76 });
77 }
78 })();
79