mapserver/server/static/js/main.js

83 lines
2.2 KiB
JavaScript
Raw Normal View History

2019-02-01 14:46:38 +03:00
'use strict';
2019-01-20 21:50:24 +03:00
2019-02-01 14:46:38 +03:00
api.getConfig().then(function(cfg){
2019-01-20 21:50:24 +03:00
2019-02-01 14:46:38 +03:00
var wsChannel = new WebSocketChannel();
wsChannel.connect();
2019-01-29 23:07:29 +03:00
2019-02-01 14:46:38 +03:00
var initialZoom = 11;
var initialCenter = [0, 0];
2019-01-22 22:19:04 +03:00
2019-02-01 14:46:38 +03:00
var map = L.map('image-map', {
minZoom: 2,
maxZoom: 12,
center: initialCenter,
zoom: initialZoom,
2019-02-01 15:20:50 +03:00
crs: SimpleCRS
2019-02-01 14:46:38 +03:00
});
2019-01-29 20:00:00 +03:00
2019-02-02 19:28:35 +03:00
map.attributionControl.addAttribution('<a href="https://github.com/thomasrudin-mt/mapserver">Minetest Mapserver</a>');
2019-01-29 20:08:54 +03:00
2019-02-01 14:46:38 +03:00
var layers = {};
var overlays = {}
2019-01-20 21:50:24 +03:00
2019-02-01 15:20:50 +03:00
var layerMgr = new LayerManager(cfg.layers, map);
var tileLayer = new RealtimeTileLayer(wsChannel, 0);
2019-02-01 14:46:38 +03:00
tileLayer.addTo(map);
2019-01-20 21:50:24 +03:00
2019-02-07 09:56:52 +03:00
//TODO: all layers
2019-02-01 14:46:38 +03:00
layers["Base"] = tileLayer;
2019-02-07 09:56:52 +03:00
2019-02-14 16:16:32 +03:00
if (cfg.mapobjects.mapserver) {
overlays["Player"] = new PlayerOverlay(wsChannel, layerMgr);
overlays["POI"] = new PoiOverlay(wsChannel, layerMgr);
overlays["Labels"] = new LabelOverlay(wsChannel, layerMgr);
}
if (cfg.mapobjects.travelnet) {
overlays["Travelnet"] = new TravelnetOverlay(wsChannel, layerMgr);
}
2019-02-12 15:40:33 +03:00
if (cfg.mapobjects.bones) {
overlays["Bones"] = new BonesOverlay(wsChannel, layerMgr);
}
2019-02-14 16:16:32 +03:00
if (cfg.mapobjects.digilines) {
overlays["Digilines LCD"] = new LcdOverlay(wsChannel, layerMgr);
}
if (cfg.mapobjects.digiterms) {
overlays["Digiterms"] = new DigitermOverlay(wsChannel, layerMgr);
}
if (cfg.mapobjects.luacontroller) {
overlays["Lua Controller"] = new LuacontrollerOverlay(wsChannel, layerMgr);
}
if (cfg.mapobjects.technic) {
overlays["Technic Anchor"] = new TechnicAnchorOverlay(wsChannel, layerMgr);
overlays["Technic Quarry"] = new TechnicQuarryOverlay(wsChannel, layerMgr);
overlays["Technic Switching station"] = new TechnicSwitchOverlay(wsChannel, layerMgr);
}
if (cfg.mapobjects.protector) {
overlays["Protector"] = new ProtectorOverlay(wsChannel, layerMgr);
}
2019-02-08 17:25:37 +03:00
overlays["Missions"] = new MissionOverlay(wsChannel, layerMgr);
2019-01-29 20:08:54 +03:00
2019-02-08 10:27:10 +03:00
//Default enabled overlays
2019-02-07 21:01:00 +03:00
map.addLayer(overlays["Player"]);
2019-02-08 10:27:10 +03:00
map.addLayer(overlays["POI"]);
2019-02-08 17:12:40 +03:00
map.addLayer(overlays["Labels"]);
2019-02-05 23:17:14 +03:00
2019-02-01 14:46:38 +03:00
L.control.layers(layers, overlays).addTo(map);
2019-01-20 21:50:24 +03:00
2019-02-07 09:56:52 +03:00
new CoordinatesDisplay({ position: 'bottomleft' }).addTo(map);
new WorldInfoDisplay(wsChannel, { position: 'bottomright' }).addTo(map);
2019-02-04 23:25:30 +03:00
2019-02-04 23:15:00 +03:00
}).catch(function(e){
console.error(e);
2019-02-01 14:46:38 +03:00
});