Skip to content

Commit dd0f7c0

Browse files
committed
feat: add leaflet.js framework
Moved from Google's map to Leaflet.js's API. BREAKING CHANGES: will no longer use Google Map's API
1 parent d23bec2 commit dd0f7c0

File tree

1 file changed

+53
-40
lines changed

1 file changed

+53
-40
lines changed

index.php

+53-40
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@
115115
<script src="js/bootstrap.bundle.min.js"></script>
116116
<script src="js/bootstrap.min.js"></script>
117117
<script src="js/bootstrap-notify.min.js"></script>
118+
119+
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.4/dist/leaflet.css" integrity="sha512-puBpdR0798OZvTTbP4A8Ix/l+A4dHDD0DGqYW6RQ+9jxkRFclaxxQb/SJAWZfWAkuyeQUytO7+7N4QKrDh+drA==" crossorigin=""/>
120+
<script src="https://unpkg.com/leaflet@1.3.4/dist/leaflet.js" integrity="sha512-nMMmRyTVoLYqjP9hrbed9S+FzjZHW5gY1TWCHA5ckwXZBadntCNs8kEqAWdrb9O7rxbCaA4lKTIWjDXZxflOcA==" crossorigin=""></script>
118121

119-
<script type="text/javascript" src="https://maps.google.com/maps/api/js"></script>
120122

121123
<script>
122124

@@ -154,40 +156,8 @@
154156
var _SETTINGS_debug = <?php echo json_encode($config->debug); ?>;
155157

156158
var _SETTINGS_blipUrl = "<?php echo $config->blipUrl(); ?>";
157-
158-
// Do not remove unless you know what you're doing (and you have a google api key)
159-
// Hack from https://stackoverflow.com/questions/38148097/google-maps-api-without-key/38809129#38809129
160-
// hack Google Maps to bypass API v3 key (needed since 22 June 2016 http://googlegeodevelopers.blogspot.com.es/2016/06/building-for-scale-updates-to-google.html)
161-
var target = document.head;
162-
var observer = new MutationObserver(function(mutations) {
163-
for (var i = 0; mutations[i]; ++i) { // notify when script to hack is added in HTML head
164-
if (mutations[i].addedNodes[0].nodeName == "SCRIPT" && mutations[i].addedNodes[0].src.match(/\/AuthenticationService.Authenticate?/g)) {
165-
var str = mutations[i].addedNodes[0].src.match(/[?&]callback=.*[&$]/g);
166-
if (str) {
167-
if (str[0][str[0].length - 1] == '&') {
168-
str = str[0].substring(10, str[0].length - 1);
169-
} else {
170-
str = str[0].substring(10);
171-
}
172-
var split = str.split(".");
173-
var object = split[0];
174-
var method = split[1];
175-
window[object][method] = null; // remove censorship message function _xdc_._jmzdv6 (AJAX callback name "_jmzdv6" differs depending on URL)
176-
//window[object] = {}; // when we removed the complete object _xdc_, Google Maps tiles did not load when we moved the map with the mouse (no problem with OpenStreetMap)
177-
}
178-
observer.disconnect();
179-
}
180-
}
181-
});
182-
var config = { attributes: true, childList: true, characterData: true }
183-
observer.observe(target, config);
184-
185159
</script>
186160

187-
<?php
188-
Minifier::printFirstJs($config->debug);
189-
?>
190-
191161
</head>
192162
<body>
193163

@@ -314,16 +284,59 @@
314284
<div id="map-canvas" style="position: relative; overflow: hidden; background-color: rgb(15, 168, 210);"></div>
315285
</main>
316286
</div>
287+
288+
<script src="js/src/utils.js"></script>
289+
<script>
290+
var _MAP_currentMarker;
291+
var _MAP_markerStore;
292+
var _MAP_map;
317293

318-
<?php
319-
Minifier::printLastJs($config->debug);
320-
$parser->printJsForParams();
294+
/*
295+
var greenIcon = L.icon({
296+
iconUrl: 'images/icons/debug.png',
321297

322-
if(!Update::latestVersion()){
323-
echo Update::alertJs();
324-
}
325-
?>
298+
iconSize: [23, 32], // size of the icon
299+
iconAnchor: [23, 32/2], // point of the icon which will correspond to marker's location
300+
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
301+
});
302+
var normalIcon = L.icon({
303+
iconUrl: 'images/icons/normal.png',
326304

305+
iconSize: [23, 32], // size of the icon
306+
iconAnchor: [23, 32/2], // point of the icon which will correspond to marker's location
307+
popupAnchor: [-3, -76] // point from which the popup should open relative to the iconAnchor
308+
});
309+
*/
310+
311+
var map_tiles = {
312+
"Normal" : L.tileLayer("images/tiles/normal/minimap_sea_{y}_{x}.png", {tileSize: 1024}),
313+
"Postal" : L.tileLayer("images/tiles/postal/minimap_sea_{y}_{x}.png", {tileSize: 3072})
314+
};
315+
316+
// 0, 0 in game =
317+
318+
function mapInit(elementID) {
319+
320+
_MAP_map = L.map('map-canvas', {
321+
maxZoom: 0,
322+
minZoon: 0,
323+
crs: L.CRS.Simple,
324+
layers: [map_tiles["Normal"]]
325+
}).setView([0,0], 0);
326+
//_MAP_map.setMaxBounds(new L.LatLngBounds(br, tl));
327+
328+
L.control.layers(map_tiles).addTo(_MAP_map);
329+
330+
_MAP_map.on("baselayerchange", function(e){
331+
console.log(e.layer);
332+
var recent = _MAP_map.unproject([e.layer.options.tileSize, e.layer.options.tileSize], _MAP_map.getMaxZoom());
333+
_MAP_map.setView(recent, 0);
334+
})
335+
336+
//L.tileLayer("images/tiles/minimap_{y}_{x}.png", {tileSize: 512}).addTo(_MAP_map);
337+
}
338+
mapInit();
339+
</script>
327340
</body>
328341

329342
</html>

0 commit comments

Comments
 (0)