add bounds padding

This commit is contained in:
Artem Halushko 2020-03-20 19:24:19 +02:00
parent ab29be731e
commit c79b32e769
5 changed files with 12 additions and 6 deletions

View File

@ -210,8 +210,8 @@ export default abstract class LeafletMap {
private createMarker(key, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings, setFocus = true) {
this.ready$.subscribe(() => {
const newMarker = new Marker(this.map, this.convertPosition(data), settings, data, dataSources, () => { }, this.dragMarker);
if (setFocus)
this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
if (setFocus && settings.fitMapBounds)
this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()).pad(0.2));
this.markers.set(key, newMarker);
});
}
@ -245,10 +245,10 @@ export default abstract class LeafletMap {
if (data.length) {
const dataSource = polyData.map(arr => arr[0]);
if (this.poly) {
this.updatePolyline(data, dataSource, this.options);
this.updatePolyline(data, polyData, this.options);
}
else {
this.createPolyline(data, dataSource, this.options);
this.createPolyline(data, polyData, this.options);
}
}
})

View File

@ -70,6 +70,7 @@ export type MarkerSettings = {
markerImages?: string[];
useMarkerImage: boolean;
markerImageSize: number;
fitMapBounds: boolean;
markerImage: {
length: number
}

View File

@ -166,6 +166,8 @@ export class MapWidgetController implements MapWidgetInterface {
}
update() {
console.log(parseArray(this.data));
if (this.drawRoutes)
this.map.updatePolylines(parseArray(this.data));
if (this.settings.showPolygon) {

View File

@ -46,9 +46,7 @@ export class Polygon {
}
updatePolygonColor(settings) {
console.log('Polygon -> updatePolygonColor -> settings', settings)
const style: L.PathOptions = {
fill: true,
fillColor: settings.color,
color: settings.color,

View File

@ -34,6 +34,7 @@ export class Polyline {
this.leafletPoly = L.polyline(locations,
this.getPolyStyle(settings)
).addTo(this.map);
if (settings.usePolylineDecorator) {
this.polylineDecorator = L.polylineDecorator(this.leafletPoly, this.getDecoratorSettings(settings)).addTo(this.map);
}
@ -62,12 +63,16 @@ export class Polyline {
updatePolyline(settings, data, dataSources) {
this.leafletPoly.setStyle(this.getPolyStyle(settings));
console.log( this.getPolyStyle(settings));
// this.setPolylineLatLngs(data);
if(this.polylineDecorator)
this.polylineDecorator.setPaths(this.leafletPoly);
}
getPolyStyle(settings: PolylineSettings): L.PolylineOptions {
console.log(this.data,this.dataSources, this.dataSources[this.data[0]?.dsIndex], this.data[0]?.dsIndex);
return {
color: settings.useColorFunction ?
safeExecute(settings.colorFunction, [this.data, this.dataSources, this.data[0]?.dsIndex]) : settings.color,