1
0
forked from MTSR/mapserver

jshint first batch

This commit is contained in:
NatureFreshMilk 2019-04-04 10:19:29 +02:00
parent 1e124a2a90
commit 3adb10ca6c
14 changed files with 73 additions and 53 deletions

View File

@ -30,6 +30,9 @@ clean:
rm -rf $(STATIC_VFS) rm -rf $(STATIC_VFS)
rm -rf $(OUT_DIR) rm -rf $(OUT_DIR)
jshint:
jshint static/js/*.js static/js/util static/js/overlays
$(STATIC_VFS): $(STATIC_VFS):
go generate go generate

View File

@ -0,0 +1,12 @@
{
"undef": true,
"unused": true,
"esversion": 6,
"browser": true,
"globals": {
"debounce": true,
"L": true,
"m": true,
"api": true
}
}

View File

@ -1,11 +1,11 @@
'use strict'; /* exported CoordinatesDisplay */
// coord display // coord display
var CoordinatesDisplay = L.Control.extend({ var CoordinatesDisplay = L.Control.extend({
onAdd: function(map) { onAdd: function(map) {
var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display'); var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display');
var hoverCoord, clickCoord var hoverCoord, clickCoord;
function updateHover(ev){ function updateHover(ev){
hoverCoord = ev.latlng; hoverCoord = ev.latlng;
@ -33,8 +33,6 @@ var CoordinatesDisplay = L.Control.extend({
map.on('touch', updateClick); map.on('touch', updateClick);
return div; return div;
},
onRemove: function(map) {
} }
}); });

View File

@ -1,26 +1,26 @@
'use strict'; /* exported Hashroute */
var Hashroute = { var Hashroute = {
setup: function(map, layerMgr){ setup: function(map, layerMgr){
function updateHash(){ function updateHash(){
var center = map.getCenter(); var center = map.getCenter();
location.hash = window.location.hash =
layerMgr.getCurrentLayer().id + "/" + layerMgr.getCurrentLayer().id + "/" +
center.lng + "/" + center.lat + "/" + map.getZoom(); center.lng + "/" + center.lat + "/" + map.getZoom();
} }
map.on('zoomend', updateHash) map.on('zoomend', updateHash);
map.on('moveend', updateHash) map.on('moveend', updateHash);
map.on('baselayerchange', updateHash) map.on('baselayerchange', updateHash);
updateHash(); updateHash();
}, },
getLayerId: function(){ getLayerId: function(){
var hashParts = location.hash.substring(1).split("/"); var hashParts = window.location.hash.substring(1).split("/");
if (hashParts.length == 4){ if (hashParts.length == 4){
//new format //new format
return +hashParts[0] return +hashParts[0];
} }
@ -28,14 +28,14 @@ var Hashroute = {
}, },
getZoom: function(){ getZoom: function(){
var hashParts = location.hash.substring(1).split("/"); var hashParts = window.location.hash.substring(1).split("/");
if (hashParts.length == 3){ if (hashParts.length == 3){
//old format //old format
return +hashParts[2] return +hashParts[2];
} else if (hashParts.length == 4){ } else if (hashParts.length == 4){
//new format //new format
return +hashParts[3] return +hashParts[3];
} }
@ -43,7 +43,7 @@ var Hashroute = {
}, },
getCenter: function(){ getCenter: function(){
var hashParts = location.hash.substring(1).split("/"); var hashParts = window.location.hash.substring(1).split("/");
if (hashParts.length == 3){ if (hashParts.length == 3){
//old format //old format
return [+hashParts[1], +hashParts[0]]; return [+hashParts[1], +hashParts[0]];

View File

@ -1,4 +1,4 @@
'use strict'; /* exported LayerManager */
function LayerManager(layers, map){ function LayerManager(layers, map){
this.listeners = []; this.listeners = [];
@ -8,7 +8,6 @@ function LayerManager(layers, map){
var self = this; var self = this;
map.on('baselayerchange', function (e) { map.on('baselayerchange', function (e) {
console.log("baselayerchange", e.layer);
self.setLayerId(e.layer.layerId); self.setLayerId(e.layer.layerId);
}); });
@ -25,7 +24,7 @@ LayerManager.prototype.setLayerId = function(layerId){
return; return;
} }
}); });
}, };
LayerManager.prototype.addListener = function(listener){ LayerManager.prototype.addListener = function(listener){

View File

@ -1,24 +1,25 @@
'use strict'; /* jshint undef: false */
/* exported Overlaysetup */
function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
if (cfg.mapobjects.mapserver) { if (cfg.mapobjects.mapserver) {
overlays["Player"] = new PlayerOverlay(wsChannel, layerMgr); overlays.Player = new PlayerOverlay(wsChannel, layerMgr);
overlays["POI"] = new PoiOverlay(wsChannel, layerMgr); overlays.POI = new PoiOverlay(wsChannel, layerMgr);
overlays["Label"] = new LabelOverlay(wsChannel, layerMgr); overlays.Label = new LabelOverlay(wsChannel, layerMgr);
overlays["Border"] = new BorderOverlay(wsChannel, layerMgr); overlays.Border = new BorderOverlay(wsChannel, layerMgr);
map.addLayer(overlays["Player"]); map.addLayer(overlays.Player);
map.addLayer(overlays["POI"]); map.addLayer(overlays.POI);
map.addLayer(overlays["Labels"]); map.addLayer(overlays.Labels);
} }
if (cfg.mapobjects.travelnet) { if (cfg.mapobjects.travelnet) {
overlays["Travelnet"] = new TravelnetOverlay(wsChannel, layerMgr); overlays.Travelnet = new TravelnetOverlay(wsChannel, layerMgr);
} }
if (cfg.mapobjects.bones) { if (cfg.mapobjects.bones) {
overlays["Bones"] = new BonesOverlay(wsChannel, layerMgr); overlays.Bones = new BonesOverlay(wsChannel, layerMgr);
} }
if (cfg.mapobjects.digilines) { if (cfg.mapobjects.digilines) {
@ -26,7 +27,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
} }
if (cfg.mapobjects.digiterms) { if (cfg.mapobjects.digiterms) {
overlays["Digiterms"] = new DigitermOverlay(wsChannel, layerMgr); overlays.Digiterms = new DigitermOverlay(wsChannel, layerMgr);
} }
if (cfg.mapobjects.luacontroller) { if (cfg.mapobjects.luacontroller) {
@ -40,7 +41,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
} }
if (cfg.mapobjects.protector) { if (cfg.mapobjects.protector) {
overlays["Protector"] = new ProtectorOverlay(wsChannel, layerMgr); overlays.Protector = new ProtectorOverlay(wsChannel, layerMgr);
} }
if (cfg.mapobjects.xpprotector) { if (cfg.mapobjects.xpprotector) {
@ -52,11 +53,11 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
} }
if (cfg.mapobjects.mission) { if (cfg.mapobjects.mission) {
overlays["Missions"] = new MissionOverlay(wsChannel, layerMgr); overlays.Missions = new MissionOverlay(wsChannel, layerMgr);
} }
if (cfg.mapobjects.train) { if (cfg.mapobjects.train) {
overlays["Trains"] = new TrainOverlay(wsChannel, layerMgr); overlays.Trains = new TrainOverlay(wsChannel, layerMgr);
overlays["Trainlines"] = new TrainlineOverlay(wsChannel, layerMgr); overlays.Trainlines = new TrainlineOverlay(wsChannel, layerMgr);
} }
} }

View File

@ -1,4 +1,4 @@
'use strict'; /* exported RealtimeTileLayer */
var RealtimeTileLayer = L.TileLayer.extend({ var RealtimeTileLayer = L.TileLayer.extend({

View File

@ -1,4 +1,4 @@
'use strict'; /* exported SimpleCRS */
var SimpleCRS = L.Util.extend({}, L.CRS.Simple, { var SimpleCRS = L.Util.extend({}, L.CRS.Simple, {
scale: function (zoom) { scale: function (zoom) {

View File

@ -1,7 +1,11 @@
'use strict'; /* exported WebSocketChannel */
function WebSocketChannel(){ function WebSocketChannel(){
this.wsUrl = location.protocol.replace("http", "ws") + "//" + location.host + location.pathname.substring(0, location.pathname.lastIndexOf("/")) + "/api/ws"; 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] */};
} }
@ -18,7 +22,7 @@ WebSocketChannel.prototype.addListener = function(type, listener){
WebSocketChannel.prototype.removeListener = function(type, listener){ WebSocketChannel.prototype.removeListener = function(type, listener){
var list = this.listenerMap[type]; var list = this.listenerMap[type];
if (!list){ if (!list){
return return;
} }
this.listenerMap[type] = list.filter(function(l){ this.listenerMap[type] = list.filter(function(l){
@ -40,10 +44,10 @@ WebSocketChannel.prototype.connect = function(){
listener(event.data); listener(event.data);
}); });
} }
} };
ws.onerror = function(){ ws.onerror = function(){
//reconnect after some time //reconnect after some time
setTimeout(self.connect.bind(self), 1000); setTimeout(self.connect.bind(self), 1000);
} };
}; };

View File

@ -1,4 +1,4 @@
'use strict'; /* exported WorldInfoDisplay */
// coord display // coord display
var WorldInfoDisplay = L.Control.extend({ var WorldInfoDisplay = L.Control.extend({
@ -7,7 +7,7 @@ var WorldInfoDisplay = L.Control.extend({
this.wsChannel = wsChannel; this.wsChannel = wsChannel;
}, },
onAdd: function(map) { onAdd: function() {
var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display'); var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display');
this.wsChannel.addListener("minetest-info", function(info){ this.wsChannel.addListener("minetest-info", function(info){
@ -15,8 +15,5 @@ var WorldInfoDisplay = L.Control.extend({
}); });
return div; return div;
},
onRemove: function(map) {
} }
}); });

View File

@ -1,3 +1,5 @@
/* exported api */
var api = { var api = {
getMapObjects: function(query){ getMapObjects: function(query){

View File

@ -1,4 +1,4 @@
'use strict'; /* jshint undef: false */
api.getConfig().then(function(cfg){ api.getConfig().then(function(cfg){
@ -16,7 +16,7 @@ api.getConfig().then(function(cfg){
map.attributionControl.addAttribution('<a href="https://github.com/thomasrudin-mt/mapserver">Minetest Mapserver</a>'); map.attributionControl.addAttribution('<a href="https://github.com/thomasrudin-mt/mapserver">Minetest Mapserver</a>');
var layers = {}; var layers = {};
var overlays = {} var overlays = {};
var layerMgr = new LayerManager(cfg.layers, map); var layerMgr = new LayerManager(cfg.layers, map);
layerMgr.setLayerId( Hashroute.getLayerId() ); layerMgr.setLayerId( Hashroute.getLayerId() );

View File

@ -1,4 +1,5 @@
'use strict'; /* exported AbstractGeoJsonOverlay */
/* jshint unused: false */
var AbstractGeoJsonOverlay = L.LayerGroup.extend({ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
initialize: function(wsChannel, layerMgr, type) { initialize: function(wsChannel, layerMgr, type) {
@ -81,7 +82,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
var geoJsonLayer = self.createGeoJson(objects); var geoJsonLayer = self.createGeoJson(objects);
geoJsonLayer.addTo(self); geoJsonLayer.addTo(self);
}) });
}, },
@ -90,7 +91,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
map.on("zoomend", this.onMapMove); map.on("zoomend", this.onMapMove);
map.on("moveend", this.onMapMove); map.on("moveend", this.onMapMove);
this.layerMgr.addListener(this.onLayerChange); this.layerMgr.addListener(this.onLayerChange);
this.reDraw(true) this.reDraw(true);
}, },
onRemove: function(map) { onRemove: function(map) {

View File

@ -1,3 +1,5 @@
/* exported debounce */
function debounce(func, wait, immediate) { function debounce(func, wait, immediate) {
var timeout; var timeout;
return function() { return function() {
@ -9,6 +11,7 @@ function debounce(func, wait, immediate) {
var callNow = immediate && !timeout; var callNow = immediate && !timeout;
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(later, wait); timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args); if (callNow)
func.apply(context, args);
}; };
}; }