2019-01-17 13:56:25 +00:00
|
|
|
"use strict";
|
|
|
|
|
2019-01-17 14:07:31 +00:00
|
|
|
// Import leaflet, but some plugins require it to have the variable name 'L' :-/
|
|
|
|
import L from 'leaflet';
|
|
|
|
import 'leaflet-fullscreen';
|
2019-01-17 13:56:25 +00:00
|
|
|
|
|
|
|
import Config from './Config.mjs';
|
2019-01-17 16:13:27 +00:00
|
|
|
import LayerDeviceMarkers from './LayerDeviceMarkers.mjs';
|
2019-01-17 13:56:25 +00:00
|
|
|
|
|
|
|
class Map {
|
|
|
|
constructor() {
|
|
|
|
}
|
|
|
|
|
|
|
|
setup() {
|
2019-01-17 16:13:27 +00:00
|
|
|
// Create the map
|
2019-01-17 14:07:31 +00:00
|
|
|
this.map = L.map("map", {
|
|
|
|
fullscreenControl: true
|
|
|
|
});
|
2019-01-17 13:56:25 +00:00
|
|
|
this.map.setView(Config.default_location, Config.default_zoom);
|
|
|
|
|
2019-01-17 16:13:27 +00:00
|
|
|
// Add the OpenStreetMap tile layer
|
2019-01-17 14:07:31 +00:00
|
|
|
this.layer_openstreet = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
2019-01-17 13:56:25 +00:00
|
|
|
id: "openstreetmap",
|
|
|
|
maxZoom: 19,
|
2019-01-17 13:58:56 +00:00
|
|
|
attribution: "© <a href='https://www.openstreetmap.org/copyright'>OpenStreetMap contributors</a>"
|
2019-01-17 13:56:25 +00:00
|
|
|
}).addTo(this.map);
|
2019-01-17 16:13:27 +00:00
|
|
|
|
|
|
|
// Add the device markers
|
|
|
|
console.info("[map] Loading device markers....");
|
|
|
|
this.device_markers = new LayerDeviceMarkers(this.map);
|
|
|
|
this.device_markers.setup().then(() => {
|
|
|
|
console.info("[map] Device markers loaded successfully.");
|
2019-01-17 16:38:15 +00:00
|
|
|
|
|
|
|
// Display a layer controller
|
|
|
|
this.setup_layer_control();
|
2019-01-17 16:13:27 +00:00
|
|
|
});
|
2019-01-17 16:38:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
setup_layer_control() {
|
|
|
|
this.layer_control = L.control.layers({
|
|
|
|
// Base layer(s)
|
|
|
|
"OpenStreetMap": this.layer_openstreet
|
|
|
|
}, { // Overlay(s)
|
|
|
|
"Devices": this.device_markers.layer
|
|
|
|
}, { // Options
|
2019-01-17 16:39:47 +00:00
|
|
|
|
2019-01-17 16:38:15 +00:00
|
|
|
});
|
|
|
|
this.layer_control.addTo(this.map);
|
2019-01-17 13:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Map;
|