Commit 240f58948d04acb8ea2b943d637a50ae0630bdc9

Authored by Artem Halushko
1 parent f6ca0996

map bouds support

@@ -21,10 +21,10 @@ export default abstract class LeafletMap { @@ -21,10 +21,10 @@ export default abstract class LeafletMap {
21 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map)); 21 ready$: Observable<L.Map> = this.map$.pipe(filter(map => !!map));
22 options: MapOptions; 22 options: MapOptions;
23 isMarketCluster; 23 isMarketCluster;
  24 + bounds: L.LatLngBounds;
24 25
25 26
26 constructor($container: HTMLElement, options: MapOptions) { 27 constructor($container: HTMLElement, options: MapOptions) {
27 - console.log("LeafletMap -> constructor -> options", options)  
28 this.options = options; 28 this.options = options;
29 } 29 }
30 30
@@ -52,6 +52,11 @@ export default abstract class LeafletMap { @@ -52,6 +52,11 @@ export default abstract class LeafletMap {
52 52
53 public setMap(map: L.Map) { 53 public setMap(map: L.Map) {
54 this.map = map; 54 this.map = map;
  55 + if (this.options.useDefaultCenterPosition) {
  56 + this.map.panTo(this.options.defaultCenterPosition);
  57 + this.bounds = map.getBounds();
  58 + }
  59 + else this.bounds = new L.LatLngBounds(null, null)
55 this.map$.next(this.map); 60 this.map$.next(this.map);
56 } 61 }
57 62
@@ -147,7 +152,9 @@ export default abstract class LeafletMap { @@ -147,7 +152,9 @@ export default abstract class LeafletMap {
147 let defaultSettings: MarkerSettings = { 152 let defaultSettings: MarkerSettings = {
148 color: '#FD2785' 153 color: '#FD2785'
149 } 154 }
150 - this.markers.set(key, new Marker(this.map, location, { ...defaultSettings, ...settings })) 155 + const newMarker = new Marker(this.map, location, { ...defaultSettings, ...settings });
  156 + this.map.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()));
  157 + this.markers.set(key, newMarker);
151 }); 158 });
152 } 159 }
153 160
@@ -172,7 +179,6 @@ export default abstract class LeafletMap { @@ -172,7 +179,6 @@ export default abstract class LeafletMap {
172 } 179 }
173 180
174 else { 181 else {
175 - this.map$  
176 this.createPolyline(polyData.map(data => this.convertPosition(data)), this.options); 182 this.createPolyline(polyData.map(data => this.convertPosition(data)), this.options);
177 } 183 }
178 184
@@ -187,8 +193,13 @@ export default abstract class LeafletMap { @@ -187,8 +193,13 @@ export default abstract class LeafletMap {
187 } 193 }
188 194
189 createPolyline(locations, settings) { 195 createPolyline(locations, settings) {
190 - this.ready$.subscribe(() =>  
191 - this.poly = new Polyline(this.map, locations, settings)  
192 - ) 196 + this.ready$.subscribe(() => {
  197 + this.poly = new Polyline(this.map, locations, settings);
  198 + const bounds = this.bounds.extend(this.poly.leafletPoly.getBounds());
  199 + if (bounds.isValid()) {
  200 + this.map.fitBounds(bounds);
  201 + this.bounds = bounds;
  202 + }
  203 + });
193 } 204 }
194 } 205 }
  1 +import { LatLngExpression } from 'leaflet';
  2 +
1 export interface MapOptions { 3 export interface MapOptions {
2 initCallback?: Function, 4 initCallback?: Function,
3 defaultZoomLevel?: number, 5 defaultZoomLevel?: number,
@@ -11,8 +13,9 @@ export interface MapOptions { @@ -11,8 +13,9 @@ export interface MapOptions {
11 mapProvider: MapProviders, 13 mapProvider: MapProviders,
12 mapUrl?: string; 14 mapUrl?: string;
13 credentials?: any, // declare credentials format 15 credentials?: any, // declare credentials format
14 - defaultCenterPosition?: L.LatLngExpression,  
15 - markerClusteringSetting? 16 + defaultCenterPosition?: LatLngExpression,
  17 + markerClusteringSetting?,
  18 + useDefaultCenterPosition?: boolean
16 } 19 }
17 20
18 export enum MapProviders { 21 export enum MapProviders {
@@ -55,9 +55,7 @@ TbMapWidgetV2 = class TbMapWidgetV2 implements MapWidgetInterface { @@ -55,9 +55,7 @@ TbMapWidgetV2 = class TbMapWidgetV2 implements MapWidgetInterface {
55 onInit() { 55 onInit() {
56 } 56 }
57 57
58 - update() {  
59 - console.log(this.data,parseData(this.data) );  
60 - 58 + update() {
61 if (this.drawRoutes) 59 if (this.drawRoutes)
62 this.map.updatePolylines(parseArray(this.data)); 60 this.map.updatePolylines(parseArray(this.data));
63 this.map.updateMarkers(parseData(this.data)); 61 this.map.updateMarkers(parseData(this.data));
@@ -113,7 +113,7 @@ const canonicalTitleMap = (titleMap: any, originalEnum?: string[]): { name: stri @@ -113,7 +113,7 @@ const canonicalTitleMap = (titleMap: any, originalEnum?: string[]): { name: stri
113 113
114 const stdFormObj = (name: string, schema: any, options: DefaultsFormOptions): any => { 114 const stdFormObj = (name: string, schema: any, options: DefaultsFormOptions): any => {
115 options = options || {}; 115 options = options || {};
116 - const f = options.global && options.global.formDefaults ? _.cloneDeep(options.global.formDefaults) : {}; 116 + const f: any = options.global && options.global.formDefaults ? _.cloneDeep(options.global.formDefaults) : {};
117 if (options.global && options.global.supressPropertyTitles === true) { 117 if (options.global && options.global.supressPropertyTitles === true) {
118 f.title = schema.title; 118 f.title = schema.title;
119 } else { 119 } else {