|
|
@ -23,7 +23,7 @@ import 'leaflet.markercluster/dist/leaflet.markercluster' |
|
|
|
|
|
|
|
|
import { MapSettings, MarkerSettings, FormattedData, UnitedMapSettings, PolygonSettings, PolylineSettings } from './map-models'; |
|
|
import { MapSettings, MarkerSettings, FormattedData, UnitedMapSettings, PolygonSettings, PolylineSettings } from './map-models'; |
|
|
import { Marker } from './markers'; |
|
|
import { Marker } from './markers'; |
|
|
import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; |
|
|
import { Observable, BehaviorSubject } from 'rxjs'; |
|
|
import { filter } from 'rxjs/operators'; |
|
|
import { filter } from 'rxjs/operators'; |
|
|
import { Polyline } from './polyline'; |
|
|
import { Polyline } from './polyline'; |
|
|
import { Polygon } from './polygon'; |
|
|
import { Polygon } from './polygon'; |
|
|
@ -64,7 +64,7 @@ export default abstract class LeafletMap { |
|
|
let mousePositionOnMap: L.LatLng; |
|
|
let mousePositionOnMap: L.LatLng; |
|
|
let addMarker: L.Control; |
|
|
let addMarker: L.Control; |
|
|
this.map.on('mouseup', (e: L.LeafletMouseEvent) => { |
|
|
this.map.on('mouseup', (e: L.LeafletMouseEvent) => { |
|
|
mousePositionOnMap = e.latlng |
|
|
mousePositionOnMap = e.latlng; |
|
|
}) |
|
|
}) |
|
|
const dragListener = (e: L.DragEndEvent) => { |
|
|
const dragListener = (e: L.DragEndEvent) => { |
|
|
if (e.type === 'dragend' && mousePositionOnMap) { |
|
|
if (e.type === 'dragend' && mousePositionOnMap) { |
|
|
@ -164,6 +164,23 @@ export default abstract class LeafletMap { |
|
|
return this.map.getCenter(); |
|
|
return this.map.getCenter(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fitBounds(bounds, useDefaultZoom = false) { |
|
|
|
|
|
if (bounds.isValid()) { |
|
|
|
|
|
if ((this.options.dontFitMapBounds || useDefaultZoom) && this.options.defaultZoomLevel) { |
|
|
|
|
|
this.map.setZoom(this.options.defaultZoomLevel, { animate: false }); |
|
|
|
|
|
this.map.panTo(bounds.getCenter(), { animate: false }); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.map.once('zoomend', function () { |
|
|
|
|
|
if (!this.options.defaultZoomLevel && this.options.map.getZoom() > this.options.minZoomLevel) { |
|
|
|
|
|
this.map.setZoom(this.options.minZoomLevel, { animate: false }); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
this.map.fitBounds(bounds, { padding: [50, 50], animate: false }); |
|
|
|
|
|
} |
|
|
|
|
|
this.bounds = this.bounds.extend(bounds); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
convertPosition(expression: object): L.LatLng { |
|
|
convertPosition(expression: object): L.LatLng { |
|
|
if (!expression) return null; |
|
|
if (!expression) return null; |
|
|
const lat = expression[this.options.latKeyName]; |
|
|
const lat = expression[this.options.latKeyName]; |
|
|
@ -185,7 +202,7 @@ export default abstract class LeafletMap { |
|
|
updateMarkers(markersData) { |
|
|
updateMarkers(markersData) { |
|
|
markersData.forEach(data => { |
|
|
markersData.forEach(data => { |
|
|
if (this.convertPosition(data)) { |
|
|
if (this.convertPosition(data)) { |
|
|
if (data.rotationAngle) { |
|
|
if (data.rotationAngle || data.rotationAngle === 0) { |
|
|
this.options.icon = L.divIcon({ |
|
|
this.options.icon = L.divIcon({ |
|
|
html: `<div class="arrow" style="transform: translate(-10px, -10px) rotate(${data.rotationAngle}deg);"><div>` |
|
|
html: `<div class="arrow" style="transform: translate(-10px, -10px) rotate(${data.rotationAngle}deg);"><div>` |
|
|
}) |
|
|
}) |
|
|
@ -211,8 +228,7 @@ export default abstract class LeafletMap { |
|
|
private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, setFocus = true) { |
|
|
private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, setFocus = true) { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const newMarker = new Marker(this.map, this.convertPosition(data), settings, data, dataSources, () => { }, this.dragMarker); |
|
|
const newMarker = new Marker(this.map, this.convertPosition(data), settings, data, dataSources, () => { }, this.dragMarker); |
|
|
if (setFocus /*&& settings.fitMapBounds*/) |
|
|
this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()), setFocus); |
|
|
this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()).pad(0.2)); |
|
|
|
|
|
this.markers.set(key, newMarker); |
|
|
this.markers.set(key, newMarker); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -260,11 +276,8 @@ export default abstract class LeafletMap { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const poly = new Polyline(this.map, |
|
|
const poly = new Polyline(this.map, |
|
|
data.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
data.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
const bounds = this.bounds.extend(poly.leafletPoly.getBounds().pad(0.2)); |
|
|
const bounds = this.bounds.extend(poly.leafletPoly.getBounds()); |
|
|
if (bounds.isValid()) { |
|
|
this.fitBounds(bounds) |
|
|
this.map.fitBounds(bounds); |
|
|
|
|
|
this.bounds = bounds; |
|
|
|
|
|
} |
|
|
|
|
|
this.polylines.set(data[0].entityName, poly) |
|
|
this.polylines.set(data[0].entityName, poly) |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
@ -296,7 +309,7 @@ export default abstract class LeafletMap { |
|
|
createPolygon(key: string, data: LatLngTuple[], dataSources: DatasourceData[], settings: PolygonSettings) { |
|
|
createPolygon(key: string, data: LatLngTuple[], dataSources: DatasourceData[], settings: PolygonSettings) { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const polygon = new Polygon(this.map, data, dataSources, settings); |
|
|
const polygon = new Polygon(this.map, data, dataSources, settings); |
|
|
const bounds = this.bounds.extend(polygon.leafletPoly.getBounds().pad(0.2)); |
|
|
const bounds = this.bounds.extend(polygon.leafletPoly.getBounds()); |
|
|
if (bounds.isValid()) { |
|
|
if (bounds.isValid()) { |
|
|
this.map.fitBounds(bounds); |
|
|
this.map.fitBounds(bounds); |
|
|
this.bounds = bounds; |
|
|
this.bounds = bounds; |
|
|
|