From 557b0642b89fa5ae0188fbb8843a13ccd53ca445 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 28 Jul 2020 13:06:14 +0300 Subject: [PATCH] Added setting pageSize for a map, deleted deprecated map provider and fix creating a markers --- .../components/widget/lib/maps/leaflet-map.ts | 7 ++++--- .../home/components/widget/lib/maps/map-models.ts | 6 ++++-- .../components/widget/lib/maps/map-widget2.ts | 2 +- .../widget/lib/maps/providers/image-map.ts | 15 ++++++++++----- .../home/components/widget/lib/maps/schemes.ts | 12 ++++++++---- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts index 69226317ce..743bea73ac 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet-map.ts @@ -42,7 +42,7 @@ import { Polygon } from './polygon'; import { createTooltip, parseArray, safeExecute } from '@home/components/widget/lib/maps/maps-utils'; import { WidgetContext } from '@home/models/widget-component.models'; import { DatasourceData } from '@shared/models/widget.models'; -import { deepClone } from '@core/utils'; +import { deepClone, isDefinedAndNotNull } from '@core/utils'; export default abstract class LeafletMap { @@ -249,8 +249,9 @@ export default abstract class LeafletMap { if (!expression) return null; const lat = expression[this.options.latKeyName]; const lng = expression[this.options.lngKeyName]; - if (isNaN(lat) || isNaN(lng)) - return null; + if (!isDefinedAndNotNull(lat) || isNaN(lat) || !isDefinedAndNotNull(lng) || isNaN(lng)){ + return null; + } else return L.latLng(lat, lng) as L.LatLng; } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-models.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-models.ts index 46b7634811..cff22e1181 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-models.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-models.ts @@ -25,7 +25,7 @@ import { } from './schemes'; import { EntityType } from '@shared/models/entity-type.models'; -export const DEFAULT_MAP_PAGE_SIZE = 1024; +export const DEFAULT_MAP_PAGE_SIZE = 2 ** 14; export type GenericFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string; export type MarkerImageFunction = (data: FormattedData, dsData: FormattedData[], dsIndex: number) => string; @@ -68,6 +68,7 @@ export type MapSettings = { removeOutsideVisibleBounds: boolean, useCustomProvider: boolean, customProviderTileUrl: string; + mapPageSize: number; } export enum MapProviders { @@ -267,7 +268,8 @@ export const defaultSettings: any = { credentials: '', markerClusteringSetting: null, draggableMarker: false, - fitMapBounds: true + fitMapBounds: true, + mapPageSize: DEFAULT_MAP_PAGE_SIZE }; export const hereProviders = [ diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts index 99c22eeb6e..fd06598fb3 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/map-widget2.ts @@ -81,7 +81,7 @@ export class MapWidgetController implements MapWidgetInterface { this.map.saveMarkerLocation = this.setMarkerLocation; this.pageLink = { page: 0, - pageSize: DEFAULT_MAP_PAGE_SIZE, + pageSize: this.settings.mapPageSize, textSearch: null, dynamic: true }; diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts index b4f5726c32..b8c0a9c82e 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/providers/image-map.ts @@ -24,6 +24,7 @@ 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'; +import { isDefinedAndNotNull } from '@core/utils'; const maxZoom = 4;// ? @@ -209,11 +210,15 @@ export class ImageMap extends LeafletMap { } convertPosition(expression): L.LatLng { - if (isNaN(expression[this.options.xPosKeyName]) || isNaN(expression[this.options.yPosKeyName])) return null; - Object.assign(expression, this.posFunction(expression[this.options.xPosKeyName], expression[this.options.yPosKeyName])); - return this.pointToLatLng( - expression.x * this.width, - expression.y * this.height); + const xPos = expression[this.options.xPosKeyName]; + const yPos = expression[this.options.yPosKeyName]; + if (!isDefinedAndNotNull(xPos) || isNaN(xPos) || !isDefinedAndNotNull(yPos) || isNaN(yPos)) { + return null; + } + Object.assign(expression, this.posFunction(xPos, yPos)); + return this.pointToLatLng( + expression.x * this.width, + expression.y * this.height); } convertPositionPolygon(expression: Array<[number, number]>): L.LatLngExpression[] { diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/maps/schemes.ts b/ui-ngx/src/app/modules/home/components/widget/lib/maps/schemes.ts index b8d953394a..73445707bf 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/maps/schemes.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/maps/schemes.ts @@ -14,6 +14,8 @@ /// limitations under the License. /// +import { DEFAULT_MAP_PAGE_SIZE } from '@home/components/widget/lib/maps/map-models'; + export const googleMapSettingsSchema = { schema: { @@ -197,10 +199,6 @@ export const openstreetMapSettingsSchema = value: 'OpenStreetMap.Mapnik', label: 'OpenStreetMap.Mapnik (Default)' }, - { - value: 'OpenStreetMap.BlackAndWhite', - label: 'OpenStreetMap.BlackAndWhite' - }, { value: 'OpenStreetMap.HOT', label: 'OpenStreetMap.HOT' @@ -246,6 +244,11 @@ export const commonMapSettingsSchema = type: 'boolean', default: false }, + mapPageSize: { + title: 'Map page size load entities', + type: 'number', + default: DEFAULT_MAP_PAGE_SIZE + }, defaultCenterPosition: { title: 'Default map center position (0,0)', type: 'string', @@ -408,6 +411,7 @@ export const commonMapSettingsSchema = key: 'fitMapBounds', condition: 'model.provider !== "image-map"' }, + 'mapPageSize', 'draggableMarker', { key: 'disableScrollZooming',