|
|
|
@ -150,7 +150,7 @@ export default abstract class LeafletMap { |
|
|
|
this.deleteMarker(ds.entityName); |
|
|
|
this.createMarker(ds.entityName, updatedEnttity, this.datasources, this.options); |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
datasourcesList.append(dsItem); |
|
|
|
}); |
|
|
|
datasourcesList.append(document.createElement('br')); |
|
|
|
@ -158,14 +158,14 @@ export default abstract class LeafletMap { |
|
|
|
deleteBtn.appendChild(document.createTextNode('Discard changes')); |
|
|
|
deleteBtn.onclick = () => { |
|
|
|
this.map.removeLayer(newMarker); |
|
|
|
} |
|
|
|
}; |
|
|
|
datasourcesList.append(deleteBtn); |
|
|
|
const popup = L.popup(); |
|
|
|
popup.setContent(datasourcesList); |
|
|
|
newMarker.bindPopup(popup).openPopup(); |
|
|
|
} |
|
|
|
addMarker.setPosition('topright') |
|
|
|
} |
|
|
|
addMarker.setPosition('topright'); |
|
|
|
}; |
|
|
|
L.Control.AddMarker = L.Control.extend({ |
|
|
|
onAdd() { |
|
|
|
const img = L.DomUtil.create('img') as any; |
|
|
|
@ -177,7 +177,7 @@ export default abstract class LeafletMap { |
|
|
|
img.draggable = true; |
|
|
|
const draggableImg = new L.Draggable(img); |
|
|
|
draggableImg.enable(); |
|
|
|
draggableImg.on('dragend', dragListener) |
|
|
|
draggableImg.on('dragend', dragListener); |
|
|
|
return img; |
|
|
|
}, |
|
|
|
onRemove() { |
|
|
|
@ -186,7 +186,7 @@ export default abstract class LeafletMap { |
|
|
|
} as any); |
|
|
|
L.control.addMarker = (opts) => { |
|
|
|
return new L.Control.AddMarker(opts); |
|
|
|
} |
|
|
|
}; |
|
|
|
addMarker = L.control.addMarker({ position: 'topright' }).addTo(this.map); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -198,8 +198,8 @@ export default abstract class LeafletMap { |
|
|
|
this.map.on('mousemove', (e: L.LeafletMouseEvent) => { |
|
|
|
const latlng1 = e.latlng; |
|
|
|
const latlng2 = L.latLng(e.latlng.lat, e.latlng.lng + 10); |
|
|
|
const latlng3 = L.latLng(e.latlng.lat-10, e.latlng.lng); |
|
|
|
mousePositionOnMap = [latlng1,latlng2, latlng3 ]; |
|
|
|
const latlng3 = L.latLng(e.latlng.lat - 10, e.latlng.lng); |
|
|
|
mousePositionOnMap = [latlng1, latlng2, latlng3]; |
|
|
|
}); |
|
|
|
const dragListener = (e: L.DragEndEvent) => { |
|
|
|
if (e.type === 'dragend' && mousePositionOnMap) { |
|
|
|
@ -220,7 +220,7 @@ export default abstract class LeafletMap { |
|
|
|
this.map.removeLayer(newPolygon); |
|
|
|
this.deletePolygon(ds.entityName); |
|
|
|
}); |
|
|
|
} |
|
|
|
}; |
|
|
|
datasourcesList.append(dsItem); |
|
|
|
}); |
|
|
|
datasourcesList.append(document.createElement('br')); |
|
|
|
@ -228,14 +228,14 @@ export default abstract class LeafletMap { |
|
|
|
deleteBtn.appendChild(document.createTextNode('Discard changes')); |
|
|
|
deleteBtn.onclick = () => { |
|
|
|
this.map.removeLayer(newPolygon); |
|
|
|
} |
|
|
|
}; |
|
|
|
datasourcesList.append(deleteBtn); |
|
|
|
const popup = L.popup(); |
|
|
|
popup.setContent(datasourcesList); |
|
|
|
newPolygon.bindPopup(popup).openPopup(); |
|
|
|
} |
|
|
|
addPolygon.setPosition('topright') |
|
|
|
} |
|
|
|
addPolygon.setPosition('topright'); |
|
|
|
}; |
|
|
|
L.Control.AddPolygon = L.Control.extend({ |
|
|
|
onAdd() { |
|
|
|
const img = L.DomUtil.create('img') as any; |
|
|
|
@ -247,7 +247,7 @@ export default abstract class LeafletMap { |
|
|
|
img.draggable = true; |
|
|
|
const draggableImg = new L.Draggable(img); |
|
|
|
draggableImg.enable(); |
|
|
|
draggableImg.on('dragend', dragListener) |
|
|
|
draggableImg.on('dragend', dragListener); |
|
|
|
return img; |
|
|
|
}, |
|
|
|
onRemove() { |
|
|
|
@ -256,7 +256,7 @@ export default abstract class LeafletMap { |
|
|
|
} as any); |
|
|
|
L.control.addPolygon = (opts) => { |
|
|
|
return new L.Control.AddPolygon(opts); |
|
|
|
} |
|
|
|
}; |
|
|
|
addPolygon = L.control.addPolygon({ position: 'topright' }).addTo(this.map); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -280,10 +280,11 @@ export default abstract class LeafletMap { |
|
|
|
public setMap(map: L.Map) { |
|
|
|
this.map = map; |
|
|
|
if (this.options.useDefaultCenterPosition) { |
|
|
|
this.map.panTo(this.options.defaultCenterPosition); |
|
|
|
this.bounds = map.getBounds(); |
|
|
|
this.map.panTo(this.options.defaultCenterPosition); |
|
|
|
this.bounds = map.getBounds(); |
|
|
|
} else { |
|
|
|
this.bounds = new L.LatLngBounds(null, null); |
|
|
|
} |
|
|
|
else this.bounds = new L.LatLngBounds(null, null); |
|
|
|
if (this.options.draggableMarker) { |
|
|
|
this.addMarkerControl(); |
|
|
|
} |
|
|
|
@ -299,11 +300,11 @@ export default abstract class LeafletMap { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public saveMarkerLocation(_e: FormattedData, lat?: number, lng?: number): Observable<any> { |
|
|
|
public saveMarkerLocation(datasource: FormattedData, lat?: number, lng?: number): Observable<any> { |
|
|
|
return of(null); |
|
|
|
} |
|
|
|
|
|
|
|
public savePolygonLocation(_e: FormattedData, coordinates?: Array<[number, number]>): Observable<any> { |
|
|
|
public savePolygonLocation(datasource: FormattedData, coordinates?: Array<[number, number]>): Observable<any> { |
|
|
|
return of(null); |
|
|
|
} |
|
|
|
|
|
|
|
@ -364,7 +365,9 @@ export default abstract class LeafletMap { |
|
|
|
} |
|
|
|
|
|
|
|
convertPosition(expression: object): L.LatLng { |
|
|
|
if (!expression) return null; |
|
|
|
if (!expression) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
const lat = expression[this.options.latKeyName]; |
|
|
|
const lng = expression[this.options.lngKeyName]; |
|
|
|
if (!isDefinedAndNotNull(lat) || isString(lat) || isNaN(lat) || !isDefinedAndNotNull(lng) || isString(lng) || isNaN(lng)) { |
|
|
|
@ -382,34 +385,34 @@ export default abstract class LeafletMap { |
|
|
|
} else { |
|
|
|
return null; |
|
|
|
} |
|
|
|
}).filter(el => !!el) |
|
|
|
}).filter(el => !!el); |
|
|
|
} |
|
|
|
|
|
|
|
convertToCustomFormat(position: L.LatLng): object { |
|
|
|
return { |
|
|
|
[this.options.latKeyName]: position.lat % 90, |
|
|
|
[this.options.lngKeyName]: position.lng % 180 |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
convertToPolygonFormat(points: Array<any>): Array<any> { |
|
|
|
if (points.length) { |
|
|
|
return points.map(point=> { |
|
|
|
return points.map(point => { |
|
|
|
if (point.length) { |
|
|
|
return this.convertToPolygonFormat(point); |
|
|
|
} else { |
|
|
|
return [point.lat, point.lng]; |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
} else { |
|
|
|
return [] |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
convertPolygonToCustomFormat(expression: any[][]): object { |
|
|
|
return { |
|
|
|
[this.options.polygonKeyName] : this.convertToPolygonFormat(expression) |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
updateData(drawRoutes: boolean, showPolygon: boolean) { |
|
|
|
@ -509,7 +512,7 @@ export default abstract class LeafletMap { |
|
|
|
this.markersCluster.addLayers(createdMarkers.map(marker => marker.leafletMarker)); |
|
|
|
} |
|
|
|
if (updatedMarkers.length) { |
|
|
|
this.markersCluster.refreshClusters(updatedMarkers.map(marker => marker.leafletMarker)) |
|
|
|
this.markersCluster.refreshClusters(updatedMarkers.map(marker => marker.leafletMarker)); |
|
|
|
} |
|
|
|
if (deletedMarkers.length) { |
|
|
|
this.markersCluster.removeLayers(deletedMarkers.map(marker => marker.leafletMarker)); |
|
|
|
@ -518,7 +521,9 @@ export default abstract class LeafletMap { |
|
|
|
} |
|
|
|
|
|
|
|
dragMarker = (e, data = {} as FormattedData) => { |
|
|
|
if (e.type !== 'dragend') return; |
|
|
|
if (e.type !== 'dragend') { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.saveMarkerLocation({ ...data, ...this.convertToCustomFormat(e.target._latlng) }).subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -527,7 +532,7 @@ export default abstract class LeafletMap { |
|
|
|
const newMarker = new Marker(this, this.convertPosition(data), settings, data, dataSources, this.dragMarker); |
|
|
|
if (callback) { |
|
|
|
newMarker.leafletMarker.on('click', () => { |
|
|
|
callback(data, true) |
|
|
|
callback(data, true); |
|
|
|
}); |
|
|
|
} |
|
|
|
if (this.bounds && updateBounds && !(this.options as MarkerSettings).useClusterMarkers) { |
|
|
|
@ -684,7 +689,9 @@ export default abstract class LeafletMap { |
|
|
|
} |
|
|
|
|
|
|
|
dragPolygonVertex = (e?, data = {} as FormattedData) => { |
|
|
|
if (e === undefined || (e.type !== 'editable:vertex:dragend' && e.type !== 'editable:vertex:deleted')) return; |
|
|
|
if (e === undefined || (e.type !== 'editable:vertex:dragend' && e.type !== 'editable:vertex:deleted')) { |
|
|
|
return; |
|
|
|
} |
|
|
|
this.savePolygonLocation({ ...data, ...this.convertPolygonToCustomFormat(e.layer._latlngs) }).subscribe(); |
|
|
|
} |
|
|
|
|
|
|
|
|