proper bootstrap order
This commit is contained in:
parent
68f757b7d4
commit
8a5194a9f8
@ -15,6 +15,7 @@
|
|||||||
<script src="js/lib/mithril.min.js"></script>
|
<script src="js/lib/mithril.min.js"></script>
|
||||||
<script src="js/api.js"></script>
|
<script src="js/api.js"></script>
|
||||||
<script src="js/LayerManager.js"></script>
|
<script src="js/LayerManager.js"></script>
|
||||||
|
<script src="js/SimpleCRS.js"></script>
|
||||||
<script src="js/WebSocketChannel.js"></script>
|
<script src="js/WebSocketChannel.js"></script>
|
||||||
<script src="js/RealtimeTileLayer.js"></script>
|
<script src="js/RealtimeTileLayer.js"></script>
|
||||||
<script src="js/CoordinatesDisplay.js"></script>
|
<script src="js/CoordinatesDisplay.js"></script>
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function LayerManager(layers){
|
function LayerManager(layers, map){
|
||||||
|
|
||||||
|
map.on('baselayerchange', function (e) {
|
||||||
|
console.log("baselayerchange", e.layer);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LayerManager.prototype.addListener = function(listener){
|
LayerManager.prototype.addListener = function(listener){
|
||||||
|
@ -1,36 +1,39 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
function RealtimeTileLayer(wsChannel){
|
var RealtimeTileLayer = L.TileLayer.extend({
|
||||||
var self = this;
|
|
||||||
|
|
||||||
wsChannel.addListener("rendered-tile", function(tc){
|
initialize: function(wsChannel, layerId) {
|
||||||
var id = self.getImageId(tc.layerid, tc.x, tc.y, tc.zoom);
|
var self = this;
|
||||||
var el = document.getElementById(id);
|
this.layerId = layerId;
|
||||||
|
|
||||||
if (el){
|
wsChannel.addListener("rendered-tile", function(tc){
|
||||||
//Update src attribute if img found
|
if (tc.layerid != self.layerId){
|
||||||
el.src = self.getTileSource(tc.layerid, tc.x, tc.y, tc.zoom, true);
|
//ignore other layers
|
||||||
}
|
return;
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
|
||||||
RealtimeTileLayer.prototype.getTileSource = function(layerId, x,y,zoom,cacheBust){
|
var id = self.getImageId(tc.layerid, tc.x, tc.y, tc.zoom);
|
||||||
return "api/tile/" + layerId + "/" + x + "/" + y + "/" + zoom + "?_=" + Date.now();
|
var el = document.getElementById(id);
|
||||||
};
|
|
||||||
|
|
||||||
RealtimeTileLayer.prototype.getImageId = function(layerId, x, y, zoom){
|
if (el){
|
||||||
return "tile-" + layerId + "/" + x + "/" + y + "/" + zoom;
|
//Update src attribute if img found
|
||||||
};
|
el.src = self.getTileSource(tc.layerid, tc.x, tc.y, tc.zoom, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
RealtimeTileLayer.prototype.createLayer = function(layerId){
|
getTileSource: function(x,y,zoom,cacheBust){
|
||||||
var self = this;
|
return "api/tile/" + this.layerId + "/" + x + "/" + y + "/" + zoom + "?_=" + Date.now();
|
||||||
|
},
|
||||||
|
|
||||||
return L.TileLayer.extend({
|
getImageId: function(x, y, zoom){
|
||||||
createTile: function(coords){
|
return "tile-" + this.layerId + "/" + x + "/" + y + "/" + zoom;
|
||||||
var tile = document.createElement('img');
|
},
|
||||||
tile.src = self.getTileSource(layerId, coords.x, coords.y, coords.z);
|
|
||||||
tile.id = self.getImageId(layerId, coords.x, coords.y, coords.z);
|
createTile: function(coords){
|
||||||
return tile;
|
var tile = document.createElement('img');
|
||||||
}
|
tile.src = this.getTileSource(coords.x, coords.y, coords.z);
|
||||||
});
|
tile.id = this.getImageId(coords.x, coords.y, coords.z);
|
||||||
};
|
return tile;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
7
server/static/js/SimpleCRS.js
Normal file
7
server/static/js/SimpleCRS.js
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var SimpleCRS = L.Util.extend({}, L.CRS.Simple, {
|
||||||
|
scale: function (zoom) {
|
||||||
|
return Math.pow(2, zoom-9);
|
||||||
|
}
|
||||||
|
});
|
@ -1,21 +1,12 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
api.getConfig().then(function(cfg){
|
api.getConfig().then(function(cfg){
|
||||||
var layerMgr = new LayerManager(cfg.layers);
|
|
||||||
|
|
||||||
var wsChannel = new WebSocketChannel();
|
var wsChannel = new WebSocketChannel();
|
||||||
wsChannel.connect();
|
wsChannel.connect();
|
||||||
|
|
||||||
var rtTiles = new RealtimeTileLayer(wsChannel);
|
var rtTiles = new RealtimeTileLayer(wsChannel);
|
||||||
|
|
||||||
|
|
||||||
var crs = L.Util.extend({}, L.CRS.Simple, {
|
|
||||||
//transformation: L.transformation(0.001, 0, -0.001, 0),
|
|
||||||
scale: function (zoom) {
|
|
||||||
return Math.pow(2, zoom-9);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var initialZoom = 11;
|
var initialZoom = 11;
|
||||||
var initialCenter = [0, 0];
|
var initialCenter = [0, 0];
|
||||||
|
|
||||||
@ -24,7 +15,7 @@ api.getConfig().then(function(cfg){
|
|||||||
maxZoom: 12,
|
maxZoom: 12,
|
||||||
center: initialCenter,
|
center: initialCenter,
|
||||||
zoom: initialZoom,
|
zoom: initialZoom,
|
||||||
crs: crs
|
crs: SimpleCRS
|
||||||
});
|
});
|
||||||
|
|
||||||
map.attributionControl.addAttribution('<a href="https://github.com/thomasrudin-mt/mapserver">Mapserver</a>');
|
map.attributionControl.addAttribution('<a href="https://github.com/thomasrudin-mt/mapserver">Mapserver</a>');
|
||||||
@ -32,12 +23,13 @@ api.getConfig().then(function(cfg){
|
|||||||
var layers = {};
|
var layers = {};
|
||||||
var overlays = {}
|
var overlays = {}
|
||||||
|
|
||||||
var Layer = rtTiles.createLayer(0);
|
var layerMgr = new LayerManager(cfg.layers, map);
|
||||||
var tileLayer = new Layer();
|
|
||||||
|
var tileLayer = new RealtimeTileLayer(wsChannel, 0);
|
||||||
tileLayer.addTo(map);
|
tileLayer.addTo(map);
|
||||||
|
|
||||||
layers["Base"] = tileLayer;
|
layers["Base"] = tileLayer;
|
||||||
overlays["Travelnet"] = new TravelnetOverlay();
|
overlays["Travelnet"] = new TravelnetOverlay(wsChannel, layerMgr);
|
||||||
|
|
||||||
L.control.layers(layers, overlays).addTo(map);
|
L.control.layers(layers, overlays).addTo(map);
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ var TravelnetIcon = L.icon({
|
|||||||
});
|
});
|
||||||
|
|
||||||
var TravelnetOverlay = L.LayerGroup.extend({
|
var TravelnetOverlay = L.LayerGroup.extend({
|
||||||
initialize: function() {
|
initialize: function(wsChannel, layerMgr) {
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user