Browse Source

UI: Map - add map scale control.

pull/12866/head
Igor Kulikov 2 years ago
parent
commit
880ab02743
  1. 8
      ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts
  2. 8
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html
  3. 11
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts
  4. 16
      ui-ngx/src/app/shared/models/widget/maps/map.models.ts
  5. 3
      ui-ngx/src/assets/locale/locale.constant-en_US.json

8
ui-ngx/src/app/modules/home/components/widget/lib/maps/map.ts

@ -20,6 +20,7 @@ import {
DataKeyValuePair, DataKeyValuePair,
MapBooleanFunction, MapBooleanFunction,
mapDataLayerTypes, mapDataLayerTypes,
MapScale,
MapType, MapType,
mergeMapDatasources, mergeMapDatasources,
parseCenterPosition, parseCenterPosition,
@ -171,7 +172,12 @@ export abstract class TbMap<S extends BaseMapSettings> {
} }
private setupControls(): Observable<any> { private setupControls(): Observable<any> {
//L.control.scale().addTo(this.map); if (this.settings.scales?.length) {
L.control.scale({
metric: this.settings.scales.includes(MapScale.metric),
imperial: this.settings.scales.includes(MapScale.imperial)
}).addTo(this.map);
}
if (this.map.zoomControl) { if (this.map.zoomControl) {
this.map.zoomControl.setPosition(this.settings.controlsPosition); this.map.zoomControl.setPosition(this.settings.controlsPosition);
} }

8
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.html

@ -99,6 +99,14 @@
</mat-chip-option> </mat-chip-option>
</mat-chip-listbox> </mat-chip-listbox>
</div> </div>
<div class="tb-form-row space-between column-lt-md">
<div translate>widgets.maps.control.scale</div>
<mat-chip-listbox multiple formControlName="scales">
<mat-chip-option *ngFor="let scale of mapScales" [value]="scale">
{{ mapScaleTranslationMap.get(scale) | translate }}
</mat-chip-option>
</mat-chip-listbox>
</div>
<div *ngIf="showDragButtonModeButtonSettings" class="tb-form-row"> <div *ngIf="showDragButtonModeButtonSettings" class="tb-form-row">
<mat-slide-toggle class="mat-slide" formControlName="dragModeButton"> <mat-slide-toggle class="mat-slide" formControlName="dragModeButton">
{{ 'widgets.maps.control.switch-to-drag-mode-using-button' | translate }} {{ 'widgets.maps.control.switch-to-drag-mode-using-button' | translate }}

11
ui-ngx/src/app/modules/home/components/widget/lib/settings/common/map/map-settings.component.ts

@ -33,7 +33,7 @@ import {
mapControlPositions, mapControlPositions,
mapControlsPositionTranslationMap, mapControlsPositionTranslationMap,
MapDataLayerSettings, MapDataLayerSettings,
MapDataLayerType, MapDataLayerType, mapScales, mapScaleTranslationMap,
MapSetting, MapSetting,
MapType, MapType,
mapZoomActions, mapZoomActions,
@ -74,12 +74,16 @@ export class MapSettingsComponent implements OnInit, ControlValueAccessor, Valid
mapControlPositions = mapControlPositions; mapControlPositions = mapControlPositions;
mapZoomActions = mapZoomActions;
mapControlsPositionTranslationMap = mapControlsPositionTranslationMap; mapControlsPositionTranslationMap = mapControlsPositionTranslationMap;
mapZoomActions = mapZoomActions;
mapZoomActionTranslationMap = mapZoomActionTranslationMap; mapZoomActionTranslationMap = mapZoomActionTranslationMap;
mapScales = mapScales;
mapScaleTranslationMap = mapScaleTranslationMap;
MapType = MapType; MapType = MapType;
@Input() @Input()
@ -144,6 +148,7 @@ export class MapSettingsComponent implements OnInit, ControlValueAccessor, Valid
additionalDataSources: [null, []], additionalDataSources: [null, []],
controlsPosition: [null, []], controlsPosition: [null, []],
zoomActions: [null, []], zoomActions: [null, []],
scales: [null, []],
dragModeButton: [null, []], dragModeButton: [null, []],
fitMapBounds: [null, []], fitMapBounds: [null, []],
useDefaultCenterPosition: [null, []], useDefaultCenterPosition: [null, []],

16
ui-ngx/src/app/shared/models/widget/maps/map.models.ts

@ -640,6 +640,20 @@ export const mapZoomActionTranslationMap = new Map<MapZoomAction, string>(
] ]
); );
export enum MapScale {
metric = 'metric',
imperial = 'imperial'
}
export const mapScales = Object.keys(MapScale) as MapScale[];
export const mapScaleTranslationMap = new Map<MapScale, string>(
[
[MapScale.metric, 'widgets.maps.control.scale-metric'],
[MapScale.imperial, 'widgets.maps.control.scale-imperial'],
]
);
export interface MapActionButtonSettings { export interface MapActionButtonSettings {
label?: string; label?: string;
icon?: string; icon?: string;
@ -666,6 +680,7 @@ export interface BaseMapSettings {
additionalDataSources: AdditionalMapDataSourceSettings[]; additionalDataSources: AdditionalMapDataSourceSettings[];
controlsPosition: MapControlsPosition; controlsPosition: MapControlsPosition;
zoomActions: MapZoomAction[]; zoomActions: MapZoomAction[];
scales: MapScale[];
dragModeButton: boolean; dragModeButton: boolean;
fitMapBounds: boolean; fitMapBounds: boolean;
useDefaultCenterPosition: boolean; useDefaultCenterPosition: boolean;
@ -689,6 +704,7 @@ export const defaultBaseMapSettings: BaseMapSettings = {
additionalDataSources: [], additionalDataSources: [],
controlsPosition: MapControlsPosition.topleft, controlsPosition: MapControlsPosition.topleft,
zoomActions: [MapZoomAction.scroll, MapZoomAction.doubleClick, MapZoomAction.controlButtons], zoomActions: [MapZoomAction.scroll, MapZoomAction.doubleClick, MapZoomAction.controlButtons],
scales: [],
dragModeButton: false, dragModeButton: false,
fitMapBounds: true, fitMapBounds: true,
useDefaultCenterPosition: false, useDefaultCenterPosition: false,

3
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -7705,6 +7705,9 @@
"zoom-scroll": "Scroll", "zoom-scroll": "Scroll",
"zoom-double-click": "Double click", "zoom-double-click": "Double click",
"zoom-control-buttons": "Control buttons", "zoom-control-buttons": "Control buttons",
"scale": "Scale",
"scale-metric": "Metric",
"scale-imperial": "Imperial",
"switch-to-drag-mode-using-button": "Switch to drag mode using button" "switch-to-drag-mode-using-button": "Switch to drag mode using button"
}, },
"timeline": { "timeline": {

Loading…
Cancel
Save