|
|
@ -21,7 +21,7 @@ import 'leaflet.markercluster/dist/MarkerCluster.css' |
|
|
import 'leaflet.markercluster/dist/MarkerCluster.Default.css' |
|
|
import 'leaflet.markercluster/dist/MarkerCluster.Default.css' |
|
|
import 'leaflet.markercluster/dist/leaflet.markercluster' |
|
|
import 'leaflet.markercluster/dist/leaflet.markercluster' |
|
|
|
|
|
|
|
|
import { MapOptions, MarkerSettings } from './map-models'; |
|
|
import { MapSettings, MarkerSettings, FormattedData } from './map-models'; |
|
|
import { Marker } from './markers'; |
|
|
import { Marker } from './markers'; |
|
|
import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; |
|
|
import { Observable, of, BehaviorSubject, Subject } from 'rxjs'; |
|
|
import { filter } from 'rxjs/operators'; |
|
|
import { filter } from 'rxjs/operators'; |
|
|
@ -38,15 +38,15 @@ export default abstract class LeafletMap { |
|
|
map: L.Map; |
|
|
map: L.Map; |
|
|
map$: BehaviorSubject<L.Map> = new BehaviorSubject(null); |
|
|
map$: BehaviorSubject<L.Map> = new BehaviorSubject(null); |
|
|
ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); |
|
|
ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); |
|
|
options: MapOptions; |
|
|
options: MapSettings & MarkerSettings; |
|
|
isMarketCluster: boolean; |
|
|
isMarketCluster: boolean; |
|
|
bounds: L.LatLngBounds; |
|
|
bounds: L.LatLngBounds; |
|
|
|
|
|
|
|
|
constructor($container: HTMLElement, options: MapOptions) { |
|
|
constructor($container: HTMLElement, options: MapSettings & MarkerSettings) { |
|
|
this.options = options; |
|
|
this.options = options; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public initSettings(options: MapOptions) { |
|
|
public initSettings(options: MapSettings) { |
|
|
const { initCallback, |
|
|
const { initCallback, |
|
|
defaultZoomLevel, |
|
|
defaultZoomLevel, |
|
|
dontFitMapBounds, |
|
|
dontFitMapBounds, |
|
|
@ -56,7 +56,7 @@ export default abstract class LeafletMap { |
|
|
credentials, |
|
|
credentials, |
|
|
defaultCenterPosition, |
|
|
defaultCenterPosition, |
|
|
draggebleMarker, |
|
|
draggebleMarker, |
|
|
markerClusteringSetting }: MapOptions = options; |
|
|
markerClusteringSetting }: MapSettings = options; |
|
|
if (disableScrollZooming) { |
|
|
if (disableScrollZooming) { |
|
|
this.map.scrollWheelZoom.disable(); |
|
|
this.map.scrollWheelZoom.disable(); |
|
|
} |
|
|
} |
|
|
@ -86,16 +86,12 @@ export default abstract class LeafletMap { |
|
|
} |
|
|
} |
|
|
} as any); |
|
|
} as any); |
|
|
|
|
|
|
|
|
L.control.addMarker = function (opts) { |
|
|
L.control.addMarker = (opts) => { |
|
|
return new L.Control.AddMarker(opts); |
|
|
return new L.Control.AddMarker(opts); |
|
|
} |
|
|
} |
|
|
L.control.addMarker({ position: 'topright' }).addTo(this.map); |
|
|
L.control.addMarker({ position: 'topright' }).addTo(this.map); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/*inited() {/// !!!!
|
|
|
|
|
|
return !!this.map; |
|
|
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
public setMap(map: L.Map) { |
|
|
public setMap(map: L.Map) { |
|
|
this.map = map; |
|
|
this.map = map; |
|
|
if (this.options.useDefaultCenterPosition) { |
|
|
if (this.options.useDefaultCenterPosition) { |
|
|
@ -117,10 +113,6 @@ export default abstract class LeafletMap { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
getContainer() { |
|
|
|
|
|
return this.map; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
createLatLng(lat: number, lng: number): L.LatLng { |
|
|
createLatLng(lat: number, lng: number): L.LatLng { |
|
|
return L.latLng(lat, lng); |
|
|
return L.latLng(lat, lng); |
|
|
} |
|
|
} |
|
|
@ -147,8 +139,13 @@ export default abstract class LeafletMap { |
|
|
return this.map.getCenter(); |
|
|
return this.map.getCenter(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
convertPosition(expression: any): L.LatLng { |
|
|
convertPosition(expression: object): L.LatLng { |
|
|
return L.latLng(expression[this.options.latKeyName], expression[this.options.lngKeyName]) as L.LatLng; |
|
|
const lat = expression[this.options.latKeyName]; |
|
|
|
|
|
const lng = expression[this.options.lngKeyName]; |
|
|
|
|
|
if (isNaN(lat) || isNaN(lng)) |
|
|
|
|
|
return null; |
|
|
|
|
|
else |
|
|
|
|
|
return L.latLng(lat, lng) as L.LatLng; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
convertToCustomFormat(position: L.LatLng): object { |
|
|
convertToCustomFormat(position: L.LatLng): object { |
|
|
@ -161,24 +158,26 @@ export default abstract class LeafletMap { |
|
|
// Markers
|
|
|
// Markers
|
|
|
updateMarkers(markersData) { |
|
|
updateMarkers(markersData) { |
|
|
markersData.forEach(data => { |
|
|
markersData.forEach(data => { |
|
|
if (data.rotationAngle) { |
|
|
if (this.convertPosition(data)) { |
|
|
this.options.icon = L.divIcon({ |
|
|
if (data.rotationAngle) { |
|
|
html: `<div class="arrow" style="transform: rotate(${data.rotationAngle}deg)"><div>` |
|
|
this.options.icon = L.divIcon({ |
|
|
}) |
|
|
html: `<div class="arrow" style="transform: rotate(${data.rotationAngle}deg)"><div>` |
|
|
} |
|
|
}) |
|
|
else { |
|
|
} |
|
|
this.options.icon = null; |
|
|
else { |
|
|
} |
|
|
this.options.icon = null; |
|
|
if (this.markers.get(data.aliasName)) { |
|
|
} |
|
|
this.updateMarker(data.aliasName, data, markersData, this.options as MarkerSettings) |
|
|
if (this.markers.get(data.aliasName)) { |
|
|
} |
|
|
this.updateMarker(data.aliasName, data, markersData, this.options) |
|
|
else { |
|
|
} |
|
|
this.createMarker(data.aliasName, data, markersData, this.options as MarkerSettings); |
|
|
else { |
|
|
|
|
|
this.createMarker(data.aliasName, data, markersData, this.options as MarkerSettings); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private createMarker(key, data, dataSources, settings: MarkerSettings) { |
|
|
private createMarker(key, data: FormattedData, dataSources, settings: MarkerSettings) { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
const newMarker = new Marker(this.map, this.convertPosition(data), settings, data, dataSources); |
|
|
const newMarker = new Marker(this.map, this.convertPosition(data), settings, data, dataSources); |
|
|
this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); |
|
|
this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng())); |
|
|
@ -219,10 +218,11 @@ export default abstract class LeafletMap { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
createPolyline(data, dataSources, settings) { |
|
|
createPolyline(data: any[], dataSources, settings) { |
|
|
if (data.length) |
|
|
if (data.length) |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
this.poly = new Polyline(this.map, data.map(data => this.convertPosition(data)), data, dataSources, settings); |
|
|
this.poly = new Polyline(this.map, |
|
|
|
|
|
data.map(el => this.convertPosition(el)).filter(el => !!el), data, dataSources, settings); |
|
|
const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds()); |
|
|
const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds()); |
|
|
if (bounds.isValid()) { |
|
|
if (bounds.isValid()) { |
|
|
this.map.fitBounds(bounds); |
|
|
this.map.fitBounds(bounds); |
|
|
@ -237,7 +237,7 @@ export default abstract class LeafletMap { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// polygon
|
|
|
// Polygon
|
|
|
|
|
|
|
|
|
updatePolygons(polyData: Array<Array<any>>) { |
|
|
updatePolygons(polyData: Array<Array<any>>) { |
|
|
polyData.forEach((data: any) => { |
|
|
polyData.forEach((data: any) => { |
|
|
@ -268,7 +268,7 @@ export default abstract class LeafletMap { |
|
|
|
|
|
|
|
|
updatePolygon(data, dataSources, settings) { |
|
|
updatePolygon(data, dataSources, settings) { |
|
|
this.ready$.subscribe(() => { |
|
|
this.ready$.subscribe(() => { |
|
|
// this.polygon.updatePolygon(settings, data, dataSources);
|
|
|
// this.polygon.updatePolygon(settings, data, dataSources);
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |