map: adding custom layers
This commit is contained in:
parent
a0120221ae
commit
58cd7ad026
@ -13,6 +13,7 @@
|
|||||||
- infobox: link to geouri with node's coordinates
|
- infobox: link to geouri with node's coordinates
|
||||||
- infobox: show node id
|
- infobox: show node id
|
||||||
- map: locate user
|
- map: locate user
|
||||||
|
- map: adding custom layers from leaflet.providers
|
||||||
- nodelist: sort by uptime fixed
|
- nodelist: sort by uptime fixed
|
||||||
|
|
||||||
### Fixed bugs:
|
### Fixed bugs:
|
||||||
|
38
lib/map.js
38
lib/map.js
@ -123,6 +123,8 @@ define(["d3", "leaflet", "moment", "locationmarker", "leaflet.label",
|
|||||||
var groupOnline, groupOffline, groupNew, groupLost, groupLines
|
var groupOnline, groupOffline, groupNew, groupLost, groupLines
|
||||||
|
|
||||||
var map, userLocation
|
var map, userLocation
|
||||||
|
var layerControl
|
||||||
|
var customLayers = new Set()
|
||||||
|
|
||||||
var locateUserButton = new LocateButton(function (d) {
|
var locateUserButton = new LocateButton(function (d) {
|
||||||
if (d)
|
if (d)
|
||||||
@ -160,13 +162,34 @@ define(["d3", "leaflet", "moment", "locationmarker", "leaflet.label",
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addLayer(layerName) {
|
||||||
|
if (customLayers.has(layerName))
|
||||||
|
return
|
||||||
|
|
||||||
|
try {
|
||||||
|
var layer = L.tileLayer.provider(layerName)
|
||||||
|
layerControl.addBaseLayer(layer, layerName)
|
||||||
|
customLayers.add(layerName)
|
||||||
|
|
||||||
|
if (!layerControl.added) {
|
||||||
|
layerControl.addTo(map)
|
||||||
|
layerControl.added = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localStorageTest())
|
||||||
|
localStorage.setItem("map/customLayers", JSON.stringify(Array.from(customLayers)))
|
||||||
|
} catch (e) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var el = document.createElement("div")
|
var el = document.createElement("div")
|
||||||
el.classList.add("map")
|
el.classList.add("map")
|
||||||
self.div = el
|
self.div = el
|
||||||
|
|
||||||
map = L.map(el, options)
|
map = L.map(el, options)
|
||||||
|
|
||||||
L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
var baseLayer = L.tileLayer("https://otile{s}-s.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", {
|
||||||
subdomains: "1234",
|
subdomains: "1234",
|
||||||
type: "osm",
|
type: "osm",
|
||||||
attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
attribution: "Tiles © <a href=\"https://www.mapquest.com/\" target=\"_blank\">MapQuest</a>, Data CC-BY-SA OpenStreetMap",
|
||||||
@ -179,9 +202,20 @@ define(["d3", "leaflet", "moment", "locationmarker", "leaflet.label",
|
|||||||
map.addControl(locateUserButton)
|
map.addControl(locateUserButton)
|
||||||
|
|
||||||
map.addControl(new AddLayerButton(function () {
|
map.addControl(new AddLayerButton(function () {
|
||||||
L.tileLayer.provider(prompt()).addTo(map)
|
/*eslint no-alert:0*/
|
||||||
|
var layerName = prompt("Leaflet Provider:")
|
||||||
|
addLayer(layerName)
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
layerControl = L.control.layers({"MapQuest": baseLayer}, [], {position: "bottomright"})
|
||||||
|
|
||||||
|
if (localStorageTest()) {
|
||||||
|
var layers = JSON.parse(localStorage.getItem("map/customLayers"))
|
||||||
|
|
||||||
|
if (layers)
|
||||||
|
layers.forEach(addLayer)
|
||||||
|
}
|
||||||
|
|
||||||
var nodeDict = {}
|
var nodeDict = {}
|
||||||
var linkDict = {}
|
var linkDict = {}
|
||||||
var highlight
|
var highlight
|
||||||
|
@ -41,6 +41,12 @@ module.exports = function(grunt) {
|
|||||||
expand: true,
|
expand: true,
|
||||||
dest: "build/",
|
dest: "build/",
|
||||||
cwd: "bower_components/ionicons/"
|
cwd: "bower_components/ionicons/"
|
||||||
|
},
|
||||||
|
leafletImages: {
|
||||||
|
src: [ "images/*" ],
|
||||||
|
expand: true,
|
||||||
|
dest: "build/",
|
||||||
|
cwd: "bower_components/leaflet/dist/"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
sass: {
|
sass: {
|
||||||
|
Loading…
Reference in New Issue
Block a user