Add tset config to leaflet layer, refactor marker
Instead of stuffing specialised values into overviewer.collections, put a reference to the overviewerConfig tileset entry into the leaflet layer, so that we can access it from callbacks easily.
This commit is contained in:
@@ -52,16 +52,13 @@ overviewer.collections = {
|
|||||||
'markerInfo': {},
|
'markerInfo': {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* holds a reference to the current spawn marker.
|
* holds a reference to the spawn marker.
|
||||||
*/
|
*/
|
||||||
'spawnMarker': null,
|
'spawnMarker': null,
|
||||||
/**
|
|
||||||
* contains the spawn marker for each world
|
|
||||||
*/
|
|
||||||
'spawnMarkers': {},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* if a user visits a specific URL, this marker will point to the coordinates in the hash
|
* if a user visits a specific URL, this marker will point to the
|
||||||
|
* coordinates in the hash
|
||||||
*/
|
*/
|
||||||
'locationMarker': null
|
'locationMarker': null
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -109,14 +109,23 @@ overviewer.util = {
|
|||||||
|
|
||||||
overviewer.map.on('baselayerchange', function(ev) {
|
overviewer.map.on('baselayerchange', function(ev) {
|
||||||
overviewer.current_layer[overviewer.current_world] = ev.name;
|
overviewer.current_layer[overviewer.current_world] = ev.name;
|
||||||
|
var ovconf = ev.layer.tileSetConfig;
|
||||||
|
|
||||||
// Remove old spawn marker, add new one
|
// Remove old spawn marker, add new one
|
||||||
if (overviewer.collections.spawnMarker) {
|
if (overviewer.collections.spawnMarker) {
|
||||||
overviewer.collections.spawnMarker.remove();
|
overviewer.collections.spawnMarker.remove();
|
||||||
}
|
}
|
||||||
if (overviewer.collections.spawnMarkers[overviewer.current_world]) {
|
if (typeof(ovconf.spawn) == "object") {
|
||||||
overviewer.collections.spawnMarker = overviewer.collections
|
/// TODO: Retina Icon
|
||||||
.spawnMarkers[overviewer.current_world];
|
var spawnIcon = L.icon({
|
||||||
|
iconUrl: overviewerConfig.CONST.image.spawnMarker,
|
||||||
|
});
|
||||||
|
var latlng = overviewer.util.fromWorldToLatLng(ovconf.spawn[0],
|
||||||
|
ovconf.spawn[1],
|
||||||
|
ovconf.spawn[2],
|
||||||
|
ovconf);
|
||||||
|
var ohaimark = L.marker(latlng, {icon: spawnIcon, title: "Spawn"});
|
||||||
|
overviewer.collections.spawnMarker = ohaimark
|
||||||
overviewer.collections.spawnMarker.addTo(overviewer.map);
|
overviewer.collections.spawnMarker.addTo(overviewer.map);
|
||||||
} else {
|
} else {
|
||||||
overviewer.collections.spawnMarker = null;
|
overviewer.collections.spawnMarker = null;
|
||||||
@@ -160,17 +169,12 @@ overviewer.util = {
|
|||||||
overviewer.collections.mapTypes[obj.world][obj.name] = myLayer;
|
overviewer.collections.mapTypes[obj.world][obj.name] = myLayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
myLayer["tileSetConfig"] = obj;
|
||||||
|
|
||||||
|
|
||||||
if (typeof(obj.spawn) == "object") {
|
if (typeof(obj.spawn) == "object") {
|
||||||
var latlng = overviewer.util.fromWorldToLatLng(obj.spawn[0], obj.spawn[1], obj.spawn[2], obj);
|
var latlng = overviewer.util.fromWorldToLatLng(obj.spawn[0], obj.spawn[1], obj.spawn[2], obj);
|
||||||
overviewer.collections.centers[obj.world] = [ latlng, 1 ];
|
overviewer.collections.centers[obj.world] = [ latlng, 1 ];
|
||||||
|
|
||||||
/// TODO: Retina Icon
|
|
||||||
var spawnIcon = L.icon({
|
|
||||||
iconUrl: overviewerConfig.CONST.image.spawnMarker,
|
|
||||||
});
|
|
||||||
var ohaimark = L.marker(latlng, {icon: spawnIcon, title: "Spawn"});
|
|
||||||
overviewer.collections.spawnMarkers[obj.world] = ohaimark;
|
|
||||||
} else {
|
} else {
|
||||||
overviewer.collections.centers[obj.world] = [ [0, 0], 1 ];
|
overviewer.collections.centers[obj.world] = [ [0, 0], 1 ];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user