diff --git a/server/static/js/.jshintrc b/server/static/js/.jshintrc index 3eff30a..7ac1881 100644 --- a/server/static/js/.jshintrc +++ b/server/static/js/.jshintrc @@ -4,9 +4,7 @@ "esversion": 6, "browser": true, "globals": { - "debounce": true, "L": true, - "m": true, - "api": true + "m": true } } diff --git a/server/static/js/Hashroute.js b/server/static/js/Hashroute.js index 727a702..f3b3777 100644 --- a/server/static/js/Hashroute.js +++ b/server/static/js/Hashroute.js @@ -1,4 +1,3 @@ -/* exported Hashroute */ export default { diff --git a/server/static/js/LayerManager.js b/server/static/js/LayerManager.js index 4f724fe..6d0d395 100644 --- a/server/static/js/LayerManager.js +++ b/server/static/js/LayerManager.js @@ -1,77 +1,78 @@ -/* exported LayerManager */ -/* globals RealtimeTileLayer: true */ +import RealtimeTileLayer from './RealtimeTileLayer.js'; -function LayerManager(wsChannel, layers, map, currentLayerId){ - this.listeners = []; - this.currentLayer = layers[0]; - this.layers = layers; - this.map = map; - this.layerObjects = {}; +class LayerManager { - var self = this; + setup(wsChannel, layers, map, currentLayerId){ + this.listeners = []; + this.currentLayer = layers[0]; + this.layers = layers; + this.map = map; + this.layerObjects = {}; - //All layers - layers.forEach(function(layer){ - var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map); - self.layerObjects[layer.name] = tileLayer; - if (layer.id == currentLayerId){ - tileLayer.addTo(map); - self.currentLayer = layer; - } - }); + var self = this; - map.on('baselayerchange', function (e) { - self.setLayerId(e.layer.layerId); - }); + //All layers + layers.forEach(function(layer){ + var tileLayer = new RealtimeTileLayer(wsChannel, layer.id, map); + self.layerObjects[layer.name] = tileLayer; + if (layer.id == currentLayerId){ + tileLayer.addTo(map); + self.currentLayer = layer; + } + }); + map.on('baselayerchange', function (e) { + self.setLayerId(e.layer.layerId); + }); + } + + switchLayer(layerId){ + var self = this; + Object.keys(this.layerObjects).forEach(function(key){ + var layerObj = self.layerObjects[key]; + if (self.map.hasLayer(layerObj)){ + self.map.removeLayer(layerObj); + } + }); + + Object.keys(this.layerObjects).forEach(function(key){ + var layerObj = self.layerObjects[key]; + if (layerObj.layerId == layerId){ + self.map.addLayer(layerObj); + } + }); + } + + setLayerId(layerId){ + var self = this; + this.layers.forEach(function(layer){ + if (layer.id == layerId){ + self.currentLayer = layer; + self.listeners.forEach(function(listener){ + listener(layer); + }); + return; + } + }); + } + + getLayerByY(y){ + return this.layers.find(layer => (y >= (layer.from*16) && y <= (layer.to*16))); + } + + addListener(listener){ + this.listeners.push(listener); + } + + removeListener(listener){ + this.listeners = this.listeners.filter(function(el){ + return el != listener; + }); + } + + getCurrentLayer(){ + return this.currentLayer; + } } -LayerManager.prototype.switchLayer = function(layerId){ - var self = this; - Object.keys(this.layerObjects).forEach(function(key){ - var layerObj = self.layerObjects[key]; - if (self.map.hasLayer(layerObj)){ - self.map.removeLayer(layerObj); - } - }); - - Object.keys(this.layerObjects).forEach(function(key){ - var layerObj = self.layerObjects[key]; - if (layerObj.layerId == layerId){ - self.map.addLayer(layerObj); - } - }); -}; - -LayerManager.prototype.setLayerId = function(layerId){ - var self = this; - this.layers.forEach(function(layer){ - if (layer.id == layerId){ - self.currentLayer = layer; - self.listeners.forEach(function(listener){ - listener(layer); - }); - return; - } - }); -}; - -LayerManager.prototype.getLayerByY = function(y){ - return this.layers.find(function(layer){ - return (y >= (layer.from*16) && y <= (layer.to*16)); - }); -}; - -LayerManager.prototype.addListener = function(listener){ - this.listeners.push(listener); -}; - -LayerManager.prototype.removeListener = function(listener){ - this.listeners = this.listeners.filter(function(el){ - return el != listener; - }); -}; - -LayerManager.prototype.getCurrentLayer = function(){ - return this.currentLayer; -}; +export default new LayerManager(); diff --git a/server/static/js/Overlaysetup.js b/server/static/js/Overlaysetup.js index 8b2650b..6e4dfde 100644 --- a/server/static/js/Overlaysetup.js +++ b/server/static/js/Overlaysetup.js @@ -1,160 +1,184 @@ -/* jshint undef: false */ -/* exported Overlaysetup */ +import PlayerOverlay from './overlays/PlayerOverlay.js'; +import PoiOverlay from './overlays/PoiOverlay.js'; +import ShopOverlay from './overlays/ShopOverlay.js'; +import LabelOverlay from './overlays/LabelOverlay.js'; +import TrainlineOverlay from './overlays/TrainlineOverlay.js'; +import TravelnetOverlay from './overlays/TravelnetOverlay.js'; +import BonesOverlay from './overlays/BonesOverlay.js'; +import LcdOverlay from './overlays/LcdOverlay.js'; +import DigitermOverlay from './overlays/DigitermOverlay.js'; +import LuacontrollerOverlay from './overlays/LuacontrollerOverlay.js'; +import TechnicAnchorOverlay from './overlays/TechnicAnchorOverlay.js'; +import TechnicQuarryOverlay from './overlays/TechnicQuarryOverlay.js'; +import TechnicSwitchOverlay from './overlays/TechnicSwitchOverlay.js'; +import ProtectorOverlay from './overlays/ProtectorOverlay.js'; +import XPProtectorOverlay from './overlays/XPProtectorOverlay.js'; +import PrivProtectorOverlay from './overlays/PrivProtectorOverlay.js'; +import MissionOverlay from './overlays/MissionOverlay.js'; +import MinecartOverlay from './overlays/MinecartOverlay.js'; +import ATMOverlay from './overlays/ATMOverlay.js'; +import LocatorOverlay from './overlays/LocatorOverlay.js'; +import BorderOverlay from './overlays/BorderOverlay.js'; +import TrainOverlay from './overlays/TrainOverlay.js'; -function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ +export default function(cfg, map, overlays, wsChannel, layerMgr){ - if (cfg.mapobjects.mapserver_player) { - overlays.Player = new PlayerOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mapserver_player") >= 0) { - map.addLayer(overlays.Player); - } + function isDefault(key){ + return cfg.defaultoverlays.indexOf(key) >= 0; + } + + if (cfg.mapobjects.mapserver_player) { + overlays.Player = new PlayerOverlay(wsChannel, layerMgr); + if (isDefault("mapserver_player")) { + map.addLayer(overlays.Player); } + } - if (cfg.mapobjects.mapserver_poi) { - overlays.POI = new PoiOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mapserver_poi") >= 0) { - map.addLayer(overlays.POI); - } + if (cfg.mapobjects.mapserver_poi) { + overlays.POI = new PoiOverlay(wsChannel, layerMgr); + if (isDefault("mapserver_poi")) { + map.addLayer(overlays.POI); } + } - if (cfg.mapobjects.smartshop || cfg.mapobjects.fancyvend) { - overlays.Shop = new ShopOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("smartshop") >= 0 || cfg.defaultoverlays.indexOf("fancyvend") >= 0) { - map.addLayer(overlays.Shop); - } + if (cfg.mapobjects.smartshop || cfg.mapobjects.fancyvend) { + overlays.Shop = new ShopOverlay(wsChannel, layerMgr); + if (isDefault("smartshop") || isDefault("fancyvend")) { + map.addLayer(overlays.Shop); } + } - if (cfg.mapobjects.mapserver_label) { - overlays.Label = new LabelOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mapserver_label") >= 0) { - map.addLayer(overlays.Label); - } + if (cfg.mapobjects.mapserver_label) { + overlays.Label = new LabelOverlay(wsChannel, layerMgr); + if (isDefault("mapserver_label")) { + map.addLayer(overlays.Label); } + } - if (cfg.mapobjects.mapserver_trainline) { - overlays.Trainlines = new TrainlineOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mapserver_trainline") >= 0) { - map.addLayer(overlays.Trainlines); - } + if (cfg.mapobjects.mapserver_trainline) { + overlays.Trainlines = new TrainlineOverlay(wsChannel, layerMgr); + if (isDefault("mapserver_trainline")) { + map.addLayer(overlays.Trainlines); } + } - if (cfg.mapobjects.mapserver_border) { - overlays.Border = new BorderOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mapserver_border") >= 0) { - map.addLayer(overlays.Border); - } + if (cfg.mapobjects.mapserver_border) { + overlays.Border = new BorderOverlay(wsChannel, layerMgr); + if (isDefault("mapserver_border")) { + map.addLayer(overlays.Border); } + } - if (cfg.mapobjects.travelnet) { - overlays.Travelnet = new TravelnetOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("travelnet") >= 0) { - map.addLayer(overlays.Travelnet); - } + if (cfg.mapobjects.travelnet) { + overlays.Travelnet = new TravelnetOverlay(wsChannel, layerMgr); + if (isDefault("travelnet")) { + map.addLayer(overlays.Travelnet); } + } - if (cfg.mapobjects.bones) { - overlays.Bones = new BonesOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("bones") >= 0) { - map.addLayer(overlays.Bones); - } + if (cfg.mapobjects.bones) { + overlays.Bones = new BonesOverlay(wsChannel, layerMgr); + if (isDefault("bones")) { + map.addLayer(overlays.Bones); } + } - if (cfg.mapobjects.digilines) { - overlays["Digilines LCD"] = new LcdOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("digilines") >= 0) { - map.addLayer(overlays["Digilines LCD"]); - } + if (cfg.mapobjects.digilines) { + overlays["Digilines LCD"] = new LcdOverlay(wsChannel, layerMgr); + if (isDefault("digilines")) { + map.addLayer(overlays["Digilines LCD"]); } + } - if (cfg.mapobjects.digiterms) { - overlays.Digiterms = new DigitermOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("digiterms") >= 0) { - map.addLayer(overlays.Digiterms); - } + if (cfg.mapobjects.digiterms) { + overlays.Digiterms = new DigitermOverlay(wsChannel, layerMgr); + if (isDefault("digiterms")) { + map.addLayer(overlays.Digiterms); } + } - if (cfg.mapobjects.luacontroller) { - overlays["Lua Controller"] = new LuacontrollerOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("luacontroller") >= 0) { - map.addLayer(overlays["Lua Controller"]); - } + if (cfg.mapobjects.luacontroller) { + overlays["Lua Controller"] = new LuacontrollerOverlay(wsChannel, layerMgr); + if (isDefault("luacontroller")) { + map.addLayer(overlays["Lua Controller"]); } + } - if (cfg.mapobjects.technic_anchor) { - overlays["Technic Anchor"] = new TechnicAnchorOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("technic_anchor") >= 0) { - map.addLayer(overlays["Technic Anchor"]); - } + if (cfg.mapobjects.technic_anchor) { + overlays["Technic Anchor"] = new TechnicAnchorOverlay(wsChannel, layerMgr); + if (isDefault("technic_anchor")) { + map.addLayer(overlays["Technic Anchor"]); } + } - if (cfg.mapobjects.technic_quarry) { - overlays["Technic Quarry"] = new TechnicQuarryOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("technic_quarry") >= 0) { - map.addLayer(overlays["Technic Quarry"]); - } + if (cfg.mapobjects.technic_quarry) { + overlays["Technic Quarry"] = new TechnicQuarryOverlay(wsChannel, layerMgr); + if (isDefault("technic_quarry")) { + map.addLayer(overlays["Technic Quarry"]); } + } - if (cfg.mapobjects.technic_switch) { - overlays["Technic Switching station"] = new TechnicSwitchOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("technic_switch") >= 0) { - map.addLayer(overlays["Technic Switching station"]); - } + if (cfg.mapobjects.technic_switch) { + overlays["Technic Switching station"] = new TechnicSwitchOverlay(wsChannel, layerMgr); + if (isDefault("technic_switch")) { + map.addLayer(overlays["Technic Switching station"]); } + } - if (cfg.mapobjects.protector) { - overlays.Protector = new ProtectorOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("protector") >= 0) { - map.addLayer(overlays.Protector); - } + if (cfg.mapobjects.protector) { + overlays.Protector = new ProtectorOverlay(wsChannel, layerMgr); + if (isDefault("protector")) { + map.addLayer(overlays.Protector); } + } - if (cfg.mapobjects.xpprotector) { - overlays["XP Protector"] = new XPProtectorOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("xpprotector") >= 0) { - map.addLayer(overlays["XP Protector"]); - } + if (cfg.mapobjects.xpprotector) { + overlays["XP Protector"] = new XPProtectorOverlay(wsChannel, layerMgr); + if (isDefault("xpprotector")) { + map.addLayer(overlays["XP Protector"]); } + } - if (cfg.mapobjects.privprotector) { - overlays["Priv Protector"] = new PrivProtectorOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("privprotector") >= 0) { - map.addLayer(overlays["Priv Protector"]); - } + if (cfg.mapobjects.privprotector) { + overlays["Priv Protector"] = new PrivProtectorOverlay(wsChannel, layerMgr); + if (isDefault("privprotector")) { + map.addLayer(overlays["Priv Protector"]); } + } - if (cfg.mapobjects.mission) { - overlays.Missions = new MissionOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("mission") >= 0) { - map.addLayer(overlays.Missions); - } + if (cfg.mapobjects.mission) { + overlays.Missions = new MissionOverlay(wsChannel, layerMgr); + if (isDefault("mission")) { + map.addLayer(overlays.Missions); } + } - if (cfg.mapobjects.train) { - overlays.Trains = new TrainOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("train") >= 0) { - map.addLayer(overlays.Trains); - } + if (cfg.mapobjects.train) { + overlays.Trains = new TrainOverlay(wsChannel, layerMgr); + if (isDefault("train")) { + map.addLayer(overlays.Trains); } + } - if (cfg.mapobjects.minecart) { - overlays.Minecart = new MinecartOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("minecart") >= 0) { - map.addLayer(overlays.Minecart); - } + if (cfg.mapobjects.minecart) { + overlays.Minecart = new MinecartOverlay(wsChannel, layerMgr); + if (isDefault("minecart")) { + map.addLayer(overlays.Minecart); } + } - if (cfg.mapobjects.atm) { - overlays.ATM = new ATMOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("atm") >= 0) { - map.addLayer(overlays.ATM); - } + if (cfg.mapobjects.atm) { + overlays.ATM = new ATMOverlay(wsChannel, layerMgr); + if (isDefault("atm")) { + map.addLayer(overlays.ATM); } + } - if (cfg.mapobjects.locator) { - overlays.Locator = new LocatorOverlay(wsChannel, layerMgr); - if (cfg.defaultoverlays.indexOf("locator") >= 0) { - map.addLayer(overlays.Locator); - } + if (cfg.mapobjects.locator) { + overlays.Locator = new LocatorOverlay(wsChannel, layerMgr); + if (isDefault("locator")) { + map.addLayer(overlays.Locator); } + } } diff --git a/server/static/js/SearchControl.js b/server/static/js/SearchControl.js index bcea102..1aa228f 100644 --- a/server/static/js/SearchControl.js +++ b/server/static/js/SearchControl.js @@ -1,3 +1,5 @@ +import SearchMenu from './search/SearchMenu.js'; +import SearchInput from './search/SearchInput.js'; export default L.Control.extend({ initialize: function(wsChannel, opts) { @@ -8,9 +10,7 @@ export default L.Control.extend({ var div = L.DomUtil.create('div'); m.mount(div, SearchInput); m.mount(document.getElementById("search-content"), { - view: function () { - return m(SearchMenu, {map: map}); - } + view: () => m(SearchMenu, {map: map}) }); return div; diff --git a/server/static/js/WebSocketChannel.js b/server/static/js/WebSocketChannel.js index 320bbfd..7edbfd5 100644 --- a/server/static/js/WebSocketChannel.js +++ b/server/static/js/WebSocketChannel.js @@ -1,53 +1,54 @@ -/* exported WebSocketChannel */ -function WebSocketChannel(){ - this.wsUrl = window.location.protocol.replace("http", "ws") + - "//" + window.location.host + - window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + - "/api/ws"; +class WebSocketChannel { + constructor(){ + this.wsUrl = window.location.protocol.replace("http", "ws") + + "//" + window.location.host + + window.location.pathname.substring(0, window.location.pathname.lastIndexOf("/")) + + "/api/ws"; - this.listenerMap = {/* type -> [listeners] */}; + this.listenerMap = {/* type -> [listeners] */}; + } + + addListener(type, listener){ + var list = this.listenerMap[type]; + if (!list){ + list = []; + this.listenerMap[type] = list; + } + + list.push(listener); + } + + removeListener(type, listener){ + var list = this.listenerMap[type]; + if (!list){ + return; + } + + this.listenerMap[type] = list.filter(l => l != listener); + } + + connect(){ + var ws = new WebSocket(this.wsUrl); + var self = this; + + ws.onmessage = function(e){ + var event = JSON.parse(e.data); + //rendered-tile, mapobject-created, mapobjects-cleared + + var listeners = self.listenerMap[event.type]; + if (listeners){ + listeners.forEach(function(listener){ + listener(event.data); + }); + } + }; + + ws.onerror = function(){ + //reconnect after some time + setTimeout(self.connect.bind(self), 1000); + }; + } } -WebSocketChannel.prototype.addListener = function(type, listener){ - var list = this.listenerMap[type]; - if (!list){ - list = []; - this.listenerMap[type] = list; - } - - list.push(listener); -}; - -WebSocketChannel.prototype.removeListener = function(type, listener){ - var list = this.listenerMap[type]; - if (!list){ - return; - } - - this.listenerMap[type] = list.filter(function(l){ - return l != listener; - }); -}; - -WebSocketChannel.prototype.connect = function(){ - var ws = new WebSocket(this.wsUrl); - var self = this; - - ws.onmessage = function(e){ - var event = JSON.parse(e.data); - //rendered-tile, mapobject-created, mapobjects-cleared - - var listeners = self.listenerMap[event.type]; - if (listeners){ - listeners.forEach(function(listener){ - listener(event.data); - }); - } - }; - - ws.onerror = function(){ - //reconnect after some time - setTimeout(self.connect.bind(self), 1000); - }; -}; +export default new WebSocketChannel(); diff --git a/server/static/js/api.js b/server/static/js/api.js index 8b42a97..f83f4f5 100644 --- a/server/static/js/api.js +++ b/server/static/js/api.js @@ -1,5 +1,5 @@ -export getMapObjects(query){ +export function getMapObjects(query){ return m.request({ method: "POST", url: "api/mapobjects/", @@ -7,6 +7,6 @@ export getMapObjects(query){ }); } -export getConfig(){ +export function getConfig(){ return m.request("api/config"); } diff --git a/server/static/js/main.js b/server/static/js/main.js index e69de29..080e9ee 100644 --- a/server/static/js/main.js +++ b/server/static/js/main.js @@ -0,0 +1,5 @@ + +import { getConfig } from './api.js'; +import { setup } from './map.js'; + +getConfig().then(setup); diff --git a/server/static/js/map.js b/server/static/js/map.js index 0993f0c..a672558 100644 --- a/server/static/js/map.js +++ b/server/static/js/map.js @@ -1,6 +1,14 @@ +import wsChannel from './WebSocketChannel.js'; +import Hashroute from './Hashroute.js'; +import SimpleCRS from './SimpleCRS.js'; +import CoordinatesDisplay from './CoordinatesDisplay.js'; +import WorldInfoDisplay from './WorldInfoDisplay.js'; +import SearchControl from './SearchControl.js'; +import Overlaysetup from './Overlaysetup.js'; +import layerManager from './LayerManager.js'; export function setup(cfg){ - var wsChannel = new WebSocketChannel(); + wsChannel.connect(); var map = L.map('image-map', { @@ -15,11 +23,10 @@ export function setup(cfg){ var overlays = {}; - window.layerMgr = new LayerManager(wsChannel, cfg.layers, map, Hashroute.getLayerId()); + layerManager.setup(wsChannel, cfg.layers, map, Hashroute.getLayerId()); //All overlays - Overlaysetup(cfg, map, overlays, wsChannel, layerMgr); - + Overlaysetup(cfg, map, overlays, wsChannel, layerManager); new CoordinatesDisplay({ position: 'bottomleft' }).addTo(map); new WorldInfoDisplay(wsChannel, { position: 'bottomright' }).addTo(map); @@ -29,7 +36,7 @@ export function setup(cfg){ } //layer control - L.control.layers(layerMgr.layerObjects, overlays, { position: "topright" }).addTo(map); + L.control.layers(layerManager.layerObjects, overlays, { position: "topright" }).addTo(map); - Hashroute.setup(map, layerMgr); + Hashroute.setup(map, layerManager); } diff --git a/server/static/js/nomodule.js b/server/static/js/nomodule.js index e69de29..cd49c1c 100644 --- a/server/static/js/nomodule.js +++ b/server/static/js/nomodule.js @@ -0,0 +1,2 @@ + +//TODO diff --git a/server/static/js/overlays/AbstractGeoJsonOverlay.js b/server/static/js/overlays/AbstractGeoJsonOverlay.js index 5ed1e81..1827d32 100644 --- a/server/static/js/overlays/AbstractGeoJsonOverlay.js +++ b/server/static/js/overlays/AbstractGeoJsonOverlay.js @@ -1,3 +1,5 @@ +import debounce from '../util/debounce.js'; +import { getMapObjects } from '../api.js'; export default L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr, type) { @@ -11,7 +13,7 @@ export default L.LayerGroup.extend({ this.onMapMove = debounce(this.onMapMove.bind(this), 50); }, - onLayerChange: function(layer){ + onLayerChange: function(){ this.reDraw(); }, @@ -19,7 +21,7 @@ export default L.LayerGroup.extend({ this.reDraw(); }, - createStyle: function(feature){ + createStyle: function(){ //TODO: default style }, @@ -70,7 +72,7 @@ export default L.LayerGroup.extend({ var z1 = parseInt(min.lat/16); var z2 = parseInt(max.lat/16); - api.getMapObjects({ + getMapObjects({ pos1: { x:x1, y:y1, z:z1 }, pos2: { x:x2, y:y2, z:z2 }, type: this.type diff --git a/server/static/js/overlays/AbstractIconOverlay.js b/server/static/js/overlays/AbstractIconOverlay.js index 32c0035..dc5aa12 100644 --- a/server/static/js/overlays/AbstractIconOverlay.js +++ b/server/static/js/overlays/AbstractIconOverlay.js @@ -1,3 +1,5 @@ +import debounce from '../util/debounce.js'; +import { getMapObjects } from '../api.js'; export default L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr, type, icon) { @@ -34,7 +36,7 @@ export default L.LayerGroup.extend({ return x + "/" + y + "/" + z; }, - onLayerChange: function(layer){ + onLayerChange: function(/*layer*/){ this.reDraw(true); }, @@ -42,7 +44,7 @@ export default L.LayerGroup.extend({ this.reDraw(false); }, - getIcon: function(obj){ + getIcon: function(/*ob*/){ return this.icon; }, @@ -75,7 +77,7 @@ export default L.LayerGroup.extend({ var z1 = parseInt(min.lat/16); var z2 = parseInt(max.lat/16); - api.getMapObjects({ + getMapObjects({ pos1: { x:x1, y:y1, z:z1 }, pos2: { x:x2, y:y2, z:z2 }, type: this.type diff --git a/server/static/js/overlays/BonesOverlay.js b/server/static/js/overlays/BonesOverlay.js index 137a4f4..046a4e8 100644 --- a/server/static/js/overlays/BonesOverlay.js +++ b/server/static/js/overlays/BonesOverlay.js @@ -1,6 +1,6 @@ import AbstractIconOverlay from './AbstractIconOverlay.js'; -export default L.icon({ +var BonesIcon = L.icon({ iconUrl: 'pics/bones_top.png', iconSize: [16, 16], @@ -8,7 +8,7 @@ export default L.icon({ popupAnchor: [0, -16] }); -var BonesOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "bones", BonesIcon); }, diff --git a/server/static/js/overlays/LabelOverlay.js b/server/static/js/overlays/LabelOverlay.js index a2c0177..e3802b5 100644 --- a/server/static/js/overlays/LabelOverlay.js +++ b/server/static/js/overlays/LabelOverlay.js @@ -1,8 +1,6 @@ -/* exported LabelOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; - -var LabelOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "label"); }, diff --git a/server/static/js/overlays/LcdOverlay.js b/server/static/js/overlays/LcdOverlay.js index cabf224..712aac1 100644 --- a/server/static/js/overlays/LcdOverlay.js +++ b/server/static/js/overlays/LcdOverlay.js @@ -1,5 +1,4 @@ -/* exported LcdOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var LcdIcon = L.icon({ iconUrl: 'pics/lcd_lcd.png', @@ -9,7 +8,7 @@ var LcdIcon = L.icon({ popupAnchor: [0, -16] }); -var LcdOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "digilinelcd", LcdIcon); }, diff --git a/server/static/js/overlays/LocatorOverlay.js b/server/static/js/overlays/LocatorOverlay.js index deea7d2..18525b2 100644 --- a/server/static/js/overlays/LocatorOverlay.js +++ b/server/static/js/overlays/LocatorOverlay.js @@ -1,8 +1,6 @@ -/* exported LocatorOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; - -var LocatorOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "locator"); }, diff --git a/server/static/js/overlays/LuacontrollerOverlay.js b/server/static/js/overlays/LuacontrollerOverlay.js index 7f41aa4..3b6db99 100644 --- a/server/static/js/overlays/LuacontrollerOverlay.js +++ b/server/static/js/overlays/LuacontrollerOverlay.js @@ -1,5 +1,4 @@ -/* exported LuacontrollerOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var LuacontrollerIcon = L.icon({ iconUrl: 'pics/jeija_luacontroller_top.png', @@ -17,7 +16,7 @@ var LuacontrollerBurntIcon = L.icon({ popupAnchor: [0, -16] }); -var LuacontrollerOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "luacontroller"); }, diff --git a/server/static/js/overlays/MinecartOverlay.js b/server/static/js/overlays/MinecartOverlay.js index 1ef8ad0..3f400c0 100644 --- a/server/static/js/overlays/MinecartOverlay.js +++ b/server/static/js/overlays/MinecartOverlay.js @@ -1,8 +1,5 @@ -/* exported MinecartOverlay */ -/* globals AbstractIconOverlay: true */ -/* jshint unused: false */ -var MinecartOverlay = L.LayerGroup.extend({ +export default L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { L.LayerGroup.prototype.initialize.call(this); @@ -47,7 +44,7 @@ var MinecartOverlay = L.LayerGroup.extend({ }, - onMinetestUpdate: function(info){ + onMinetestUpdate: function(/*info*/){ var self = this; this.minecarts.forEach(function(cart){ @@ -110,13 +107,13 @@ var MinecartOverlay = L.LayerGroup.extend({ }, - onAdd: function(map) { + onAdd: function(/*map*/) { this.layerMgr.addListener(this.reDraw); this.wsChannel.addListener("minetest-info", this.onMinetestUpdate); this.reDraw(); }, - onRemove: function(map) { + onRemove: function(/*map*/) { this.clearLayers(); this.layerMgr.removeListener(this.reDraw); this.wsChannel.removeListener("minetest-info", this.onMinetestUpdate); diff --git a/server/static/js/overlays/MissionOverlay.js b/server/static/js/overlays/MissionOverlay.js index 1046e68..371aa1e 100644 --- a/server/static/js/overlays/MissionOverlay.js +++ b/server/static/js/overlays/MissionOverlay.js @@ -1,5 +1,4 @@ -/* exported MissionOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var MissionIcon = L.icon({ iconUrl: 'pics/mission_32px.png', @@ -9,7 +8,7 @@ var MissionIcon = L.icon({ popupAnchor: [0, -32] }); -var MissionOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "mission", MissionIcon); }, diff --git a/server/static/js/overlays/PlayerOverlay.js b/server/static/js/overlays/PlayerOverlay.js index ac4f042..107aa20 100644 --- a/server/static/js/overlays/PlayerOverlay.js +++ b/server/static/js/overlays/PlayerOverlay.js @@ -1,6 +1,3 @@ -/* exported PlayerOverlay */ -/* globals AbstractIconOverlay: true */ -/* jshint unused: false */ var PlayerIcon = L.icon({ iconUrl: 'pics/sam.png', @@ -10,7 +7,7 @@ var PlayerIcon = L.icon({ popupAnchor: [0, -16] }); -var PlayerOverlay = L.LayerGroup.extend({ +export default L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { L.LayerGroup.prototype.initialize.call(this); @@ -61,7 +58,7 @@ var PlayerOverlay = L.LayerGroup.extend({ return (player.pos.y >= (mapLayer.from*16) && player.pos.y <= (mapLayer.to*16)); }, - onMinetestUpdate: function(info){ + onMinetestUpdate: function(/*info*/){ var self = this; this.players.forEach(function(player){ @@ -125,13 +122,13 @@ var PlayerOverlay = L.LayerGroup.extend({ }, - onAdd: function(map) { + onAdd: function(/*map*/) { this.layerMgr.addListener(this.reDraw); this.wsChannel.addListener("minetest-info", this.onMinetestUpdate); this.reDraw(); }, - onRemove: function(map) { + onRemove: function(/*map*/) { this.clearLayers(); this.layerMgr.removeListener(this.reDraw); this.wsChannel.removeListener("minetest-info", this.onMinetestUpdate); diff --git a/server/static/js/overlays/PoiOverlay.js b/server/static/js/overlays/PoiOverlay.js index 6cc57a4..6f05a2d 100644 --- a/server/static/js/overlays/PoiOverlay.js +++ b/server/static/js/overlays/PoiOverlay.js @@ -1,7 +1,6 @@ -/* exported PoiOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; -var PoiOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "poi"); }, diff --git a/server/static/js/overlays/PrivProtectorOverlay.js b/server/static/js/overlays/PrivProtectorOverlay.js index b5f60a0..a75269e 100644 --- a/server/static/js/overlays/PrivProtectorOverlay.js +++ b/server/static/js/overlays/PrivProtectorOverlay.js @@ -1,7 +1,6 @@ -/* exported PrivProtectorOverlay */ -/* globals AbstractGeoJsonOverlay: true */ +import AbstractGeoJsonOverlay from './AbstractGeoJsonOverlay.js'; -var PrivProtectorOverlay = AbstractGeoJsonOverlay.extend({ +export default AbstractGeoJsonOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "privprotector"); }, diff --git a/server/static/js/overlays/ProtectorOverlay.js b/server/static/js/overlays/ProtectorOverlay.js index 48a5374..ccbd96b 100644 --- a/server/static/js/overlays/ProtectorOverlay.js +++ b/server/static/js/overlays/ProtectorOverlay.js @@ -1,7 +1,6 @@ -/* exported ProtectorOverlay */ -/* globals AbstractGeoJsonOverlay: true */ +import AbstractGeoJsonOverlay from './AbstractGeoJsonOverlay.js'; -var ProtectorOverlay = AbstractGeoJsonOverlay.extend({ +export default AbstractGeoJsonOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "protector"); }, diff --git a/server/static/js/overlays/ShopOverlay.js b/server/static/js/overlays/ShopOverlay.js index cce844e..f8e3a9f 100644 --- a/server/static/js/overlays/ShopOverlay.js +++ b/server/static/js/overlays/ShopOverlay.js @@ -1,5 +1,4 @@ -/* exported ShopOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var ShopIcon = L.icon({ iconUrl: 'pics/shop.png', @@ -16,7 +15,7 @@ var ShopEmptyIcon = L.icon({ }); -var ShopOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "shop"); }, diff --git a/server/static/js/overlays/TechnicAnchorOverlay.js b/server/static/js/overlays/TechnicAnchorOverlay.js index 8be3e91..5553767 100644 --- a/server/static/js/overlays/TechnicAnchorOverlay.js +++ b/server/static/js/overlays/TechnicAnchorOverlay.js @@ -1,5 +1,4 @@ -/* exported TechnicAnchorOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var TechnicAnchorIcon = L.icon({ iconUrl: 'pics/technic_admin_anchor.png', @@ -9,7 +8,7 @@ var TechnicAnchorIcon = L.icon({ popupAnchor: [0, -32] }); -var TechnicAnchorOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "technicanchor", TechnicAnchorIcon); }, diff --git a/server/static/js/overlays/TechnicQuarryOverlay.js b/server/static/js/overlays/TechnicQuarryOverlay.js index 2369453..f989aca 100644 --- a/server/static/js/overlays/TechnicQuarryOverlay.js +++ b/server/static/js/overlays/TechnicQuarryOverlay.js @@ -1,5 +1,4 @@ -/* exported TechnicQuarryOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var TechnicQuarryIcon = L.icon({ iconUrl: 'pics/default_tool_mesepick.png', @@ -9,7 +8,7 @@ var TechnicQuarryIcon = L.icon({ popupAnchor: [0, -16] }); -var TechnicQuarryOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "technicquarry", TechnicQuarryIcon); }, diff --git a/server/static/js/overlays/TechnicSwitchOverlay.js b/server/static/js/overlays/TechnicSwitchOverlay.js index 7c7f5c3..dd261c4 100644 --- a/server/static/js/overlays/TechnicSwitchOverlay.js +++ b/server/static/js/overlays/TechnicSwitchOverlay.js @@ -1,5 +1,4 @@ -/* exported TechnicSwitchOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var TechnicSwitchIcon = L.icon({ iconUrl: 'pics/technic_water_mill_top_active.png', @@ -9,7 +8,7 @@ var TechnicSwitchIcon = L.icon({ popupAnchor: [0, -16] }); -var TechnicSwitchOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "technicswitch", TechnicSwitchIcon); }, diff --git a/server/static/js/overlays/TrainOverlay.js b/server/static/js/overlays/TrainOverlay.js index 08df518..ddd94aa 100644 --- a/server/static/js/overlays/TrainOverlay.js +++ b/server/static/js/overlays/TrainOverlay.js @@ -1,6 +1,3 @@ -/* exported TrainOverlay */ -/* globals AbstractIconOverlay: true */ -/* jshint unused: false */ function getTrainImageUrlForType(type){ switch(type){ @@ -32,7 +29,7 @@ function getTrainImageUrlForType(type){ } } -var TrainOverlay = L.LayerGroup.extend({ +export default L.LayerGroup.extend({ initialize: function(wsChannel, layerMgr) { L.LayerGroup.prototype.initialize.call(this); @@ -101,7 +98,7 @@ var TrainOverlay = L.LayerGroup.extend({ }, - onMinetestUpdate: function(info){ + onMinetestUpdate: function(/*info*/){ var self = this; this.trains.forEach(function(train){ @@ -165,13 +162,13 @@ var TrainOverlay = L.LayerGroup.extend({ }, - onAdd: function(map) { + onAdd: function(/*map*/) { this.layerMgr.addListener(this.reDraw); this.wsChannel.addListener("minetest-info", this.onMinetestUpdate); this.reDraw(); }, - onRemove: function(map) { + onRemove: function(/*map*/) { this.clearLayers(); this.layerMgr.removeListener(this.reDraw); this.wsChannel.removeListener("minetest-info", this.onMinetestUpdate); diff --git a/server/static/js/overlays/TrainlineOverlay.js b/server/static/js/overlays/TrainlineOverlay.js index 3d5f9f5..420750b 100644 --- a/server/static/js/overlays/TrainlineOverlay.js +++ b/server/static/js/overlays/TrainlineOverlay.js @@ -1,7 +1,6 @@ -/* exported TrainlineOverlay */ -/* globals AbstractGeoJsonOverlay: true */ +import AbstractGeoJsonOverlay from './AbstractGeoJsonOverlay.js'; -var TrainlineOverlay = AbstractGeoJsonOverlay.extend({ +export default AbstractGeoJsonOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "train"); }, diff --git a/server/static/js/overlays/TravelnetOverlay.js b/server/static/js/overlays/TravelnetOverlay.js index 2d9da7e..199199b 100644 --- a/server/static/js/overlays/TravelnetOverlay.js +++ b/server/static/js/overlays/TravelnetOverlay.js @@ -1,5 +1,4 @@ -/* exported TravelnetOverlay */ -/* globals AbstractIconOverlay: true */ +import AbstractIconOverlay from './AbstractIconOverlay.js'; var TravelnetIcon = L.icon({ iconUrl: 'pics/travelnet_inv.png', @@ -9,7 +8,7 @@ var TravelnetIcon = L.icon({ popupAnchor: [0, -32] }); -var TravelnetOverlay = AbstractIconOverlay.extend({ +export default AbstractIconOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractIconOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "travelnet", TravelnetIcon); }, diff --git a/server/static/js/overlays/XPProtectorOverlay.js b/server/static/js/overlays/XPProtectorOverlay.js index f9d081a..8b55d01 100644 --- a/server/static/js/overlays/XPProtectorOverlay.js +++ b/server/static/js/overlays/XPProtectorOverlay.js @@ -1,7 +1,6 @@ -/* exported XPProtectorOverlay */ -/* globals AbstractGeoJsonOverlay: true */ +import AbstractGeoJsonOverlay from './AbstractGeoJsonOverlay.js'; -var XPProtectorOverlay = AbstractGeoJsonOverlay.extend({ +export default AbstractGeoJsonOverlay.extend({ initialize: function(wsChannel, layerMgr) { AbstractGeoJsonOverlay.prototype.initialize.call(this, wsChannel, layerMgr, "xpprotector"); }, diff --git a/server/static/js/search/SearchInput.js b/server/static/js/search/SearchInput.js index ee128e6..b584f03 100644 --- a/server/static/js/search/SearchInput.js +++ b/server/static/js/search/SearchInput.js @@ -1,3 +1,6 @@ +import SearchStore from './SearchStore.js'; +import SearchService from './SearchService.js'; + export default { view: function(){ function handleInput(e){ diff --git a/server/static/js/search/SearchResult.js b/server/static/js/search/SearchResult.js index 5993d10..811b812 100644 --- a/server/static/js/search/SearchResult.js +++ b/server/static/js/search/SearchResult.js @@ -1,4 +1,5 @@ import SearchStore from './SearchStore.js'; +import layerMgr from '../LayerManager.js'; export default { view: function(vnode){