BlueMapWeb/public/index.html

85 lines
3.2 KiB
HTML
Raw Normal View History

2021-01-18 16:51:03 +01:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1">
2021-01-18 16:51:03 +01:00
<title>BlueMap Lib Test</title>
<link rel="shortcut icon" href="favicon.png">
</head>
<body style="margin: 0; padding: 0;">
2021-01-28 19:57:54 +01:00
<div id="map-container" style="position: absolute; width: 100%; height: 100%;"></div>
2021-01-18 16:51:03 +01:00
<script type="text/javascript" src="js/three.js"></script>
<script type="text/javascript" src="js/hammer.js"></script>
<script type="text/javascript" src="js/bluemap.js"></script>
<script type="text/javascript">
let bluemap = new BlueMap.MapViewer(document.getElementById("map-container"));
// show stats panel
bluemap.stats.showPanel(1);
2021-02-19 16:06:47 +01:00
let mapControls = new BlueMap.MapControls(bluemap.rootElement);
let freeControls = new BlueMap.FreeFlightControls(bluemap.rootElement);
2021-02-19 16:06:47 +01:00
bluemap.controlsManager.controls = mapControls;
2021-01-18 16:51:03 +01:00
// load map
2021-02-19 16:06:47 +01:00
const loadMaps = (dataUrl, events = null) => {
function loadSettings() {
return new Promise((resolve, reject) => {
let loader = new THREE.FileLoader();
loader.setResponseType("json");
loader.load(dataUrl + "settings.json",
resolve,
() => {},
() => reject("Failed to load the settings.json!")
);
});
}
return loadSettings().then(settings => {
let maps = [];
// create maps
if (settings.maps !== undefined){
for (let mapId in settings.maps) {
if (!settings.maps.hasOwnProperty(mapId)) continue;
let mapSettings = settings.maps[mapId];
if (mapSettings.enabled)
maps.push(new BlueMap.Map(mapId, dataUrl + mapId + "/", dataUrl + "settings.json", dataUrl + "textures.json", events));
}
}
// sort maps
maps.sort((map1, map2) => {
let sort = settings.maps[map1.id].ordinal - settings.maps[map2.id].ordinal;
if (isNaN(sort)) return 0;
return sort;
});
return maps;
});
}
2021-01-18 16:51:03 +01:00
let maps = [];
let markerManager = null;
2021-01-28 19:57:54 +01:00
let playerManager = null;
2021-02-19 16:06:47 +01:00
loadMaps("data/", bluemap.events).then(loadedMaps => {
2021-01-18 16:51:03 +01:00
maps = loadedMaps;
markerManager = new BlueMap.MarkerFileManager(bluemap.markers, "data/markers.json", maps[0].data.id, bluemap.events);
markerManager.update();
markerManager.setAutoUpdateInterval(1000 * 10);
2021-01-28 19:57:54 +01:00
playerManager = new BlueMap.PlayerMarkerManager(bluemap.markers, "live/players", "", bluemap.events);
2021-01-28 19:57:54 +01:00
playerManager.update();
playerManager.setAutoUpdateInterval(1000);
2021-02-19 16:06:47 +01:00
bluemap.switchMap(maps[0]).then(() => {
playerManager.worldId = maps[0].data.world;
2021-01-28 19:57:54 +01:00
});
2021-01-18 16:51:03 +01:00
});
</script>
</body>
</html>