image map alias image support
This commit is contained in:
		
							parent
							
								
									0ce514b58c
								
							
						
					
					
						commit
						2bd1a796e0
					
				@ -257,8 +257,6 @@ export default abstract class LeafletMap {
 | 
				
			|||||||
    private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings) {
 | 
					    private createMarker(key: string, data: FormattedData, dataSources: FormattedData[], settings: MarkerSettings) {
 | 
				
			||||||
        this.ready$.subscribe(() => {
 | 
					        this.ready$.subscribe(() => {
 | 
				
			||||||
            const newMarker = new Marker(this.convertPosition(data), settings, data, dataSources, this.dragMarker);
 | 
					            const newMarker = new Marker(this.convertPosition(data), settings, data, dataSources, this.dragMarker);
 | 
				
			||||||
            console.log(this.bounds);
 | 
					 | 
				
			||||||
            
 | 
					 | 
				
			||||||
            this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()), settings.draggableMarker && this.markers.size < 2);
 | 
					            this.fitBounds(this.bounds.extend(newMarker.leafletMarker.getLatLng()), settings.draggableMarker && this.markers.size < 2);
 | 
				
			||||||
            this.markers.set(key, newMarker);
 | 
					            this.markers.set(key, newMarker);
 | 
				
			||||||
            if (this.options.useClusterMarkers) {
 | 
					            if (this.options.useClusterMarkers) {
 | 
				
			||||||
@ -294,7 +292,7 @@ export default abstract class LeafletMap {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    setImageAlias(alias:Observable<any>){       
 | 
					    setImageAlias(alias:Observable<any>){
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Polyline
 | 
					    // Polyline
 | 
				
			||||||
 | 
				
			|||||||
@ -31,9 +31,9 @@ import {
 | 
				
			|||||||
} from './schemes';
 | 
					} from './schemes';
 | 
				
			||||||
import { MapWidgetStaticInterface, MapWidgetInterface } from './map-widget.interface';
 | 
					import { MapWidgetStaticInterface, MapWidgetInterface } from './map-widget.interface';
 | 
				
			||||||
import { OpenStreetMap, TencentMap, GoogleMap, HEREMap, ImageMap } from './providers';
 | 
					import { OpenStreetMap, TencentMap, GoogleMap, HEREMap, ImageMap } from './providers';
 | 
				
			||||||
import { parseFunction, parseArray, parseData, safeExecute, parseWithTranslation } from '@core/utils';
 | 
					import { parseFunction, parseArray, parseData, parseWithTranslation } from '@core/utils';
 | 
				
			||||||
import { initSchema, addToSchema, mergeSchemes, addCondition, addGroupInfo } from '@core/schema-utils';
 | 
					import { initSchema, addToSchema, mergeSchemes, addCondition, addGroupInfo } from '@core/schema-utils';
 | 
				
			||||||
import { forkJoin, of, Observable } from 'rxjs';
 | 
					import { of, Subject } from 'rxjs';
 | 
				
			||||||
import { WidgetContext } from '@app/modules/home/models/widget-component.models';
 | 
					import { WidgetContext } from '@app/modules/home/models/widget-component.models';
 | 
				
			||||||
import { getDefCenterPosition } from './maps-utils';
 | 
					import { getDefCenterPosition } from './maps-utils';
 | 
				
			||||||
import { JsonSettingsSchema, WidgetActionDescriptor, DatasourceType, widgetType } from '@shared/models/widget.models';
 | 
					import { JsonSettingsSchema, WidgetActionDescriptor, DatasourceType, widgetType } from '@shared/models/widget.models';
 | 
				
			||||||
@ -48,7 +48,6 @@ import { UtilsService } from '@core/services/utils.service';
 | 
				
			|||||||
export class MapWidgetController implements MapWidgetInterface {
 | 
					export class MapWidgetController implements MapWidgetInterface {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(public mapProvider: MapProviders, private drawRoutes: boolean, public ctx: WidgetContext, $element: HTMLElement) {
 | 
					    constructor(public mapProvider: MapProviders, private drawRoutes: boolean, public ctx: WidgetContext, $element: HTMLElement) {
 | 
				
			||||||
        console.log('MapWidgetController -> constructor -> ctx', ctx)
 | 
					 | 
				
			||||||
        if (this.map) {
 | 
					        if (this.map) {
 | 
				
			||||||
            this.map.map.remove();
 | 
					            this.map.map.remove();
 | 
				
			||||||
            delete this.map;
 | 
					            delete this.map;
 | 
				
			||||||
@ -85,7 +84,6 @@ export class MapWidgetController implements MapWidgetInterface {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static getProvidersSchema(mapProvider: MapProviders) {
 | 
					    public static getProvidersSchema(mapProvider: MapProviders) {
 | 
				
			||||||
        console.log('MapWidgetController -> getProvidersSchema -> mapProvider', mapProvider)
 | 
					 | 
				
			||||||
        mapProviderSchema.schema.properties.provider.default = mapProvider;
 | 
					        mapProviderSchema.schema.properties.provider.default = mapProvider;
 | 
				
			||||||
        return mergeSchemes([mapProviderSchema,
 | 
					        return mergeSchemes([mapProviderSchema,
 | 
				
			||||||
            ...Object.keys(providerSets)?.map(
 | 
					            ...Object.keys(providerSets)?.map(
 | 
				
			||||||
@ -178,7 +176,7 @@ export class MapWidgetController implements MapWidgetInterface {
 | 
				
			|||||||
            entityId,
 | 
					            entityId,
 | 
				
			||||||
            AttributeScope.SHARED_SCOPE,
 | 
					            AttributeScope.SHARED_SCOPE,
 | 
				
			||||||
            keys
 | 
					            keys
 | 
				
			||||||
        ).subscribe(res => {
 | 
					        ).subscribe(() => {
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -255,15 +253,19 @@ export class MapWidgetController implements MapWidgetInterface {
 | 
				
			|||||||
                ]
 | 
					                ]
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
 | 
					        const result = new Subject();
 | 
				
			||||||
        const imageUrlSubscriptionOptions = {
 | 
					        const imageUrlSubscriptionOptions = {
 | 
				
			||||||
            datasources,
 | 
					            datasources,
 | 
				
			||||||
            useDashboardTimewindow: false,
 | 
					            useDashboardTimewindow: false,
 | 
				
			||||||
            type: widgetType.latest,
 | 
					            type: widgetType.latest,
 | 
				
			||||||
            callbacks: {
 | 
					            callbacks: {
 | 
				
			||||||
                onDataUpdated: (subscription, apply) => { }
 | 
					                onDataUpdated: (subscription) => {
 | 
				
			||||||
 | 
					                    result.next(subscription.data[0].data[0]);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
        return this.ctx.subscriptionApi.createSubscription(imageUrlSubscriptionOptions, true);
 | 
					        this.ctx.subscriptionApi.createSubscription(imageUrlSubscriptionOptions, true).subscribe(() => { });
 | 
				
			||||||
 | 
					        return result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    onDestroy() {
 | 
					    onDestroy() {
 | 
				
			||||||
 | 
				
			|||||||
@ -16,10 +16,10 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import L, { LatLngLiteral } from 'leaflet';
 | 
					import L, { LatLngLiteral } from 'leaflet';
 | 
				
			||||||
import LeafletMap from '../leaflet-map';
 | 
					import LeafletMap from '../leaflet-map';
 | 
				
			||||||
import { MapSettings, UnitedMapSettings } from '../map-models';
 | 
					import { UnitedMapSettings } from '../map-models';
 | 
				
			||||||
import { aspectCache, parseFunction } from '@app/core/utils';
 | 
					import { aspectCache, parseFunction } from '@app/core/utils';
 | 
				
			||||||
import { Observable } from 'rxjs';
 | 
					import { Observable } from 'rxjs';
 | 
				
			||||||
import { skipLast, map, filter, switchMap } from 'rxjs/operators';
 | 
					import { map, filter } from 'rxjs/operators';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const maxZoom = 4;// ?
 | 
					const maxZoom = 4;// ?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -29,11 +29,13 @@ export class ImageMap extends LeafletMap {
 | 
				
			|||||||
    aspect = 0;
 | 
					    aspect = 0;
 | 
				
			||||||
    width = 0;
 | 
					    width = 0;
 | 
				
			||||||
    height = 0;
 | 
					    height = 0;
 | 
				
			||||||
 | 
					    imageUrl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor($container: HTMLElement, options: UnitedMapSettings) {
 | 
					    constructor($container: HTMLElement, options: UnitedMapSettings) {
 | 
				
			||||||
        super($container, options);
 | 
					        super($container, options);
 | 
				
			||||||
        options.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as ((rigXPos, origYPos) => { x, y });
 | 
					        options.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as ((rigXPos, origYPos) => { x, y });
 | 
				
			||||||
        aspectCache(options.mapUrl).subscribe(aspect => {
 | 
					        this.imageUrl = options.mapUrl;
 | 
				
			||||||
 | 
					        aspectCache(this.imageUrl).subscribe(aspect => {
 | 
				
			||||||
            this.aspect = aspect;
 | 
					            this.aspect = aspect;
 | 
				
			||||||
            this.onResize();
 | 
					            this.onResize();
 | 
				
			||||||
            super.setMap(this.map);
 | 
					            super.setMap(this.map);
 | 
				
			||||||
@ -43,9 +45,12 @@ export class ImageMap extends LeafletMap {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    setImageAlias(alias: Observable<any>) {
 | 
					    setImageAlias(alias: Observable<any>) {
 | 
				
			||||||
        alias.pipe(filter(result => result),
 | 
					        alias.pipe(filter(result => result),
 | 
				
			||||||
            map(subscription => subscription.data[1])).subscribe(res => {
 | 
					            filter(result => result), map(el => el[1])).subscribe(res => {
 | 
				
			||||||
                console.log("ImageMap -> setImageAlias -> res", res)
 | 
					                this.imageUrl = res;
 | 
				
			||||||
 | 
					                aspectCache(res).subscribe(aspect => {
 | 
				
			||||||
 | 
					                    this.aspect = aspect;
 | 
				
			||||||
 | 
					                    this.onResize(true);
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -64,8 +69,7 @@ export class ImageMap extends LeafletMap {
 | 
				
			|||||||
        if (this.imageOverlay) {
 | 
					        if (this.imageOverlay) {
 | 
				
			||||||
            this.imageOverlay.setBounds(bounds);
 | 
					            this.imageOverlay.setBounds(bounds);
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            this.imageOverlay = L.imageOverlay(this.options.mapUrl, bounds).addTo(this.map);
 | 
					            this.imageOverlay = L.imageOverlay(this.imageUrl, bounds).addTo(this.map);
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        const padding = 200 * maxZoom;
 | 
					        const padding = 200 * maxZoom;
 | 
				
			||||||
        southWest = this.pointToLatLng(-padding, h + padding);
 | 
					        southWest = this.pointToLatLng(-padding, h + padding);
 | 
				
			||||||
@ -127,7 +131,6 @@ export class ImageMap extends LeafletMap {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    convertPosition(expression): L.LatLng {
 | 
					    convertPosition(expression): L.LatLng {
 | 
				
			||||||
        console.log("ImageMap -> expression", expression)
 | 
					 | 
				
			||||||
        return this.pointToLatLng(
 | 
					        return this.pointToLatLng(
 | 
				
			||||||
            expression[this.options.xPosKeyName] * this.width,
 | 
					            expression[this.options.xPosKeyName] * this.width,
 | 
				
			||||||
            expression[this.options.yPosKeyName] * this.height);
 | 
					            expression[this.options.yPosKeyName] * this.height);
 | 
				
			||||||
 | 
				
			|||||||
@ -335,7 +335,7 @@ export const commonMapSettingsSchema =
 | 
				
			|||||||
            colorFunction: {
 | 
					            colorFunction: {
 | 
				
			||||||
                title: 'Color function: f(data, dsData, dsIndex)',
 | 
					                title: 'Color function: f(data, dsData, dsIndex)',
 | 
				
			||||||
                type: 'string'
 | 
					                type: 'string'
 | 
				
			||||||
            },            
 | 
					            },
 | 
				
			||||||
            markerImage: {
 | 
					            markerImage: {
 | 
				
			||||||
                title: 'Custom marker image',
 | 
					                title: 'Custom marker image',
 | 
				
			||||||
                type: 'string'
 | 
					                type: 'string'
 | 
				
			||||||
@ -434,7 +434,7 @@ export const commonMapSettingsSchema =
 | 
				
			|||||||
                    type: 'image'
 | 
					                    type: 'image'
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            ]
 | 
					            ]
 | 
				
			||||||
        }        
 | 
					        }
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -12,10 +12,6 @@
 | 
				
			|||||||
      "element",
 | 
					      "element",
 | 
				
			||||||
      "tb",
 | 
					      "tb",
 | 
				
			||||||
      "kebab-case"
 | 
					      "kebab-case"
 | 
				
			||||||
    ],
 | 
					    ]
 | 
				
			||||||
    "import-blacklist": [
 | 
					 | 
				
			||||||
      true,
 | 
					 | 
				
			||||||
      ["^.*/public-api$"]
 | 
					 | 
				
			||||||
  ]
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,8 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    "import-blacklist": [
 | 
					    "import-blacklist": [
 | 
				
			||||||
      true,
 | 
					      true,
 | 
				
			||||||
      "rxjs/Rx"
 | 
					      "rxjs/Rx",
 | 
				
			||||||
 | 
					      "^.*/public-api$"
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    "interface-name": false,
 | 
					    "interface-name": false,
 | 
				
			||||||
    "max-classes-per-file": false,
 | 
					    "max-classes-per-file": false,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user