@regionerne/gis-komponent 0.0.60 → 0.0.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -446,105 +446,117 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
446
446
 
447
447
  class LayoutService {
448
448
  _map;
449
+ mapResizedSubject = new Subject();
449
450
  set map(value) {
450
451
  this._map = value;
451
452
  }
452
- calculateWidgetPosition({ initialPosition, widgetName, widgetWidth, widgetHeight, offsetX = 2, offsetY = 2, }) {
453
+ keepWidgetInViewPort(dragPosition, widgetName, widgetHeight, widgetWidth, resizedContainerHeight = null, resizedContainerWidth = null) {
454
+ //Expanding or changing map size, make sure the widget stays in viewport
455
+ const widgetPositionOptions = {
456
+ initialPosition: '',
457
+ widgetName: widgetName,
458
+ widgetHeight: widgetHeight,
459
+ widgetWidth: widgetWidth,
460
+ currentPosition: dragPosition,
461
+ resizedContainerHeight: resizedContainerHeight,
462
+ resizedContainerWidth: resizedContainerWidth
463
+ };
464
+ return this.calculateWidgetPosition(widgetPositionOptions);
465
+ }
466
+ calculateWidgetPosition({ initialPosition, widgetName, widgetWidth, widgetHeight, offsetX = 2, offsetY = 9, currentPosition = null, resizedContainerHeight = null, resizedContainerWidth = null }) {
453
467
  let x = 0;
454
468
  let y = 0;
455
469
  let dragPosition = { x: x, y: y };
456
470
  if (!this._map)
457
471
  return dragPosition;
458
472
  const containerRect = this._map.getViewport().getBoundingClientRect();
459
- let vertical = 'top';
460
- let horizontal = 'left';
461
- switch (initialPosition) {
462
- case 'øverst/venstre':
463
- vertical = 'top';
464
- horizontal = 'left';
465
- break;
466
- case 'midt/venstre':
467
- vertical = 'middle';
468
- horizontal = 'left';
469
- break;
470
- case 'nederst/venstre':
471
- vertical = 'bottom';
472
- horizontal = 'left';
473
- break;
474
- case 'øverst/midt':
475
- vertical = 'top';
476
- horizontal = 'middle';
477
- break;
478
- case 'nederst/midt':
479
- vertical = 'bottom';
480
- horizontal = 'middle';
481
- break;
482
- case 'øverst/højre':
483
- vertical = 'top';
484
- horizontal = 'right';
485
- break;
486
- case 'midt/højre':
487
- vertical = 'middle';
488
- horizontal = 'right';
489
- break;
490
- case 'nederst/højre':
491
- vertical = 'bottom';
492
- horizontal = 'right';
493
- break;
494
- }
495
- console.log('calculateWidgetPosition', initialPosition, widgetName, this._map, this._map.getViewport(), widgetWidth, widgetHeight, containerRect, vertical, horizontal);
496
- // Vertical positioning
497
- switch (vertical) {
498
- case 'top':
499
- y = offsetY;
500
- break;
501
- case 'middle':
502
- y = (containerRect.height - widgetHeight) / 2;
503
- break;
504
- case 'bottom':
505
- if (horizontal === 'left')
506
- offsetY = offsetY + 90; // Move above scalebar in bottom-left corner
507
- y = containerRect.height - widgetHeight - offsetY;
508
- break;
473
+ if (currentPosition) {
474
+ // Expanding a widget or viewport changed size, so fit the widget inside view again
475
+ x = currentPosition.x;
476
+ y = currentPosition.y;
477
+ if (resizedContainerHeight && resizedContainerWidth) {
478
+ containerRect.height = resizedContainerHeight;
479
+ containerRect.width = resizedContainerWidth;
480
+ }
509
481
  }
510
- // Horizontal positioning
511
- switch (horizontal) {
512
- case 'left':
513
- if (vertical === 'top')
514
- offsetX = offsetX + 35; // Move to right of zoom in top-left corner
515
- x = offsetX;
516
- break;
517
- case 'middle':
518
- x = (containerRect.width - widgetWidth) / 2;
519
- break;
520
- case 'right':
521
- if (vertical === 'top')
522
- offsetX = offsetX + 35; // Move to left of compass in top-right corner
523
- x = containerRect.width - widgetWidth - offsetX;
524
- break;
482
+ else {
483
+ let vertical = 'top';
484
+ let horizontal = 'left';
485
+ switch (initialPosition) {
486
+ case 'øverst/venstre':
487
+ vertical = 'top';
488
+ horizontal = 'left';
489
+ break;
490
+ case 'midt/venstre':
491
+ vertical = 'middle';
492
+ horizontal = 'left';
493
+ break;
494
+ case 'nederst/venstre':
495
+ vertical = 'bottom';
496
+ horizontal = 'left';
497
+ break;
498
+ case 'øverst/midt':
499
+ vertical = 'top';
500
+ horizontal = 'middle';
501
+ break;
502
+ case 'nederst/midt':
503
+ vertical = 'bottom';
504
+ horizontal = 'middle';
505
+ break;
506
+ case 'øverst/højre':
507
+ vertical = 'top';
508
+ horizontal = 'right';
509
+ break;
510
+ case 'midt/højre':
511
+ vertical = 'middle';
512
+ horizontal = 'right';
513
+ break;
514
+ case 'nederst/højre':
515
+ vertical = 'bottom';
516
+ horizontal = 'right';
517
+ break;
518
+ default: break;
519
+ }
520
+ // Vertical positioning
521
+ switch (vertical) {
522
+ case 'top':
523
+ y = offsetY;
524
+ break;
525
+ case 'middle':
526
+ y = (containerRect.height - widgetHeight) / 2;
527
+ break;
528
+ case 'bottom':
529
+ if (horizontal === 'left')
530
+ offsetY = offsetY + 90; // Move above scalebar in bottom-left corner
531
+ y = containerRect.height - widgetHeight - offsetY;
532
+ break;
533
+ }
534
+ // Horizontal positioning
535
+ switch (horizontal) {
536
+ case 'left':
537
+ if (vertical === 'top')
538
+ offsetX = offsetX + 35; // Move to right of zoom in top-left corner
539
+ x = offsetX;
540
+ break;
541
+ case 'middle':
542
+ x = (containerRect.width - widgetWidth) / 2;
543
+ break;
544
+ case 'right':
545
+ if (vertical === 'top')
546
+ offsetX = offsetX + 35; // Move to left of compass in top-right corner
547
+ x = containerRect.width - widgetWidth - offsetX;
548
+ break;
549
+ }
525
550
  }
551
+ console.log('Ensure the widget stays inside the viewport', containerRect, containerRect.width - widgetWidth, x, containerRect.height - widgetHeight, y);
526
552
  // Ensure the widget stays inside the viewport
527
- x = Math.max(-containerRect.x, Math.min(x, containerRect.width - widgetWidth));
528
- y = Math.max(-containerRect.y, Math.min(y, containerRect.height - widgetHeight));
553
+ x = Math.max(offsetX, Math.min(x, containerRect.width - widgetWidth));
554
+ y = Math.max(offsetY, Math.min(y, containerRect.height - widgetHeight));
529
555
  dragPosition = { x: x, y: y };
530
556
  console.log('calculateWidgetPosition end ', dragPosition);
531
557
  this._savePosition(widgetName, dragPosition);
532
558
  return { x, y };
533
559
  }
534
- bringElementIntoViewIfNeeded(elementClass, offsetValue, collapsed) {
535
- const element = document.querySelector(elementClass);
536
- if (!element)
537
- return;
538
- const left = parseInt(element.style.left || '0', 10);
539
- if (collapsed) {
540
- // Widget minimized, remove the style for left
541
- element.style.left = '0em';
542
- }
543
- else {
544
- // If widget expands outside screen on the right (left is > <offsetValue> em), then bring it back
545
- element.style.left = `${left > offsetValue ? offsetValue : left}em`;
546
- }
547
- }
548
560
  _savePosition(widgetStorageKey, position) {
549
561
  try {
550
562
  localStorage.setItem(widgetStorageKey, JSON.stringify(position));
@@ -810,6 +822,31 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.15", ngImpo
810
822
  type: Injectable
811
823
  }], ctorParameters: () => [{ type: OlCapabilitiesService }] });
812
824
 
825
+ class WidgetConstants {
826
+ static collapsedHeight = 24;
827
+ static collapsedWidth = 86;
828
+ static toolboxHeight = 64;
829
+ static toolboxWidth = 729;
830
+ static searchHeight = 122;
831
+ static searchWidth = 374;
832
+ static activeObjectsHeight = 80;
833
+ static activeObjectsWidth = 350;
834
+ static layerSelectorHeight = 209;
835
+ static layerSelectorWidth = 329;
836
+ static legendsHeight = 341;
837
+ static legendsWidth = 296;
838
+ static toolboxDefaultX = 29;
839
+ static toolboxDefaultY = 120;
840
+ static searchDefaultX = 29;
841
+ static searchDefaultY = 5;
842
+ static activeObjectsDefaultX = 29;
843
+ static activeObjectsDefaultY = 238;
844
+ static layerSelectorDefaultX = 29;
845
+ static layerSelectorDefaultY = 470;
846
+ static legendsDefaultX = 1790;
847
+ static legendsDefaultY = 743;
848
+ }
849
+
813
850
  class LayerSelectorComponent {
814
851
  set contentBody(content) {
815
852
  this._layerSelectorBody = content;
@@ -1073,8 +1110,9 @@ class LayerSelectorComponent {
1073
1110
  this.searchText = '';
1074
1111
  this.filterChanged();
1075
1112
  }
1076
- if (this.profile.layerSelectorInitialPosition.includes('højre')) {
1077
- this._layoutService.bringElementIntoViewIfNeeded('.layer-selector-body-wrapper', -13, this.collapsed);
1113
+ if (!this.collapsed) {
1114
+ //Expanding, make sure it stays in viewport
1115
+ this.layerSelectorDragPosition = this._layoutService.keepWidgetInViewPort(this.layerSelectorDragPosition, this.POSITION_STORAGE_KEY, WidgetConstants.layerSelectorHeight, WidgetConstants.layerSelectorWidth);
1078
1116
  }
1079
1117
  }
1080
1118
  updateOpacity(layerId, opacity) {
@@ -1175,12 +1213,12 @@ class LayerSelectorComponent {
1175
1213
  _loadPosition(collapsed) {
1176
1214
  try {
1177
1215
  // Default height and width when collapsed
1178
- let widgetHeight = 24;
1179
- let widgetWidth = 86;
1216
+ let widgetHeight = WidgetConstants.collapsedHeight;
1217
+ let widgetWidth = WidgetConstants.collapsedWidth;
1180
1218
  if (!collapsed) {
1181
1219
  // Custom height and width when expanded
1182
- widgetHeight = 209;
1183
- widgetWidth = 329;
1220
+ widgetHeight = WidgetConstants.layerSelectorHeight;
1221
+ widgetWidth = WidgetConstants.layerSelectorWidth;
1184
1222
  }
1185
1223
  const widgetPositionOptions = {
1186
1224
  initialPosition: this.profile.layerSelectorInitialPosition,
@@ -1202,7 +1240,7 @@ class LayerSelectorComponent {
1202
1240
  }
1203
1241
  else {
1204
1242
  // Default position for layer selector
1205
- this.layerSelectorDragPosition = { x: 29, y: 370 };
1243
+ this.layerSelectorDragPosition = { x: WidgetConstants.layerSelectorDefaultX, y: WidgetConstants.layerSelectorDefaultY };
1206
1244
  this._savePosition(this.layerSelectorDragPosition);
1207
1245
  }
1208
1246
  }
@@ -1751,6 +1789,9 @@ class MergeFeaturesService {
1751
1789
  if (this._featureHelper.isLocked(f)) {
1752
1790
  return false;
1753
1791
  }
1792
+ if (this._featureHelper.typeId(f) !== typeId) {
1793
+ return false;
1794
+ }
1754
1795
  if (this._selectedMergeFeature) {
1755
1796
  const previusFeatureObject = this.formatter.writeFeatureObject(this._selectedMergeFeature, this._formatterOptions);
1756
1797
  const bufferedPreviouslySelected = buffer(previusFeatureObject, 5, { units: 'centimeters' });
@@ -2479,7 +2520,6 @@ class ShowDocumentInfoService {
2479
2520
  const geom = evt.feature.getGeometry();
2480
2521
  this._documentSearch.search({ kind: 'polygon', value: geom }, 100).subscribe({
2481
2522
  next: result => {
2482
- console.log("🚀 ~ ShowDocumentInfoService ~ _startByPolygon ~ result:", result);
2483
2523
  this._features.next(result);
2484
2524
  }
2485
2525
  });
@@ -3533,25 +3573,18 @@ class ToolboxComponent {
3533
3573
  this.activeMode = 'edit';
3534
3574
  const modify = new Modify({
3535
3575
  source: this._drawLayerService.source,
3536
- condition: evt => {
3537
- // first, get all features from the draw-layer
3538
- const feature = this.map.forEachFeatureAtPixel(evt.pixel, f => f, { layerFilter: l => l == this._drawLayerService.layer });
3539
- if (!feature) {
3540
- return false;
3541
- }
3542
- return !this._featureHelper.isLocked(feature);
3576
+ filter: (f) => {
3577
+ return !this._featureHelper.isLocked(f);
3543
3578
  },
3544
- // No delete
3545
3579
  deleteCondition: () => false,
3546
3580
  // Allow moving existing and add new points
3547
- // condition: always,
3581
+ // condition: always,
3548
3582
  insertVertexCondition: always,
3549
3583
  });
3550
3584
  /* Modify fires changes to features a LOT, so to not flood the UndoRedo service, I disable until ending the modify
3551
3585
  and then force an update, to add the updated feature to the undo-service. */
3552
3586
  modify.on('modifystart', () => this._undoRedo.disable());
3553
3587
  modify.on('modifyend', (evt) => {
3554
- console.log("🚀 ~ ToolboxComponent ~ startEdit ~ evt:", evt);
3555
3588
  this._undoRedo.enable();
3556
3589
  evt.features.forEach(f => {
3557
3590
  f.set('updated', new Date().toISOString());
@@ -3572,7 +3605,7 @@ class ToolboxComponent {
3572
3605
  idsToExcludeFromOverlap.push(`${feature.getId()}`); // Don't check these for overlap
3573
3606
  this._drawLayerService.source.addFeature(feature);
3574
3607
  });
3575
- // Don't check for overlap with the feature being updated.
3608
+ // Don't check for overlap with the feature being updated.
3576
3609
  this._overlap.handleOverlaps(result, idsToExcludeFromOverlap).pipe(filter(f => !!f)).subscribe({
3577
3610
  next: f => {
3578
3611
  if (f) {
@@ -3783,6 +3816,10 @@ class ToolboxComponent {
3783
3816
  ngOnInit() {
3784
3817
  this._originalMapHeight = this.map.getSize()[1];
3785
3818
  this._originalMapWidth = this.map.getSize()[0];
3819
+ this._layoutService.mapResizedSubject.subscribe(mapResized => {
3820
+ //Map resized, make sure it stays in viewport
3821
+ this.dragPosition = this._layoutService.keepWidgetInViewPort(this.dragPosition, this._POSITION_STORAGE_KEY, WidgetConstants.toolboxHeight, WidgetConstants.toolboxWidth, this.mapHeight, this.mapWidth);
3822
+ });
3786
3823
  this.drawItems = [];
3787
3824
  (this.settings.geometryTypeSettings ?? []).filter(f => f.availableGeometryTypes).forEach(geomSetting => {
3788
3825
  geomSetting.availableGeometryTypes.forEach(geomType => {
@@ -3919,12 +3956,12 @@ class ToolboxComponent {
3919
3956
  _loadPosition(collapsed) {
3920
3957
  try {
3921
3958
  // Default height and width when collapsed
3922
- let widgetHeight = 24;
3923
- let widgetWidth = 86;
3959
+ let widgetHeight = WidgetConstants.collapsedHeight;
3960
+ let widgetWidth = WidgetConstants.collapsedWidth;
3924
3961
  if (!collapsed) {
3925
3962
  // Custom height and width when expanded
3926
- widgetHeight = 64;
3927
- widgetWidth = 729;
3963
+ widgetHeight = WidgetConstants.toolboxHeight;
3964
+ widgetWidth = WidgetConstants.toolboxWidth;
3928
3965
  }
3929
3966
  const container = this.map.getViewport();
3930
3967
  const widgetPositionOptions = {
@@ -3947,7 +3984,7 @@ class ToolboxComponent {
3947
3984
  }
3948
3985
  else {
3949
3986
  // Default position for toolbox
3950
- this.dragPosition = { x: 29, y: 26 };
3987
+ this.dragPosition = { x: WidgetConstants.toolboxDefaultX, y: WidgetConstants.toolboxDefaultY };
3951
3988
  this._savePosition();
3952
3989
  }
3953
3990
  }
@@ -3976,7 +4013,7 @@ class ToolboxComponent {
3976
4013
  return;
3977
4014
  }
3978
4015
  const changeTypeSelect = new Select$1({
3979
- // layers: [this._drawLayer!],
4016
+ // layers: [this._drawLayer!],
3980
4017
  layers: [this._drawLayerService.layer],
3981
4018
  filter: f => !this._featureHelper.isLocked(f) && this._featureHelper.typeId(f) !== this.selectedDrawItem?.typeId // can't changed locked and cant change to same type
3982
4019
  });
@@ -4010,8 +4047,9 @@ class ToolboxComponent {
4010
4047
  this.stopMeasureArea();
4011
4048
  this.stopMeasureLength();
4012
4049
  }
4013
- if (this.profile.toolboxInitialPosition.includes('højre')) {
4014
- this._layoutService.bringElementIntoViewIfNeeded('.toolbox-wrapper', -33, this.collapsed);
4050
+ if (!this.collapsed) {
4051
+ //Expanding, make sure it stays in viewport
4052
+ this.dragPosition = this._layoutService.keepWidgetInViewPort(this.dragPosition, this._POSITION_STORAGE_KEY, WidgetConstants.toolboxHeight, WidgetConstants.toolboxWidth);
4015
4053
  }
4016
4054
  }
4017
4055
  startMeasureArea() {
@@ -4081,15 +4119,11 @@ class ToolboxComponent {
4081
4119
  }
4082
4120
  }
4083
4121
  setNewMapDimensions() {
4122
+ this._layoutService.mapResizedSubject.next(true);
4084
4123
  this.map.getTargetElement().style.width = this.mapWidth + 'px';
4085
4124
  this.map.getTargetElement().style.height = this.mapHeight + 'px';
4086
- if (this.mapWidth < 1920 && this.profile.toolboxInitialPosition.includes('højre')) {
4087
- const offset = this.mapWidth <= 800 ? 80 : (this.mapWidth <= 1280 ? 40 :
4088
- (this.mapWidth <= 1680 ? 20 : 0));
4089
- //Map got smaller, push Toolbox to the left
4090
- this._layoutService.bringElementIntoViewIfNeeded('.toolbox-wrapper', -offset, this.collapsed);
4091
- }
4092
4125
  this.map.updateSize();
4126
+ this._layoutService.map = this.map;
4093
4127
  }
4094
4128
  doPrint() {
4095
4129
  let htmlElement = this.map.getViewport();
@@ -4373,7 +4407,6 @@ class ActiveObjectsComponent {
4373
4407
  });
4374
4408
  this._featuresForHighlight$.subscribe({
4375
4409
  next: features => {
4376
- console.log("🚀 ~ ActiveObjectsComponent ~ constructor ~ features:", features);
4377
4410
  this._highlightFromMap(features.map(feature => feature.getId()));
4378
4411
  }
4379
4412
  });
@@ -4468,8 +4501,9 @@ class ActiveObjectsComponent {
4468
4501
  }
4469
4502
  togglePanel() {
4470
4503
  this.collapsed = !this.collapsed;
4471
- if (this.profile.activeObjectsInitialPosition.includes('højre')) {
4472
- this._layoutService.bringElementIntoViewIfNeeded('.active-objects-wrapper', -15, this.collapsed);
4504
+ if (!this.collapsed) {
4505
+ //Expanding, make sure it stays in viewport
4506
+ this.dragPosition = this._layoutService.keepWidgetInViewPort(this.dragPosition, this.POSITION_STORAGE_KEY, WidgetConstants.activeObjectsHeight, WidgetConstants.activeObjectsWidth);
4473
4507
  }
4474
4508
  }
4475
4509
  onDragEnded(event) {
@@ -4488,12 +4522,12 @@ class ActiveObjectsComponent {
4488
4522
  _loadPosition(collapsed) {
4489
4523
  try {
4490
4524
  // Default height and width when collapsed
4491
- let widgetHeight = 24;
4492
- let widgetWidth = 86;
4525
+ let widgetHeight = WidgetConstants.collapsedHeight;
4526
+ let widgetWidth = WidgetConstants.collapsedWidth;
4493
4527
  if (!collapsed) {
4494
4528
  // Custom height and width when expanded
4495
- widgetHeight = 80;
4496
- widgetWidth = 350;
4529
+ widgetHeight = WidgetConstants.activeObjectsHeight;
4530
+ widgetWidth = WidgetConstants.activeObjectsWidth;
4497
4531
  }
4498
4532
  const widgetPositionOptions = {
4499
4533
  initialPosition: this.profile.activeObjectsInitialPosition,
@@ -4515,7 +4549,7 @@ class ActiveObjectsComponent {
4515
4549
  }
4516
4550
  else {
4517
4551
  // Default position for active objects
4518
- this.dragPosition = { x: 29, y: 238 }; // TO DO - fix these everywhere
4552
+ this.dragPosition = { x: WidgetConstants.activeObjectsDefaultX, y: WidgetConstants.activeObjectsDefaultY };
4519
4553
  this._savePosition(this.dragPosition);
4520
4554
  }
4521
4555
  }
@@ -4649,9 +4683,6 @@ class MapSearchComponent {
4649
4683
  if (changes['profile'] && this.profile) {
4650
4684
  this.collapsed = this.profile.searchFolded;
4651
4685
  this._loadPosition(this.collapsed);
4652
- if (this.profile.searchInitialPosition?.includes('højre')) {
4653
- this._layoutService.bringElementIntoViewIfNeeded('.search-container', -3, this.collapsed);
4654
- }
4655
4686
  this._addWFSSearchLayers();
4656
4687
  }
4657
4688
  }
@@ -4702,8 +4733,9 @@ class MapSearchComponent {
4702
4733
  this.searchAddress = '';
4703
4734
  this.filterResults();
4704
4735
  }
4705
- if (this.profile.searchInitialPosition?.includes('højre')) {
4706
- this._layoutService.bringElementIntoViewIfNeeded('.search-container', -3, this.collapsed);
4736
+ if (!this.collapsed) {
4737
+ //Expanding, make sure it stays in viewport
4738
+ this.dragPosition = this._layoutService.keepWidgetInViewPort(this.dragPosition, this.POSITION_STORAGE_KEY, WidgetConstants.searchHeight, WidgetConstants.searchWidth);
4707
4739
  }
4708
4740
  }
4709
4741
  highlight(wkt, event) {
@@ -4739,12 +4771,12 @@ class MapSearchComponent {
4739
4771
  _loadPosition(collapsed) {
4740
4772
  try {
4741
4773
  // Default height and width when collapsed
4742
- let widgetHeight = 24;
4743
- let widgetWidth = 86;
4774
+ let widgetHeight = WidgetConstants.collapsedHeight;
4775
+ let widgetWidth = WidgetConstants.collapsedWidth;
4744
4776
  if (!collapsed) {
4745
4777
  // Custom height and width when expanded
4746
- widgetHeight = 122;
4747
- widgetWidth = 374;
4778
+ widgetHeight = WidgetConstants.searchHeight;
4779
+ widgetWidth = WidgetConstants.searchWidth;
4748
4780
  }
4749
4781
  const widgetPositionOptions = {
4750
4782
  initialPosition: this.profile.searchInitialPosition,
@@ -4766,7 +4798,7 @@ class MapSearchComponent {
4766
4798
  }
4767
4799
  else {
4768
4800
  // Default position for search
4769
- this.dragPosition = { x: 29, y: -125 };
4801
+ this.dragPosition = { x: WidgetConstants.searchDefaultX, y: WidgetConstants.searchDefaultY };
4770
4802
  this._savePosition(this.dragPosition);
4771
4803
  }
4772
4804
  }
@@ -4835,9 +4867,6 @@ class LegendsListComponent {
4835
4867
  if (changes['profile'] && this.profile) {
4836
4868
  this.collapsed = this.profile.legendsListFolded;
4837
4869
  this._loadPosition(this.collapsed);
4838
- if (this.profile.legendsListInitialPosition.includes('højre')) {
4839
- this._layoutService.bringElementIntoViewIfNeeded('.legends-list-body-wrapper', -12, this.collapsed);
4840
- }
4841
4870
  this._setFilteredLegends().subscribe(result => this.filteredLayersDetailed = result);
4842
4871
  }
4843
4872
  }
@@ -4848,8 +4877,9 @@ class LegendsListComponent {
4848
4877
  }
4849
4878
  toggleLegendsList() {
4850
4879
  this.collapsed = !this.collapsed;
4851
- if (this.profile.legendsListInitialPosition.includes('højre')) {
4852
- this._layoutService.bringElementIntoViewIfNeeded('.legends-list-body-wrapper', -12, this.collapsed);
4880
+ if (!this.collapsed) {
4881
+ //Expanding, make sure it stays in viewport
4882
+ this.dragPosition = this._layoutService.keepWidgetInViewPort(this.dragPosition, this.POSITION_STORAGE_KEY, WidgetConstants.legendsHeight, WidgetConstants.legendsWidth);
4853
4883
  }
4854
4884
  }
4855
4885
  onDragEnded(event) {
@@ -4871,12 +4901,12 @@ class LegendsListComponent {
4871
4901
  _loadPosition(collapsed) {
4872
4902
  try {
4873
4903
  // Default height and width when collapsed
4874
- let widgetHeight = 24;
4875
- let widgetWidth = 86;
4904
+ let widgetHeight = WidgetConstants.collapsedHeight;
4905
+ let widgetWidth = WidgetConstants.collapsedWidth;
4876
4906
  if (!collapsed) {
4877
4907
  // Custom height and width when expanded
4878
- widgetHeight = 341;
4879
- widgetWidth = 296;
4908
+ widgetHeight = WidgetConstants.legendsHeight;
4909
+ widgetWidth = WidgetConstants.legendsWidth;
4880
4910
  }
4881
4911
  const widgetPositionOptions = {
4882
4912
  initialPosition: this.profile.legendsListInitialPosition,
@@ -4898,7 +4928,7 @@ class LegendsListComponent {
4898
4928
  }
4899
4929
  else {
4900
4930
  // Default position for legends list
4901
- this.dragPosition = { x: 1753, y: 531 };
4931
+ this.dragPosition = { x: WidgetConstants.legendsDefaultX, y: WidgetConstants.legendsDefaultY };
4902
4932
  this._savePosition(this.dragPosition);
4903
4933
  }
4904
4934
  }