|
|
@ -14,12 +14,16 @@ |
|
|
/// limitations under the License.
|
|
|
/// limitations under the License.
|
|
|
///
|
|
|
///
|
|
|
|
|
|
|
|
|
import L, { LatLngLiteral, LatLngBounds, LatLngTuple } from 'leaflet'; |
|
|
import L, { LatLngBounds, LatLngLiteral, LatLngTuple } from 'leaflet'; |
|
|
import LeafletMap from '../leaflet-map'; |
|
|
import LeafletMap from '../leaflet-map'; |
|
|
import { UnitedMapSettings, PosFuncton } from '../map-models'; |
|
|
import { MapImage, PosFuncton, UnitedMapSettings } from '../map-models'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable, ReplaySubject } from 'rxjs'; |
|
|
import { map, filter, switchMap } from 'rxjs/operators'; |
|
|
import { filter, map, mergeMap } from 'rxjs/operators'; |
|
|
import { aspectCache, calculateNewPointCoordinate, parseFunction } from '@home/components/widget/lib/maps/maps-utils'; |
|
|
import { aspectCache, calculateNewPointCoordinate, parseFunction } from '@home/components/widget/lib/maps/maps-utils'; |
|
|
|
|
|
import { WidgetContext } from '@home/models/widget-component.models'; |
|
|
|
|
|
import { DataSet, DatasourceType, widgetType } from '@shared/models/widget.models'; |
|
|
|
|
|
import { DataKeyType } from '@shared/models/telemetry/telemetry.models'; |
|
|
|
|
|
import { WidgetSubscriptionOptions } from '@core/api/widget-api.models'; |
|
|
|
|
|
|
|
|
const maxZoom = 4;// ?
|
|
|
const maxZoom = 4;// ?
|
|
|
|
|
|
|
|
|
@ -32,26 +36,96 @@ export class ImageMap extends LeafletMap { |
|
|
imageUrl: string; |
|
|
imageUrl: string; |
|
|
posFunction: PosFuncton; |
|
|
posFunction: PosFuncton; |
|
|
|
|
|
|
|
|
constructor($container: HTMLElement, options: UnitedMapSettings) { |
|
|
constructor(ctx: WidgetContext, $container: HTMLElement, options: UnitedMapSettings) { |
|
|
super($container, options); |
|
|
super(ctx, $container, options); |
|
|
this.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as PosFuncton; |
|
|
this.posFunction = parseFunction(options.posFunction, ['origXPos', 'origYPos']) as PosFuncton; |
|
|
this.imageUrl = options.mapUrl; |
|
|
this.mapImage(options).subscribe((mapImage) => { |
|
|
aspectCache(this.imageUrl).subscribe(aspect => { |
|
|
this.imageUrl = mapImage.imageUrl; |
|
|
this.aspect = aspect; |
|
|
this.aspect = mapImage.aspect; |
|
|
|
|
|
if (mapImage.update) { |
|
|
|
|
|
this.onResize(true); |
|
|
|
|
|
} else { |
|
|
this.onResize(); |
|
|
this.onResize(); |
|
|
super.setMap(this.map); |
|
|
super.setMap(this.map); |
|
|
super.initSettings(options); |
|
|
super.initSettings(options); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setImageAlias(alias: Observable<any>) { |
|
|
private mapImage(options: UnitedMapSettings): Observable<MapImage> { |
|
|
alias.pipe(filter(result => result), map(el => el[1]), switchMap(res => { |
|
|
const imageEntityAlias = options.imageEntityAlias; |
|
|
this.imageUrl = res; |
|
|
const imageUrlAttribute = options.imageUrlAttribute; |
|
|
return aspectCache(res); |
|
|
if (!imageEntityAlias || !imageUrlAttribute) { |
|
|
})).subscribe(aspect => { |
|
|
return this.imageFromUrl(options.mapUrl); |
|
|
this.aspect = aspect; |
|
|
} |
|
|
this.onResize(true); |
|
|
const entityAliasId = this.ctx.aliasController.getEntityAliasId(imageEntityAlias); |
|
|
}); |
|
|
if (!entityAliasId) { |
|
|
|
|
|
return this.imageFromUrl(options.mapUrl); |
|
|
|
|
|
} |
|
|
|
|
|
const datasources = [ |
|
|
|
|
|
{ |
|
|
|
|
|
type: DatasourceType.entity, |
|
|
|
|
|
name: imageEntityAlias, |
|
|
|
|
|
aliasName: imageEntityAlias, |
|
|
|
|
|
entityAliasId, |
|
|
|
|
|
dataKeys: [ |
|
|
|
|
|
{ |
|
|
|
|
|
type: DataKeyType.attribute, |
|
|
|
|
|
name: imageUrlAttribute, |
|
|
|
|
|
label: imageUrlAttribute, |
|
|
|
|
|
settings: {}, |
|
|
|
|
|
_hash: Math.random() |
|
|
|
|
|
} |
|
|
|
|
|
] |
|
|
|
|
|
} |
|
|
|
|
|
]; |
|
|
|
|
|
const result = new ReplaySubject<[DataSet, boolean]>(); |
|
|
|
|
|
let isUpdate = false; |
|
|
|
|
|
const imageUrlSubscriptionOptions: WidgetSubscriptionOptions = { |
|
|
|
|
|
datasources, |
|
|
|
|
|
useDashboardTimewindow: false, |
|
|
|
|
|
type: widgetType.latest, |
|
|
|
|
|
callbacks: { |
|
|
|
|
|
onDataUpdated: (subscription) => { |
|
|
|
|
|
result.next([subscription.data[0]?.data, isUpdate]); |
|
|
|
|
|
isUpdate = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
this.ctx.subscriptionApi.createSubscription(imageUrlSubscriptionOptions, true).subscribe(() => { }); |
|
|
|
|
|
return this.imageFromAlias(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private imageFromUrl(url: string): Observable<MapImage> { |
|
|
|
|
|
return aspectCache(url).pipe( |
|
|
|
|
|
map( aspect => { |
|
|
|
|
|
const mapImage: MapImage = { |
|
|
|
|
|
imageUrl: url, |
|
|
|
|
|
aspect, |
|
|
|
|
|
update: false |
|
|
|
|
|
}; |
|
|
|
|
|
return mapImage; |
|
|
|
|
|
} |
|
|
|
|
|
)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private imageFromAlias(alias: Observable<[DataSet, boolean]>): Observable<MapImage> { |
|
|
|
|
|
return alias.pipe( |
|
|
|
|
|
filter(result => result[0].length > 0), |
|
|
|
|
|
mergeMap(res => { |
|
|
|
|
|
const mapImage: MapImage = { |
|
|
|
|
|
imageUrl: res[0][0][1], |
|
|
|
|
|
aspect: null, |
|
|
|
|
|
update: res[1] |
|
|
|
|
|
}; |
|
|
|
|
|
return aspectCache(mapImage.imageUrl).pipe( |
|
|
|
|
|
map((aspect) => { |
|
|
|
|
|
mapImage.aspect = aspect; |
|
|
|
|
|
return mapImage; |
|
|
|
|
|
} |
|
|
|
|
|
)); |
|
|
|
|
|
}) |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updateBounds(updateImage?: boolean, lastCenterPos?) { |
|
|
updateBounds(updateImage?: boolean, lastCenterPos?) { |
|
|
|