Commit 79251adb3ae65e0dab93d8cd56533e561ac0caa1
1 parent
eda4e0f7
UI: Revert code for backward-compatible after having updated editors in maps widgets
Showing
3 changed files
with
97 additions
and
55 deletions
... | ... | @@ -31,7 +31,7 @@ import { |
31 | 31 | UnitedMapSettings |
32 | 32 | } from './map-models'; |
33 | 33 | import { Marker } from './markers'; |
34 | -import { forkJoin, Observable, of } from 'rxjs'; | |
34 | +import { Observable, of } from 'rxjs'; | |
35 | 35 | import { Polyline } from './polyline'; |
36 | 36 | import { Polygon } from './polygon'; |
37 | 37 | import { createTooltip } from '@home/components/widget/lib/maps/maps-utils'; |
... | ... | @@ -50,9 +50,6 @@ import { |
50 | 50 | SelectEntityDialogData |
51 | 51 | } from '@home/components/widget/lib/maps/dialogs/select-entity-dialog.component'; |
52 | 52 | import { MatDialog } from '@angular/material/dialog'; |
53 | -import { AttributeService } from '@core/http/attribute.service'; | |
54 | -import { EntityId } from '@shared/models/id/entity-id'; | |
55 | -import { AttributeScope, DataKeyType, LatestTelemetry } from '@shared/models/telemetry/telemetry.models'; | |
56 | 53 | |
57 | 54 | export default abstract class LeafletMap { |
58 | 55 | |
... | ... | @@ -85,6 +82,9 @@ export default abstract class LeafletMap { |
85 | 82 | southWest = new L.LatLng(-Projection.SphericalMercator['MAX_LATITUDE'], -180); |
86 | 83 | // tslint:disable-next-line:no-string-literal |
87 | 84 | northEast = new L.LatLng(Projection.SphericalMercator['MAX_LATITUDE'], 180); |
85 | + saveLocation: (e: FormattedData, values: {[key: string]: any}) => Observable<any>; | |
86 | + saveMarkerLocation: (e: FormattedData, lat?: number, lng?: number) => Observable<any>; | |
87 | + savePolygonLocation: (e: FormattedData, coordinates?: Array<any>) => Observable<any>; | |
88 | 88 | |
89 | 89 | protected constructor(public ctx: WidgetContext, |
90 | 90 | public $container: HTMLElement, |
... | ... | @@ -344,55 +344,6 @@ export default abstract class LeafletMap { |
344 | 344 | } |
345 | 345 | } |
346 | 346 | |
347 | - private saveLocation(e: FormattedData, values: {[key: string]: any}): Observable<any> { | |
348 | - const attributeService = this.ctx.$injector.get(AttributeService); | |
349 | - const attributes = []; | |
350 | - const timeseries = []; | |
351 | - | |
352 | - const entityId: EntityId = { | |
353 | - entityType: e.$datasource.entityType, | |
354 | - id: e.$datasource.entityId | |
355 | - }; | |
356 | - | |
357 | - for (const dataKeyName of Object.keys(values)) { | |
358 | - for (const key of e.$datasource.dataKeys) { | |
359 | - if (dataKeyName === key.name) { | |
360 | - const value = { | |
361 | - key: key.name, | |
362 | - value: values[dataKeyName] | |
363 | - }; | |
364 | - if (key.type === DataKeyType.attribute) { | |
365 | - attributes.push(value); | |
366 | - } else if (key.type === DataKeyType.timeseries) { | |
367 | - timeseries.push(value); | |
368 | - } | |
369 | - break; | |
370 | - } | |
371 | - } | |
372 | - } | |
373 | - | |
374 | - const observables: Observable<any>[] = []; | |
375 | - if (timeseries.length) { | |
376 | - observables.push(attributeService.saveEntityTimeseries( | |
377 | - entityId, | |
378 | - LatestTelemetry.LATEST_TELEMETRY, | |
379 | - timeseries | |
380 | - )); | |
381 | - } | |
382 | - if (attributes.length) { | |
383 | - observables.push(attributeService.saveEntityAttributes( | |
384 | - entityId, | |
385 | - AttributeScope.SERVER_SCOPE, | |
386 | - attributes | |
387 | - )); | |
388 | - } | |
389 | - if (observables.length) { | |
390 | - return forkJoin(observables); | |
391 | - } else { | |
392 | - return of(null); | |
393 | - } | |
394 | - } | |
395 | - | |
396 | 347 | createLatLng(lat: number, lng: number): L.LatLng { |
397 | 348 | return L.latLng(lat, lng); |
398 | 349 | } | ... | ... |
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -import { defaultSettings, hereProviders, MapProviders, UnitedMapSettings } from './map-models'; | |
17 | +import { defaultSettings, FormattedData, hereProviders, MapProviders, UnitedMapSettings } from './map-models'; | |
18 | 18 | import LeafletMap from './leaflet-map'; |
19 | 19 | import { |
20 | 20 | commonMapSettingsSchema, |
... | ... | @@ -32,6 +32,12 @@ import { TranslateService } from '@ngx-translate/core'; |
32 | 32 | import { UtilsService } from '@core/services/utils.service'; |
33 | 33 | import { EntityDataPageLink } from '@shared/models/query/query.models'; |
34 | 34 | import { providerClass } from '@home/components/widget/lib/maps/providers'; |
35 | +import { isDefined } from '@core/utils'; | |
36 | +import L from 'leaflet'; | |
37 | +import { forkJoin, Observable, of } from 'rxjs'; | |
38 | +import { AttributeService } from '@core/http/attribute.service'; | |
39 | +import { EntityId } from '@shared/models/id/entity-id'; | |
40 | +import { AttributeScope, DataKeyType, LatestTelemetry } from '@shared/models/telemetry/telemetry.models'; | |
35 | 41 | |
36 | 42 | // @dynamic |
37 | 43 | export class MapWidgetController implements MapWidgetInterface { |
... | ... | @@ -63,6 +69,10 @@ export class MapWidgetController implements MapWidgetInterface { |
63 | 69 | } |
64 | 70 | parseWithTranslation.setTranslate(this.translate); |
65 | 71 | this.map = new MapClass(this.ctx, $element, this.settings); |
72 | + (this.ctx as any).mapInstance = this.map; | |
73 | + this.map.saveMarkerLocation = this.setMarkerLocation; | |
74 | + this.map.savePolygonLocation = this.savePolygonLocation; | |
75 | + this.map.saveLocation = this.saveLocation; | |
66 | 76 | this.pageLink = { |
67 | 77 | page: 0, |
68 | 78 | pageSize: this.settings.mapPageSize, |
... | ... | @@ -158,6 +168,86 @@ export class MapWidgetController implements MapWidgetInterface { |
158 | 168 | }, entityName, null, entityLabel); |
159 | 169 | } |
160 | 170 | |
171 | + setMarkerLocation(e: FormattedData, lat?: number, lng?: number) { | |
172 | + let markerValue; | |
173 | + if (isDefined(lat) && isDefined(lng)) { | |
174 | + const point = lat != null && lng !== null ? L.latLng(lat, lng) : null; | |
175 | + markerValue = this.map.convertToCustomFormat(point); | |
176 | + } else if (this.settings.mapProvider !== MapProviders.image) { | |
177 | + markerValue = { | |
178 | + [this.settings.latKeyName]: e[this.settings.latKeyName], | |
179 | + [this.settings.lngKeyName]: e[this.settings.lngKeyName], | |
180 | + }; | |
181 | + } else { | |
182 | + markerValue = { | |
183 | + [this.settings.xPosKeyName]: e[this.settings.xPosKeyName], | |
184 | + [this.settings.yPosKeyName]: e[this.settings.yPosKeyName], | |
185 | + }; | |
186 | + } | |
187 | + return this.saveLocation(e, markerValue); | |
188 | + } | |
189 | + | |
190 | + savePolygonLocation(e: FormattedData, coordinates?: Array<any>) { | |
191 | + let polygonValue; | |
192 | + if (isDefined(coordinates)) { | |
193 | + polygonValue = this.map.convertToPolygonFormat(coordinates); | |
194 | + } else { | |
195 | + polygonValue = { | |
196 | + [this.settings.polygonKeyName]: e[this.settings.polygonKeyName] | |
197 | + }; | |
198 | + } | |
199 | + return this.saveLocation(e, polygonValue); | |
200 | + } | |
201 | + | |
202 | + saveLocation(e: FormattedData, values: {[key: string]: any}): Observable<any> { | |
203 | + const attributeService = this.ctx.$injector.get(AttributeService); | |
204 | + const attributes = []; | |
205 | + const timeseries = []; | |
206 | + | |
207 | + const entityId: EntityId = { | |
208 | + entityType: e.$datasource.entityType, | |
209 | + id: e.$datasource.entityId | |
210 | + }; | |
211 | + | |
212 | + for (const dataKeyName of Object.keys(values)) { | |
213 | + for (const key of e.$datasource.dataKeys) { | |
214 | + if (dataKeyName === key.name) { | |
215 | + const value = { | |
216 | + key: key.name, | |
217 | + value: values[dataKeyName] | |
218 | + }; | |
219 | + if (key.type === DataKeyType.attribute) { | |
220 | + attributes.push(value); | |
221 | + } else if (key.type === DataKeyType.timeseries) { | |
222 | + timeseries.push(value); | |
223 | + } | |
224 | + break; | |
225 | + } | |
226 | + } | |
227 | + } | |
228 | + | |
229 | + const observables: Observable<any>[] = []; | |
230 | + if (timeseries.length) { | |
231 | + observables.push(attributeService.saveEntityTimeseries( | |
232 | + entityId, | |
233 | + LatestTelemetry.LATEST_TELEMETRY, | |
234 | + timeseries | |
235 | + )); | |
236 | + } | |
237 | + if (attributes.length) { | |
238 | + observables.push(attributeService.saveEntityAttributes( | |
239 | + entityId, | |
240 | + AttributeScope.SERVER_SCOPE, | |
241 | + attributes | |
242 | + )); | |
243 | + } | |
244 | + if (observables.length) { | |
245 | + return forkJoin(observables); | |
246 | + } else { | |
247 | + return of(null); | |
248 | + } | |
249 | + } | |
250 | + | |
161 | 251 | initSettings(settings: UnitedMapSettings, isEditMap?: boolean): UnitedMapSettings { |
162 | 252 | const functionParams = ['data', 'dsData', 'dsIndex']; |
163 | 253 | this.provider = settings.provider || this.mapProvider; |
... | ... | @@ -209,6 +299,7 @@ export class MapWidgetController implements MapWidgetInterface { |
209 | 299 | } |
210 | 300 | |
211 | 301 | destroy() { |
302 | + (this.ctx as any).mapInstance = null; | |
212 | 303 | if (this.map) { |
213 | 304 | this.map.remove(); |
214 | 305 | } | ... | ... |
... | ... | @@ -6444,7 +6444,7 @@ leaflet-rotatedmarker@^0.2.0: |
6444 | 6444 | resolved "https://registry.yarnpkg.com/leaflet-rotatedmarker/-/leaflet-rotatedmarker-0.2.0.tgz#4467f49f98d1bfd56959bd9c6705203dd2601277" |
6445 | 6445 | integrity sha1-RGf0n5jRv9VpWb2cZwUgPdJgEnc= |
6446 | 6446 | |
6447 | -leaflet.gridlayer.googlemutant@0.13.4: | |
6447 | +leaflet.gridlayer.googlemutant@^0.13.4: | |
6448 | 6448 | version "0.13.4" |
6449 | 6449 | resolved "https://registry.yarnpkg.com/leaflet.gridlayer.googlemutant/-/leaflet.gridlayer.googlemutant-0.13.4.tgz#0add37d240c70c999e1f1d341208e6fea2372c40" |
6450 | 6450 | integrity sha512-oC6xUSFJ9HP4WIupXakgiYckdBHuHQeSaxTXsVlcvcpfsuYoJ/HFIrz1bmK4Qr/qKO4fY1MDM6AoewU7Bph8ZQ== | ... | ... |