|
@@ -1,10 +1,12 @@
|
|
-import L from 'leaflet';
|
|
|
|
|
|
+import L, { latLng } from 'leaflet';
|
|
import './vendor';
|
|
import './vendor';
|
|
|
|
+import './leaflet-map.css';
|
|
|
|
|
|
import maps from './maps.js';
|
|
import maps from './maps.js';
|
|
import { MapMenu, MarkerMenu } from './contextMenus';
|
|
import { MapMenu, MarkerMenu } from './contextMenus';
|
|
import lmapSidebar from './sidebar';
|
|
import lmapSidebar from './sidebar';
|
|
|
|
|
|
|
|
+
|
|
import {geojson} from './example_data';
|
|
import {geojson} from './example_data';
|
|
|
|
|
|
export var MapTypes = {
|
|
export var MapTypes = {
|
|
@@ -29,24 +31,30 @@ export class LMap {
|
|
});
|
|
});
|
|
|
|
|
|
this.mapType = type;
|
|
this.mapType = type;
|
|
|
|
+ this.domID = id;
|
|
this.options = options;
|
|
this.options = options;
|
|
|
|
+ this.mapElements = [];
|
|
|
|
+ this.status = null;
|
|
|
|
+ this.clusterGroup = L.markerClusterGroup();
|
|
|
|
|
|
|
|
+ this._initialize();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _initialize(){
|
|
|
|
+ this.map.on('click', this.mapClickHandler, this);
|
|
if(this.options.sidebar){
|
|
if(this.options.sidebar){
|
|
- this.Sidebar = lmapSidebar(id);
|
|
|
|
|
|
+ this.Sidebar = lmapSidebar(this.domID);
|
|
L.control.sidebar({
|
|
L.control.sidebar({
|
|
autopan: false,
|
|
autopan: false,
|
|
closeButton: true,
|
|
closeButton: true,
|
|
- container: id + "__lmap-sidebar",
|
|
|
|
|
|
+ container: this.domID + "__lmap-sidebar",
|
|
position: 'left'
|
|
position: 'left'
|
|
}).addTo(this.map);
|
|
}).addTo(this.map);
|
|
}
|
|
}
|
|
|
|
|
|
- if(this.options.elevation){
|
|
|
|
- this.createElevation();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- this.mapElements = [];
|
|
|
|
- this.clusterGroup = L.markerClusterGroup();
|
|
|
|
|
|
+ if(this.options.elevation) this.addElevation();
|
|
|
|
+ if(this.options.geosearch) this.addGeoSearching();
|
|
|
|
+ if(this.options.routing) this.addRouting();
|
|
}
|
|
}
|
|
|
|
|
|
setView(options){
|
|
setView(options){
|
|
@@ -68,7 +76,7 @@ export class LMap {
|
|
// }).addTo(this.map);
|
|
// }).addTo(this.map);
|
|
}
|
|
}
|
|
|
|
|
|
- addLayersControl(layers, options){
|
|
|
|
|
|
+ addTileLayers(layers, options){
|
|
var baseMaps = {};
|
|
var baseMaps = {};
|
|
layers.forEach(l => {
|
|
layers.forEach(l => {
|
|
var _map = maps[l], _layer;
|
|
var _map = maps[l], _layer;
|
|
@@ -83,6 +91,10 @@ export class LMap {
|
|
});
|
|
});
|
|
|
|
|
|
L.control.layers(baseMaps).addTo(this.map);
|
|
L.control.layers(baseMaps).addTo(this.map);
|
|
|
|
+ if(this.routingControl) {
|
|
|
|
+ this.routingControl.remove();
|
|
|
|
+ this.routingControl.addTo(this.map);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
drawPath(latlngs, options){
|
|
drawPath(latlngs, options){
|
|
@@ -136,15 +148,18 @@ export class LMap {
|
|
}
|
|
}
|
|
|
|
|
|
_createMarker(el){
|
|
_createMarker(el){
|
|
|
|
+ let _this = this;
|
|
let _icon = el.icon;
|
|
let _icon = el.icon;
|
|
let _latlng = el.cord.split(',');
|
|
let _latlng = el.cord.split(',');
|
|
|
|
|
|
let marker = L.marker(_latlng, {
|
|
let marker = L.marker(_latlng, {
|
|
|
|
+ name: el.name,
|
|
icon: this._getFontIcon(_icon.icon, _icon.color),
|
|
icon: this._getFontIcon(_icon.icon, _icon.color),
|
|
...MarkerMenu(el.name)
|
|
...MarkerMenu(el.name)
|
|
});
|
|
});
|
|
|
|
|
|
marker.bindPopup("<b>"+el.name+"</b><br>"+el.cord).openPopup();
|
|
marker.bindPopup("<b>"+el.name+"</b><br>"+el.cord).openPopup();
|
|
|
|
+ marker.on('click', this.markerClickHandler, this);
|
|
|
|
|
|
return marker;
|
|
return marker;
|
|
}
|
|
}
|
|
@@ -171,14 +186,110 @@ export class LMap {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- createElevation(){
|
|
|
|
|
|
+ addElevation(){
|
|
var hg = L.control.heightgraph({
|
|
var hg = L.control.heightgraph({
|
|
position: 'bottomright',
|
|
position: 'bottomright',
|
|
width: 800,
|
|
width: 800,
|
|
- height: 280
|
|
|
|
|
|
+ height: 280,
|
|
|
|
+ expand: false
|
|
});
|
|
});
|
|
hg.addTo(this.map);
|
|
hg.addTo(this.map);
|
|
hg.addData(geojson);
|
|
hg.addData(geojson);
|
|
L.geoJson(geojson).addTo(this.map);
|
|
L.geoJson(geojson).addTo(this.map);
|
|
|
|
+ console.log(hg);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ addGeoSearching(){
|
|
|
|
+ L.Control.geocoder({
|
|
|
|
+ position: 'topleft',
|
|
|
|
+ geocoder: L.Control.Geocoder.mapbox('pk.eyJ1IjoiaHVkYWxpbmciLCJhIjoiY2thN2xobWU1MDQ5ZTMwbWt3dHdzZzNiNSJ9.h8fncaoyA-IUhfWcjFZWiw',
|
|
|
|
+ {
|
|
|
|
+ serviceUrl: "https://api.mapbox.com/geocoding/v5/mapbox.places/"
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ }).addTo(this.map);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ addRouting(){
|
|
|
|
+ var _this = this;
|
|
|
|
+ this.routingControl = L.control.custom({
|
|
|
|
+ position: 'topright',
|
|
|
|
+ content : '<button type="button" class="btn"></button>',
|
|
|
|
+ classes : 'btn-group-vertical btn-group-sm leaflet-control-routing-btn',
|
|
|
|
+ style :
|
|
|
|
+ {
|
|
|
|
+ margin: '10px 10px 0px 0px',
|
|
|
|
+ padding: '0px 0 0 0',
|
|
|
|
+ cursor: 'pointer',
|
|
|
|
+ 'background-color': 'white',
|
|
|
|
+ 'border-radius': '5px',
|
|
|
|
+ 'box-shadow': '0 0 5px 0px #8e8e8e'
|
|
|
|
+ },
|
|
|
|
+ events:
|
|
|
|
+ {
|
|
|
|
+ click: function(e)
|
|
|
|
+ {
|
|
|
|
+ this.classList.toggle("open");
|
|
|
|
+ if(this.classList.contains('open'))
|
|
|
|
+ _this.enableRoutingContainer();
|
|
|
|
+ else
|
|
|
|
+ _this.disableRoutingContainer();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }).addTo(this.map);
|
|
|
|
+
|
|
|
|
+ this.routingControlPan = L.Routing.control({
|
|
|
|
+ router: L.Routing.mapbox('pk.eyJ1IjoiaHVkYWxpbmciLCJhIjoiY2thN2xobWU1MDQ5ZTMwbWt3dHdzZzNiNSJ9.h8fncaoyA-IUhfWcjFZWiw'),
|
|
|
|
+ geocoder: L.Control.Geocoder.mapbox('pk.eyJ1IjoiaHVkYWxpbmciLCJhIjoiY2thN2xobWU1MDQ5ZTMwbWt3dHdzZzNiNSJ9.h8fncaoyA-IUhfWcjFZWiw',
|
|
|
|
+ {
|
|
|
|
+ serviceUrl: "https://api.mapbox.com/geocoding/v5/mapbox.places/"
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
+ });
|
|
|
|
+ console.log(this.routingControlPan);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ enableRoutingContainer(){
|
|
|
|
+ this.status = "ROUTING";
|
|
|
|
+ this.routingControlPan.addTo(this.map);
|
|
|
|
+ }
|
|
|
|
+ disableRoutingContainer(){
|
|
|
|
+ this.status = null;
|
|
|
|
+ this.routingControlPan.remove();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ mapClickHandler(e){
|
|
|
|
+ console.log('map', e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ markerClickHandler(e){
|
|
|
|
+ var latlng = e.target._latlng;
|
|
|
|
+ var name = e.target.options.name;
|
|
|
|
+ this._addRoutingPoint(latlng, name);
|
|
|
|
+ console.log('marker', e);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ _addRoutingPoint(latlng, name){
|
|
|
|
+ if(this.status !== 'ROUTING' || !this.options.routing) return;
|
|
|
|
+
|
|
|
|
+ var curPoints = this.routingControlPan.getWaypoints();
|
|
|
|
+ if(curPoints.length == 2){
|
|
|
|
+ if(!curPoints[0].latLng) {
|
|
|
|
+ curPoints[0].latLng = latlng;
|
|
|
|
+ curPoints[0].name = name;
|
|
|
|
+ this.routingControlPan.setWaypoints(curPoints);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ if(!curPoints[1].latLng){
|
|
|
|
+ curPoints[1].latLng = latlng;
|
|
|
|
+ curPoints[1].name = name;
|
|
|
|
+ this.routingControlPan.setWaypoints(curPoints);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ curPoints.push(L.Routing.waypoint(latlng, name));
|
|
|
|
+ this.routingControlPan.setWaypoints(curPoints);
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|