@sedoo/unidoo 0.1.71 → 0.1.73

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.
@@ -28,7 +28,7 @@ import "ol-ext/dist/ol-ext.css";
28
28
  import {
29
29
  Select,
30
30
  DragRotateAndZoom,
31
- defaults as defaultInteractions,
31
+ defaults as defaultInteractions
32
32
  } from "ol/interaction";
33
33
  import { click, pointerMove } from "ol/events/condition";
34
34
  import { FullScreen } from "ol/control";
@@ -61,52 +61,52 @@ export default {
61
61
  content_title: null,
62
62
  popupArray: [],
63
63
  popupTitleArray: [],
64
- fullscreenToggled: false, // property to track fullscreen state
64
+ fullscreenToggled: false // property to track fullscreen state
65
65
  };
66
66
  },
67
67
  props: {
68
68
  title: {
69
69
  type: String,
70
- default: "Component Unidoo MapGeoFeatures",
70
+ default: "Component Unidoo MapGeoFeatures"
71
71
  },
72
72
  colorTitle: {
73
73
  type: String,
74
- default: "#3f4a75",
74
+ default: "#3f4a75"
75
75
  },
76
76
  colorFeature: {
77
77
  type: String,
78
- default: "green",
78
+ default: "green"
79
79
  },
80
80
  colorOfSelectedFeature: {
81
81
  type: String,
82
- default: "blue",
82
+ default: "blue"
83
83
  },
84
84
  serviceUrl: {
85
85
  type: String,
86
- required: true,
86
+ required: true
87
87
  },
88
88
  bannedKeys: {
89
89
  type: String,
90
90
  default: () => {
91
91
  return "geometry,origin,interval,source,technicalId,externalLinkPrefix,externalLink,UTC_time,altitude";
92
- },
92
+ }
93
93
  },
94
94
  shapeStylePoint: {
95
95
  type: String,
96
- default: "circle",
96
+ default: "circle"
97
97
  },
98
98
  disablePopupProperties: {
99
99
  type: String,
100
- default: "false",
100
+ default: "false"
101
101
  },
102
102
  noTitleInPopupWithOneFeature: {
103
103
  type: String,
104
- default: "true",
104
+ default: "true"
105
105
  },
106
106
  isRotationShapeStylePoint: {
107
107
  type: String,
108
- default: "false",
109
- },
108
+ default: "false"
109
+ }
110
110
  },
111
111
  computed: {
112
112
  maxPopupHeight() {
@@ -116,7 +116,7 @@ export default {
116
116
  return this.calculateMaxPopupHeight();
117
117
  }
118
118
  return this.calculateMaxPopupHeight();
119
- },
119
+ }
120
120
  },
121
121
 
122
122
  created() {
@@ -151,13 +151,13 @@ export default {
151
151
  if (newVal !== oldVal && newVal !== undefined) {
152
152
  this.loadFeatures();
153
153
  }
154
- },
154
+ }
155
155
  },
156
156
  fullscreenToggled(newValue, oldValue) {
157
157
  if (newValue !== oldValue) {
158
158
  this.maxPopupHeight = this.calculateMaxPopupHeight();
159
159
  }
160
- },
160
+ }
161
161
  },
162
162
 
163
163
  methods: {
@@ -176,11 +176,13 @@ export default {
176
176
  },
177
177
 
178
178
  beforeDestroy() {
179
- window.removeEventListener("resize", this.handleResize);
180
- document.removeEventListener(
181
- "fullscreenchange",
182
- this.handleFullscreenChange
183
- );
179
+ if (typeof window !== "undefined") {
180
+ window.removeEventListener("resize", this.handleResize);
181
+ document.removeEventListener(
182
+ "fullscreenchange",
183
+ this.handleFullscreenChange
184
+ );
185
+ }
184
186
  },
185
187
 
186
188
  rotationInRadians(featureRotation) {
@@ -204,67 +206,71 @@ export default {
204
206
  * @param {string} [integrity] - The integrity hash of the stylesheet for subresource integrity checking. Optional.
205
207
  */
206
208
  addStylesheet(href, integrity = "") {
207
- // Check if the stylesheet already exists
208
- const existingLink = document.querySelector(`link[href="${href}"]`);
209
-
210
- if (!existingLink) {
211
- const link = document.createElement("link");
212
- link.href = href;
213
- link.rel = "stylesheet";
214
- link.crossOrigin = "anonymous";
215
- if (integrity) {
216
- link.integrity = integrity;
209
+ if (typeof document !== "undefined") {
210
+ // Check if the stylesheet already exists
211
+ const existingLink = document.querySelector(`link[href="${href}"]`);
212
+
213
+ if (!existingLink) {
214
+ const link = document.createElement("link");
215
+ link.href = href;
216
+ link.rel = "stylesheet";
217
+ link.crossOrigin = "anonymous";
218
+ if (integrity) {
219
+ link.integrity = integrity;
220
+ }
221
+ document.head.appendChild(link);
217
222
  }
218
- document.head.appendChild(link);
219
223
  }
220
224
  },
221
225
 
222
226
  loadFeatures() {
223
- this.infoLog("Loading features...");
227
+ if (typeof window !== "undefined") {
228
+ this.infoLog("Loading features...");
224
229
 
225
- if (this.popupArray && this.popupArray.length > 0) {
226
- // Close the popup if it is already open before loading new features.
227
- this.closePopup();
228
- }
230
+ if (this.popupArray && this.popupArray.length > 0) {
231
+ // Close the popup if it is already open before loading new features.
232
+ this.closePopup();
233
+ }
229
234
 
230
- if (this.popupTitleArray && this.popupTitleArray.length > 0) {
231
- // Close the popup title if it is already open before loading new features.
232
- this.closePopupTitle();
233
- }
235
+ if (this.popupTitleArray && this.popupTitleArray.length > 0) {
236
+ // Close the popup title if it is already open before loading new features.
237
+ this.closePopupTitle();
238
+ }
234
239
 
235
- this.axios
236
- .get(this.serviceUrl)
237
- .then((res) => {
238
- if (typeof res.data === "object") {
239
- // Your existing code...
240
- const geoJsonObject = res.data;
241
- geoJsonObject.crs = {
242
- type: "name",
243
- properties: {
244
- name: "EPSG:3857",
245
- },
246
- };
247
- this.geoJsonObject = geoJsonObject;
248
- if (geoJsonObject.features && geoJsonObject.features.length > 0) {
249
- this.updateMapFeatures(geoJsonObject);
240
+ this.axios
241
+ .get(this.serviceUrl)
242
+ .then((res) => {
243
+ if (typeof res.data === "object") {
244
+ // Your existing code...
245
+ const geoJsonObject = res.data;
246
+ geoJsonObject.crs = {
247
+ type: "name",
248
+ properties: {
249
+ name: "EPSG:3857"
250
+ }
251
+ };
252
+ this.geoJsonObject = geoJsonObject;
253
+ if (geoJsonObject.features && geoJsonObject.features.length > 0) {
254
+ this.updateMapFeatures(geoJsonObject);
255
+ } else {
256
+ this.warnLog(
257
+ "loadFeatures() : No features found in geoJsonObject ! :",
258
+ geoJsonObject
259
+ );
260
+ }
261
+ // fix the problem of the map loading the first time the component UnidooMapGepFeatures is loaded in a project (e.g. iagos-frontend-custom-elements)
262
+ this.$nextTick(() => {
263
+ // $nextTick is a Vue method that allows you to access the DOM after the next update cycle. This is useful here to make sure that the map is resized after the features are loaded.
264
+ window.dispatchEvent(new Event("resize")); // force the map to be resized after the features are loaded (ref : https://intranet.sedoo.fr/astuces-openlayers/)
265
+ });
250
266
  } else {
251
- this.warnLog(
252
- "loadFeatures() : No features found in geoJsonObject ! :",
253
- geoJsonObject
254
- );
267
+ this.errorLog("API response is not an object:", res.data);
255
268
  }
256
- // fix the problem of the map loading the first time the component UnidooMapGepFeatures is loaded in a project (e.g. iagos-frontend-custom-elements)
257
- this.$nextTick(() => {
258
- // $nextTick is a Vue method that allows you to access the DOM after the next update cycle. This is useful here to make sure that the map is resized after the features are loaded.
259
- window.dispatchEvent(new Event("resize")); // force the map to be resized after the features are loaded (ref : https://intranet.sedoo.fr/astuces-openlayers/)
260
- });
261
- } else {
262
- this.errorLog("API response is not an object:", res.data);
263
- }
264
- })
265
- .catch((error) => {
266
- this.errorLog("API request error:", error);
267
- });
269
+ })
270
+ .catch((error) => {
271
+ this.errorLog("API request error:", error);
272
+ });
273
+ }
268
274
  },
269
275
 
270
276
  initMap() {
@@ -274,25 +280,25 @@ export default {
274
280
  LineString: new Style({
275
281
  stroke: new Stroke({
276
282
  color: this.colorFeature,
277
- width: 2,
278
- }),
283
+ width: 2
284
+ })
279
285
  }),
280
286
  /* For SAFIRE */
281
287
  MultiLineString: new Style({
282
288
  stroke: new Stroke({
283
289
  color: this.colorFeature,
284
- width: 1,
285
- }),
290
+ width: 1
291
+ })
286
292
  }),
287
293
  Polygon: new Style({
288
294
  stroke: new Stroke({
289
295
  color: this.colorFeature,
290
- width: 3,
296
+ width: 3
291
297
  }),
292
298
  fill: new Fill({
293
- color: "rgba(0, 0, 255, 0.1)",
294
- }),
295
- }),
299
+ color: "rgba(0, 0, 255, 0.1)"
300
+ })
301
+ })
296
302
  };
297
303
 
298
304
  this.styles = styles;
@@ -301,25 +307,25 @@ export default {
301
307
  LineString: new Style({
302
308
  stroke: new Stroke({
303
309
  color: this.colorOfSelectedFeature,
304
- width: 2,
305
- }),
310
+ width: 2
311
+ })
306
312
  }),
307
313
  /* For SAFIRE */
308
314
  MultiLineString: new Style({
309
315
  stroke: new Stroke({
310
316
  color: this.colorOfSelectedFeature,
311
- width: 1,
312
- }),
317
+ width: 1
318
+ })
313
319
  }),
314
320
  Polygon: new Style({
315
321
  stroke: new Stroke({
316
322
  color: this.colorOfSelectedFeature,
317
- width: 3,
323
+ width: 3
318
324
  }),
319
325
  fill: new Fill({
320
- color: "rgba(0, 0, 255, 0.1)",
321
- }),
322
- }),
326
+ color: "rgba(0, 0, 255, 0.1)"
327
+ })
328
+ })
323
329
  };
324
330
 
325
331
  this.selectedStyle = selectedStyle;
@@ -329,7 +335,7 @@ export default {
329
335
 
330
336
  const vectorLayer = new VectorLayer({
331
337
  source: this.vectorSource,
332
- style: this.styleFunction,
338
+ style: this.styleFunction
333
339
  });
334
340
 
335
341
  // this is where we create the OpenLayers map
@@ -341,9 +347,9 @@ export default {
341
347
  layers: [
342
348
  // adding a background tiled layer
343
349
  new TileLayer({
344
- source: new OSM(), // tiles are served by OpenStreetMap
350
+ source: new OSM() // tiles are served by OpenStreetMap
345
351
  }),
346
- vectorLayer,
352
+ vectorLayer
347
353
  ],
348
354
  // overlays: [this.popupOverlay],
349
355
  // the map view will initially show the whole world
@@ -351,23 +357,25 @@ export default {
351
357
  zoom: 0,
352
358
  center: [0, 0],
353
359
  constrainResolution: false,
354
- projection: "EPSG:3857",
355
- }),
360
+ projection: "EPSG:3857"
361
+ })
356
362
  });
357
363
 
358
364
  const fullscreen = new FullScreen();
359
365
  this.map.addControl(fullscreen);
360
366
 
361
- // Listen for changes in fullscreen state
362
- document.addEventListener(
363
- "fullscreenchange",
364
- this.handleFullscreenChange
365
- );
367
+ if (typeof document !== "undefined") {
368
+ // Listen for changes in fullscreen state
369
+ document.addEventListener(
370
+ "fullscreenchange",
371
+ this.handleFullscreenChange
372
+ );
373
+ }
366
374
 
367
375
  // add select interaction to change the color of a selected feature
368
376
  this.selectInteraction = new Select({
369
377
  condition: click,
370
- style: this.selectedStyleFunction,
378
+ style: this.selectedStyleFunction
371
379
  });
372
380
 
373
381
  this.map.addInteraction(this.selectInteraction);
@@ -375,7 +383,7 @@ export default {
375
383
  // add hover interaction to show that a feature is selectable (change the color style)
376
384
  this.hoverInteraction = new Select({
377
385
  condition: pointerMove,
378
- style: this.selectedStyleFunction,
386
+ style: this.selectedStyleFunction
379
387
  });
380
388
 
381
389
  this.map.addInteraction(this.hoverInteraction);
@@ -396,7 +404,7 @@ export default {
396
404
 
397
405
  const geoJson = new GeoJSON({
398
406
  dataProjection: "EPSG:4326",
399
- featureProjection: "EPSG:3857",
407
+ featureProjection: "EPSG:3857"
400
408
  });
401
409
 
402
410
  const features = geoJsonObject.features;
@@ -411,7 +419,7 @@ export default {
411
419
  const batch = features.slice(i, i + batchSize);
412
420
  const featureCollection = {
413
421
  type: "FeatureCollection",
414
- features: batch,
422
+ features: batch
415
423
  };
416
424
  // Convert a collection of GeoJSON features to OpenLayers feature.
417
425
  const olFeatures = geoJson.readFeatures(featureCollection);
@@ -437,7 +445,7 @@ export default {
437
445
  this.map.getView().fit(this.vectorSource.getExtent(), {
438
446
  duration: 500, // Optional: smooth transition
439
447
  padding: [100, 100, 100, 100], // Optional: padding around the features
440
- maxZoom: 16, // Prevents zooming in too closely
448
+ maxZoom: 16 // Prevents zooming in too closely
441
449
  });
442
450
  } else {
443
451
  this.warnLog(
@@ -492,85 +500,85 @@ export default {
492
500
  imageStyle = new CircleStyle({
493
501
  radius: 5,
494
502
  fill: new Fill({
495
- color: fillColor,
503
+ color: fillColor
496
504
  }),
497
505
  stroke: new Stroke({
498
506
  color: color,
499
- width: 1,
500
- }),
507
+ width: 1
508
+ })
501
509
  });
502
510
  } else if (this.shapeStylePoint === "triangle") {
503
511
  imageStyle = new RegularShape({
504
512
  fill: new Fill({
505
- color: fillColor,
513
+ color: fillColor
506
514
  }),
507
515
  stroke: new Stroke({
508
516
  color: color,
509
- width: 1,
517
+ width: 1
510
518
  }),
511
519
  points: 3,
512
520
  radius: 10,
513
521
  angle: 0,
514
- rotation: this.rotationInRadians(featureRotation),
522
+ rotation: this.rotationInRadians(featureRotation)
515
523
  });
516
524
  } else if (this.shapeStylePoint === "square") {
517
525
  imageStyle = new RegularShape({
518
526
  fill: new Fill({
519
- color: fillColor,
527
+ color: fillColor
520
528
  }),
521
529
  stroke: new Stroke({
522
530
  color: color,
523
- width: 1,
531
+ width: 1
524
532
  }),
525
533
  points: 4,
526
534
  radius: 10,
527
535
  angle: Math.PI / 4,
528
- rotation: this.rotationInRadians(featureRotation),
536
+ rotation: this.rotationInRadians(featureRotation)
529
537
  });
530
538
  } else if (this.shapeStylePoint === "star") {
531
539
  imageStyle = new RegularShape({
532
540
  fill: new Fill({
533
- color: fillColor,
541
+ color: fillColor
534
542
  }),
535
543
  stroke: new Stroke({
536
544
  color: color,
537
- width: 1,
545
+ width: 1
538
546
  }),
539
547
  points: 5,
540
548
  radius: 10,
541
549
  radius2: 4,
542
550
  angle: 0,
543
- rotation: this.rotationInRadians(featureRotation),
551
+ rotation: this.rotationInRadians(featureRotation)
544
552
  });
545
553
  } else if (this.shapeStylePoint === "cross") {
546
554
  imageStyle = new RegularShape({
547
555
  fill: new Fill({
548
- color: fillColor,
556
+ color: fillColor
549
557
  }),
550
558
  stroke: new Stroke({
551
559
  color: color,
552
- width: 2,
560
+ width: 2
553
561
  }),
554
562
  points: 4,
555
563
  radius: 10,
556
564
  radius2: 0,
557
565
  angle: 0,
558
- rotation: this.rotationInRadians(featureRotation),
566
+ rotation: this.rotationInRadians(featureRotation)
559
567
  });
560
568
  } else if (this.shapeStylePoint === "x") {
561
569
  imageStyle = new RegularShape({
562
570
  fill: new Fill({
563
- color: fillColor,
571
+ color: fillColor
564
572
  }),
565
573
  stroke: new Stroke({
566
574
  color: color,
567
- width: 2,
575
+ width: 2
568
576
  }),
569
577
  points: 4,
570
578
  radius: 10,
571
579
  radius2: 0,
572
580
  angle: Math.PI / 4,
573
- rotation: this.rotationInRadians(featureRotation),
581
+ rotation: this.rotationInRadians(featureRotation)
574
582
  });
575
583
  } else if (this.shapeStylePoint.startsWith("fontawesome:")) {
576
584
  // Check if shapeStylePoint starts with 'fontawesome:' and then parse the string to get the icon name
@@ -581,13 +589,13 @@ export default {
581
589
  text: String.fromCharCode(iconUnicode), // Convert the Unicode number of tto a character to display the icon (e.g., '\uf3c5')
582
590
  font: "normal 36px FontAwesome",
583
591
  fill: new Fill({
584
- color: fillColor,
592
+ color: fillColor
585
593
  }),
586
594
  stroke: new Stroke({
587
595
  color: color,
588
- width: 1,
596
+ width: 1
589
597
  }),
590
- rotation: this.rotationInRadians(featureRotation),
598
+ rotation: this.rotationInRadians(featureRotation)
591
599
  });
592
600
  } else if (this.shapeStylePoint.startsWith("material:")) {
593
601
  // Check if shapeStylePoint starts with 'material:' and then parse the string to get the icon name
@@ -596,13 +604,13 @@ export default {
596
604
  text: iconName, // Use the parsed icon name here
597
605
  font: "normal 44px Material Icons",
598
606
  fill: new Fill({
599
- color: fillColor,
607
+ color: fillColor
600
608
  }),
601
609
  stroke: new Stroke({
602
610
  color: color,
603
- width: 1,
611
+ width: 1
604
612
  }),
605
- rotation: this.rotationInRadians(featureRotation),
613
+ rotation: this.rotationInRadians(featureRotation)
606
614
  });
607
615
  } else {
608
616
  this.errorLog(
@@ -614,7 +622,7 @@ export default {
614
622
 
615
623
  return new Style({
616
624
  image: imageStyle,
617
- text: textStyle,
625
+ text: textStyle
618
626
  });
619
627
  },
620
628
 
@@ -656,8 +664,8 @@ export default {
656
664
  closeBox: true,
657
665
  autoPan: true, // Activate the map centering on the popup
658
666
  autoPanAnimation: {
659
- duration: 250, // Duration of the map moving animation
660
- },
667
+ duration: 250 // Duration of the map moving animation
668
+ }
661
669
  });
662
670
  this.popupArray.push(popup);
663
671
 
@@ -984,8 +992,8 @@ export default {
984
992
  closeBox: false,
985
993
  autoPan: true, // Activate the map centering on the popup
986
994
  autoPanAnimation: {
987
- duration: 250, // Duration of the map moving animation
988
- },
995
+ duration: 250 // Duration of the map moving animation
996
+ }
989
997
  });
990
998
  this.popupTitleArray.push(popupTitle);
991
999
 
@@ -996,8 +1004,8 @@ export default {
996
1004
  popupTitle.show(positionfromLonLat, `<div>${feature.title}</div>`);
997
1005
  }
998
1006
  });
999
- },
1000
- },
1007
+ }
1008
+ }
1001
1009
  };
1002
1010
  </script>
1003
1011