|
16 | 16 | // along with this program in the file "LICENSE". If not, see <http://www.gnu.org/licenses/>.
|
17 | 17 | // ************************************************************************** //
|
18 | 18 |
|
19 |
| -var _MAP_currentMarker; |
20 |
| -var _MAP_markerStore = []; |
21 |
| -var _MAP_map; |
22 |
| - |
23 |
| -var _MAP_tiles = { |
24 |
| - "Normal": L.tileLayer("images/tiles/normal/minimap_sea_{y}_{x}.png", { minZoom: -2, maxZoom: 0, maxNativeZoom: 0, minNativeZoom: 0, tileSize: 1024 }), //Originally had the "tileSize" attribute set. Removing it allows for the "zoomed out" look |
25 |
| - "Postal": L.tileLayer("images/tiles/postal/minimap_sea_{y}_{x}.png", { minZoom: -4, maxZoom: 0, maxNativeZoom: 0, minNativeZoom: 0, tileSize: 3072 }) |
26 |
| -}; |
27 |
| - |
28 |
| -var _MAP_currentLayer = _MAP_tiles["Normal"]; |
| 19 | +window.MarkerStore = []; |
| 20 | +window.CurrentLayer = undefined; |
29 | 21 |
|
30 | 22 | function mapInit(elementID) {
|
31 | 23 |
|
32 | 24 | // Create the different layers
|
| 25 | + var tileLayers = {}; |
33 | 26 | var maps = window.config.maps;
|
34 |
| - console.log("maps:" + maps); |
| 27 | + maps.forEach(map => { |
| 28 | + console.log(map); |
| 29 | + tileLayers[map.name] = L.tileLayer(map.url, |
| 30 | + Object.assign( |
| 31 | + { minZoom: -2, maxZoom: 0, maxNativeZoom: 0, minNativeZoom: 0, tileSize: 1024, tileDirectory: config.tileDirectory }, |
| 32 | + map) |
| 33 | + ); |
| 34 | + console.log(tileLayers[map.name]); |
| 35 | + }); |
| 36 | + |
| 37 | + CurrentLayer = tileLayers[Object.keys(tileLayers)[0]]; |
35 | 38 |
|
36 |
| - _MAP_map = L.map(elementID, { |
| 39 | + window.Map = L.map(elementID, { |
37 | 40 | crs: L.CRS.Simple,
|
38 |
| - layers: [_MAP_currentLayer] |
| 41 | + layers: [CurrentLayer] |
39 | 42 | }).setView([0,0], 0);
|
40 | 43 |
|
41 |
| - // Use the "normal" bounds since, it's default. |
42 |
| - var h = _MAP_currentLayer.options.tileSize * 3, |
43 |
| - w = _MAP_currentLayer.options.tileSize * 2; |
| 44 | + var h = CurrentLayer.options.tileSize * 3, |
| 45 | + w = CurrentLayer.options.tileSize * 2; |
44 | 46 |
|
45 |
| - var southWest = _MAP_map.unproject([0, h], _MAP_map.getMaxZoom()); |
46 |
| - var northEast = _MAP_map.unproject([w, 0], _MAP_map.getMaxZoom()); |
| 47 | + var southWest = Map.unproject([0, h], Map.getMaxZoom()); |
| 48 | + var northEast = Map.unproject([w, 0], Map.getMaxZoom()); |
47 | 49 | var mapBounds = new L.LatLngBounds(southWest, northEast);
|
48 | 50 |
|
49 |
| - _MAP_map.setMaxBounds(mapBounds); |
50 |
| - L.control.layers(_MAP_tiles).addTo(_MAP_map); |
| 51 | + Map.setMaxBounds(mapBounds); |
| 52 | + L.control.layers(tileLayers).addTo(Map); |
51 | 53 |
|
52 |
| - _MAP_map.on("baselayerchange", function (e) { |
| 54 | + Map.on("baselayerchange", function (e) { |
53 | 55 | var h = e.layer.options.tileSize * 3,
|
54 | 56 | w = e.layer.options.tileSize * 2;
|
55 | 57 |
|
56 |
| - var southWest = _MAP_map.unproject([0, h], _MAP_map.getMaxZoom()); |
57 |
| - var northEast = _MAP_map.unproject([w, 0], _MAP_map.getMaxZoom()); |
| 58 | + var southWest = Map.unproject([0, h], Map.getMaxZoom()); |
| 59 | + var northEast = Map.unproject([w, 0], Map.getMaxZoom()); |
58 | 60 |
|
59 | 61 | var mapBounds = new L.LatLngBounds(southWest, northEast);
|
60 | 62 |
|
61 |
| - _MAP_map.setMaxBounds(mapBounds); |
62 |
| - _MAP_currentLayer = e.layer; |
| 63 | + Map.setMaxBounds(mapBounds); |
| 64 | + CurrentLayer = e.layer; |
63 | 65 |
|
64 | 66 | clearAllMarkers();
|
65 | 67 | toggleBlips();
|
66 | 68 | });
|
67 | 69 |
|
68 |
| - _MAP_map.on('click', function (e) { |
69 |
| - //console.log(e); |
| 70 | + Map.on('click', function (e) { |
70 | 71 | });
|
71 |
| - //L.tileLayer("images/tiles/minimap_{y}_{x}.png", {tileSize: 512}).addTo(_MAP_map); |
72 |
| - |
73 |
| - ///_MAP_map.setCenter([w * 0.5, h * 0.5]); |
74 | 72 | }
|
75 | 73 |
|
76 | 74 | function createMarker(animated, draggable, objectRef, title) {
|
@@ -101,49 +99,49 @@ function createMarker(animated, draggable, objectRef, title) {
|
101 | 99 |
|
102 | 100 | var marker = L.marker(coord, {
|
103 | 101 | title: title,
|
104 |
| - id: _MAP_markerStore.length, |
| 102 | + id: MarkerStore.length, |
105 | 103 | icon: image,
|
106 | 104 | object: objectRef,
|
107 | 105 | draggable: draggable ? true : false
|
108 |
| - }).addTo(_MAP_map).bindPopup(infoContent); |
| 106 | + }).addTo(Map).bindPopup(infoContent); |
109 | 107 |
|
110 |
| - _MAP_markerStore.push(marker); |
111 |
| - return _MAP_markerStore.length; |
| 108 | + MarkerStore.push(marker); |
| 109 | + return MarkerStore.length; |
112 | 110 | }
|
113 | 111 |
|
114 | 112 | function setMapCenter(lat, lng) {
|
115 |
| - _MAP_map.setCenter([lat, lng]); |
116 |
| - _MAP_map.setZoom(6); |
| 113 | + Map.setCenter([lat, lng]); |
| 114 | + Map.setZoom(6); |
117 | 115 | }
|
118 | 116 |
|
119 | 117 | function setMapCenterLeaflet(coord) {
|
120 |
| - _MAP_map.setCenter(coord); |
121 |
| - _MAP_map.setZoom(6); |
| 118 | + Map.setCenter(coord); |
| 119 | + Map.setZoom(6); |
122 | 120 | }
|
123 | 121 |
|
124 | 122 | function clearAllMarkers() {
|
125 |
| - for (var i = 0; i < _MAP_markerStore.length; i++) { |
126 |
| - if (_MAP_markerStore[i] != "NULL") { |
127 |
| - _MAP_markerStore[i].remove(); |
| 123 | + for (var i = 0; i < MarkerStore.length; i++) { |
| 124 | + if (MarkerStore[i] != "NULL") { |
| 125 | + MarkerStore[i].remove(); |
128 | 126 | }
|
129 | 127 | }
|
130 |
| - _MAP_markerStore.length = 0; |
| 128 | + MarkerStore.length = 0; |
131 | 129 | // Re-do player markers
|
132 | 130 | for(var id in localCache){
|
133 | 131 | localCache[id].marker = null;
|
134 | 132 | }
|
135 | 133 | }
|
136 | 134 |
|
137 | 135 | function clearMarker(id) {
|
138 |
| - if (_MAP_markerStore[id] != "NULL") { |
139 |
| - _MAP_markerStore[id].remove(); |
140 |
| - _MAP_markerStore[id] = "NULL"; |
| 136 | + if (MarkerStore[id] != "NULL") { |
| 137 | + MarkerStore[id].remove(); |
| 138 | + MarkerStore[id] = "NULL"; |
141 | 139 | $("#marker_" + id).remove();
|
142 | 140 | }
|
143 | 141 | }
|
144 | 142 |
|
145 | 143 | function getMarker(id) {
|
146 |
| - if (_MAP_markerStore[id] != "NULL") { |
147 |
| - return _MAP_markerStore[id]; |
| 144 | + if (MarkerStore[id] != "NULL") { |
| 145 | + return MarkerStore[id]; |
148 | 146 | }
|
149 | 147 | };
|
0 commit comments