forked from MTSR/mapserver
jshint first batch
This commit is contained in:
parent
1e124a2a90
commit
3adb10ca6c
@ -30,6 +30,9 @@ clean:
|
||||
rm -rf $(STATIC_VFS)
|
||||
rm -rf $(OUT_DIR)
|
||||
|
||||
jshint:
|
||||
jshint static/js/*.js static/js/util static/js/overlays
|
||||
|
||||
$(STATIC_VFS):
|
||||
go generate
|
||||
|
||||
|
12
server/static/js/.jshintrc
Normal file
12
server/static/js/.jshintrc
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"esversion": 6,
|
||||
"browser": true,
|
||||
"globals": {
|
||||
"debounce": true,
|
||||
"L": true,
|
||||
"m": true,
|
||||
"api": true
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
/* exported CoordinatesDisplay */
|
||||
|
||||
// coord display
|
||||
var CoordinatesDisplay = L.Control.extend({
|
||||
onAdd: function(map) {
|
||||
var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display');
|
||||
|
||||
var hoverCoord, clickCoord
|
||||
var hoverCoord, clickCoord;
|
||||
|
||||
function updateHover(ev){
|
||||
hoverCoord = ev.latlng;
|
||||
@ -33,8 +33,6 @@ var CoordinatesDisplay = L.Control.extend({
|
||||
map.on('touch', updateClick);
|
||||
|
||||
return div;
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,26 +1,26 @@
|
||||
'use strict';
|
||||
/* exported Hashroute */
|
||||
|
||||
var Hashroute = {
|
||||
|
||||
setup: function(map, layerMgr){
|
||||
function updateHash(){
|
||||
var center = map.getCenter();
|
||||
location.hash =
|
||||
window.location.hash =
|
||||
layerMgr.getCurrentLayer().id + "/" +
|
||||
center.lng + "/" + center.lat + "/" + map.getZoom();
|
||||
}
|
||||
|
||||
map.on('zoomend', updateHash)
|
||||
map.on('moveend', updateHash)
|
||||
map.on('baselayerchange', updateHash)
|
||||
map.on('zoomend', updateHash);
|
||||
map.on('moveend', updateHash);
|
||||
map.on('baselayerchange', updateHash);
|
||||
updateHash();
|
||||
},
|
||||
|
||||
getLayerId: function(){
|
||||
var hashParts = location.hash.substring(1).split("/");
|
||||
var hashParts = window.location.hash.substring(1).split("/");
|
||||
if (hashParts.length == 4){
|
||||
//new format
|
||||
return +hashParts[0]
|
||||
return +hashParts[0];
|
||||
|
||||
}
|
||||
|
||||
@ -28,14 +28,14 @@ var Hashroute = {
|
||||
},
|
||||
|
||||
getZoom: function(){
|
||||
var hashParts = location.hash.substring(1).split("/");
|
||||
var hashParts = window.location.hash.substring(1).split("/");
|
||||
if (hashParts.length == 3){
|
||||
//old format
|
||||
return +hashParts[2]
|
||||
return +hashParts[2];
|
||||
|
||||
} else if (hashParts.length == 4){
|
||||
//new format
|
||||
return +hashParts[3]
|
||||
return +hashParts[3];
|
||||
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ var Hashroute = {
|
||||
},
|
||||
|
||||
getCenter: function(){
|
||||
var hashParts = location.hash.substring(1).split("/");
|
||||
var hashParts = window.location.hash.substring(1).split("/");
|
||||
if (hashParts.length == 3){
|
||||
//old format
|
||||
return [+hashParts[1], +hashParts[0]];
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
/* exported LayerManager */
|
||||
|
||||
function LayerManager(layers, map){
|
||||
this.listeners = [];
|
||||
@ -8,7 +8,6 @@ function LayerManager(layers, map){
|
||||
var self = this;
|
||||
|
||||
map.on('baselayerchange', function (e) {
|
||||
console.log("baselayerchange", e.layer);
|
||||
self.setLayerId(e.layer.layerId);
|
||||
});
|
||||
|
||||
@ -25,7 +24,7 @@ LayerManager.prototype.setLayerId = function(layerId){
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
LayerManager.prototype.addListener = function(listener){
|
||||
|
@ -1,24 +1,25 @@
|
||||
'use strict';
|
||||
/* jshint undef: false */
|
||||
/* exported Overlaysetup */
|
||||
|
||||
function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
|
||||
|
||||
if (cfg.mapobjects.mapserver) {
|
||||
overlays["Player"] = new PlayerOverlay(wsChannel, layerMgr);
|
||||
overlays["POI"] = new PoiOverlay(wsChannel, layerMgr);
|
||||
overlays["Label"] = new LabelOverlay(wsChannel, layerMgr);
|
||||
overlays["Border"] = new BorderOverlay(wsChannel, layerMgr);
|
||||
overlays.Player = new PlayerOverlay(wsChannel, layerMgr);
|
||||
overlays.POI = new PoiOverlay(wsChannel, layerMgr);
|
||||
overlays.Label = new LabelOverlay(wsChannel, layerMgr);
|
||||
overlays.Border = new BorderOverlay(wsChannel, layerMgr);
|
||||
|
||||
map.addLayer(overlays["Player"]);
|
||||
map.addLayer(overlays["POI"]);
|
||||
map.addLayer(overlays["Labels"]);
|
||||
map.addLayer(overlays.Player);
|
||||
map.addLayer(overlays.POI);
|
||||
map.addLayer(overlays.Labels);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.travelnet) {
|
||||
overlays["Travelnet"] = new TravelnetOverlay(wsChannel, layerMgr);
|
||||
overlays.Travelnet = new TravelnetOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.bones) {
|
||||
overlays["Bones"] = new BonesOverlay(wsChannel, layerMgr);
|
||||
overlays.Bones = new BonesOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.digilines) {
|
||||
@ -26,7 +27,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.digiterms) {
|
||||
overlays["Digiterms"] = new DigitermOverlay(wsChannel, layerMgr);
|
||||
overlays.Digiterms = new DigitermOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.luacontroller) {
|
||||
@ -40,7 +41,7 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.protector) {
|
||||
overlays["Protector"] = new ProtectorOverlay(wsChannel, layerMgr);
|
||||
overlays.Protector = new ProtectorOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.xpprotector) {
|
||||
@ -52,11 +53,11 @@ function Overlaysetup(cfg, map, overlays, wsChannel, layerMgr){
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.mission) {
|
||||
overlays["Missions"] = new MissionOverlay(wsChannel, layerMgr);
|
||||
overlays.Missions = new MissionOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
|
||||
if (cfg.mapobjects.train) {
|
||||
overlays["Trains"] = new TrainOverlay(wsChannel, layerMgr);
|
||||
overlays["Trainlines"] = new TrainlineOverlay(wsChannel, layerMgr);
|
||||
overlays.Trains = new TrainOverlay(wsChannel, layerMgr);
|
||||
overlays.Trainlines = new TrainlineOverlay(wsChannel, layerMgr);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
/* exported RealtimeTileLayer */
|
||||
|
||||
var RealtimeTileLayer = L.TileLayer.extend({
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
/* exported SimpleCRS */
|
||||
|
||||
var SimpleCRS = L.Util.extend({}, L.CRS.Simple, {
|
||||
scale: function (zoom) {
|
||||
|
@ -1,7 +1,11 @@
|
||||
'use strict';
|
||||
/* exported 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] */};
|
||||
}
|
||||
|
||||
@ -18,7 +22,7 @@ WebSocketChannel.prototype.addListener = function(type, listener){
|
||||
WebSocketChannel.prototype.removeListener = function(type, listener){
|
||||
var list = this.listenerMap[type];
|
||||
if (!list){
|
||||
return
|
||||
return;
|
||||
}
|
||||
|
||||
this.listenerMap[type] = list.filter(function(l){
|
||||
@ -40,10 +44,10 @@ WebSocketChannel.prototype.connect = function(){
|
||||
listener(event.data);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ws.onerror = function(){
|
||||
//reconnect after some time
|
||||
setTimeout(self.connect.bind(self), 1000);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
/* exported WorldInfoDisplay */
|
||||
|
||||
// coord display
|
||||
var WorldInfoDisplay = L.Control.extend({
|
||||
@ -7,7 +7,7 @@ var WorldInfoDisplay = L.Control.extend({
|
||||
this.wsChannel = wsChannel;
|
||||
},
|
||||
|
||||
onAdd: function(map) {
|
||||
onAdd: function() {
|
||||
var div = L.DomUtil.create('div', 'leaflet-bar leaflet-custom-display');
|
||||
|
||||
this.wsChannel.addListener("minetest-info", function(info){
|
||||
@ -15,8 +15,5 @@ var WorldInfoDisplay = L.Control.extend({
|
||||
});
|
||||
|
||||
return div;
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
}
|
||||
});
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* exported api */
|
||||
|
||||
var api = {
|
||||
|
||||
getMapObjects: function(query){
|
||||
|
@ -1,4 +1,4 @@
|
||||
'use strict';
|
||||
/* jshint undef: false */
|
||||
|
||||
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>');
|
||||
|
||||
var layers = {};
|
||||
var overlays = {}
|
||||
var overlays = {};
|
||||
|
||||
var layerMgr = new LayerManager(cfg.layers, map);
|
||||
layerMgr.setLayerId( Hashroute.getLayerId() );
|
||||
|
@ -1,4 +1,5 @@
|
||||
'use strict';
|
||||
/* exported AbstractGeoJsonOverlay */
|
||||
/* jshint unused: false */
|
||||
|
||||
var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
||||
initialize: function(wsChannel, layerMgr, type) {
|
||||
@ -81,7 +82,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
||||
|
||||
var geoJsonLayer = self.createGeoJson(objects);
|
||||
geoJsonLayer.addTo(self);
|
||||
})
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
@ -90,7 +91,7 @@ var AbstractGeoJsonOverlay = L.LayerGroup.extend({
|
||||
map.on("zoomend", this.onMapMove);
|
||||
map.on("moveend", this.onMapMove);
|
||||
this.layerMgr.addListener(this.onLayerChange);
|
||||
this.reDraw(true)
|
||||
this.reDraw(true);
|
||||
},
|
||||
|
||||
onRemove: function(map) {
|
||||
|
@ -1,3 +1,5 @@
|
||||
/* exported debounce */
|
||||
|
||||
function debounce(func, wait, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
@ -9,6 +11,7 @@ function debounce(func, wait, immediate) {
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
if (callNow)
|
||||
func.apply(context, args);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user