aur-openlayers 19.6.5 → 19.6.6

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.
package/README.md CHANGED
@@ -1,63 +1,63 @@
1
- # Lib
2
-
3
- This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.0.
4
-
5
- ## Code scaffolding
6
-
7
- Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
-
9
- ```bash
10
- ng generate component component-name
11
- ```
12
-
13
- For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
-
15
- ```bash
16
- ng generate --help
17
- ```
18
-
19
- ## Building
20
-
21
- To build the library, run:
22
-
23
- ```bash
24
- ng build lib
25
- ```
26
-
27
- This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
-
29
- ### Publishing the Library
30
-
31
- Once the project is built, you can publish your library by following these steps:
32
-
33
- 1. Navigate to the `dist` directory:
34
- ```bash
35
- cd dist/lib
36
- ```
37
-
38
- 2. Run the `npm publish` command to publish your library to the npm registry:
39
- ```bash
40
- npm publish
41
- ```
42
-
43
- ## Running unit tests
44
-
45
- To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
46
-
47
- ```bash
48
- ng test
49
- ```
50
-
51
- ## Running end-to-end tests
52
-
53
- For end-to-end (e2e) testing, run:
54
-
55
- ```bash
56
- ng e2e
57
- ```
58
-
59
- Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
60
-
61
- ## Additional Resources
62
-
63
- For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
1
+ # Lib
2
+
3
+ This project was generated using [Angular CLI](https://github.com/angular/angular-cli) version 19.2.0.
4
+
5
+ ## Code scaffolding
6
+
7
+ Angular CLI includes powerful code scaffolding tools. To generate a new component, run:
8
+
9
+ ```bash
10
+ ng generate component component-name
11
+ ```
12
+
13
+ For a complete list of available schematics (such as `components`, `directives`, or `pipes`), run:
14
+
15
+ ```bash
16
+ ng generate --help
17
+ ```
18
+
19
+ ## Building
20
+
21
+ To build the library, run:
22
+
23
+ ```bash
24
+ ng build lib
25
+ ```
26
+
27
+ This command will compile your project, and the build artifacts will be placed in the `dist/` directory.
28
+
29
+ ### Publishing the Library
30
+
31
+ Once the project is built, you can publish your library by following these steps:
32
+
33
+ 1. Navigate to the `dist` directory:
34
+ ```bash
35
+ cd dist/lib
36
+ ```
37
+
38
+ 2. Run the `npm publish` command to publish your library to the npm registry:
39
+ ```bash
40
+ npm publish
41
+ ```
42
+
43
+ ## Running unit tests
44
+
45
+ To execute unit tests with the [Karma](https://karma-runner.github.io) test runner, use the following command:
46
+
47
+ ```bash
48
+ ng test
49
+ ```
50
+
51
+ ## Running end-to-end tests
52
+
53
+ For end-to-end (e2e) testing, run:
54
+
55
+ ```bash
56
+ ng e2e
57
+ ```
58
+
59
+ Angular CLI does not come with an end-to-end testing framework by default. You can choose one that suits your needs.
60
+
61
+ ## Additional Resources
62
+
63
+ For more information on using the Angular CLI, including detailed command references, visit the [Angular CLI Overview and Command Reference](https://angular.dev/tools/cli) page.
@@ -10,7 +10,8 @@ import DragPan from 'ol/interaction/DragPan';
10
10
  import Modify from 'ol/interaction/Modify';
11
11
  import * as Observable from 'ol/Observable';
12
12
  import { unByKey } from 'ol/Observable';
13
- import { LineString, MultiLineString, Point } from 'ol/geom';
13
+ import { LineString, MultiLineString, Point, Polygon } from 'ol/geom';
14
+ import { toLonLat } from 'ol/proj';
14
15
 
15
16
  class LibService {
16
17
  constructor() { }
@@ -26,18 +27,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
26
27
 
27
28
  class LibComponent {
28
29
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: LibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
29
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: LibComponent, isStandalone: true, selector: "lib-lib", ngImport: i0, template: `
30
- <p>
31
- lib works!
32
- </p>
30
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: LibComponent, isStandalone: true, selector: "lib-lib", ngImport: i0, template: `
31
+ <p>
32
+ lib works!
33
+ </p>
33
34
  `, isInline: true, styles: [""] });
34
35
  }
35
36
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: LibComponent, decorators: [{
36
37
  type: Component,
37
- args: [{ selector: 'lib-lib', imports: [], template: `
38
- <p>
39
- lib works!
40
- </p>
38
+ args: [{ selector: 'lib-lib', imports: [], template: `
39
+ <p>
40
+ lib works!
41
+ </p>
41
42
  ` }]
42
43
  }] });
43
44
 
@@ -2299,7 +2300,7 @@ const resolveMaybeFn = (value, args) => typeof value === 'function' ? value(...a
2299
2300
  * Extracts flat coordinate arrays from a feature's geometry.
2300
2301
  * Supports LineString and MultiLineString; returns empty array for others.
2301
2302
  */
2302
- function extractLineCoords(geometry) {
2303
+ function extractLineCoords$1(geometry) {
2303
2304
  if (geometry instanceof LineString) {
2304
2305
  return [geometry.getCoordinates()];
2305
2306
  }
@@ -2352,7 +2353,7 @@ class ArrowDecorationManager {
2352
2353
  const parentZ = this.parentLayer.getZIndex() ?? 0;
2353
2354
  this.layer = new VectorLayer({
2354
2355
  source: this.source,
2355
- zIndex: parentZ + 1,
2356
+ zIndex: parentZ + 2,
2356
2357
  });
2357
2358
  this.layer.set('id', `__decoration_arrows`);
2358
2359
  this.map.addLayer(this.layer);
@@ -2392,7 +2393,7 @@ class ArrowDecorationManager {
2392
2393
  const geom = feature.getGeometry();
2393
2394
  if (!geom)
2394
2395
  return;
2395
- const lines = extractLineCoords(geom);
2396
+ const lines = extractLineCoords$1(geom);
2396
2397
  for (const coords of lines) {
2397
2398
  const arrows = generateArrowPoints(coords, interval, offsetRatio);
2398
2399
  allArrows.push(...arrows);
@@ -2428,6 +2429,226 @@ class ArrowDecorationManager {
2428
2429
  }
2429
2430
  }
2430
2431
 
2432
+ /**
2433
+ * Compute projected buffer distance for a segment by converting meters
2434
+ * to EPSG:3857 units using the segment's average latitude.
2435
+ */
2436
+ function projectedDistance(ax, ay, bx, by, meters) {
2437
+ const midY = (ay + by) / 2;
2438
+ const [, lat] = toLonLat([0, midY]);
2439
+ const scale = Math.cos((lat * Math.PI) / 180);
2440
+ return scale > 1e-10 ? meters / scale : meters;
2441
+ }
2442
+ /**
2443
+ * Compute the unit normal of a segment (pointing left when walking from a→b).
2444
+ */
2445
+ function segmentNormal(ax, ay, bx, by) {
2446
+ const dx = bx - ax;
2447
+ const dy = by - ay;
2448
+ const len = Math.hypot(dx, dy);
2449
+ if (len === 0)
2450
+ return [0, 0];
2451
+ return [-dy / len, dx / len];
2452
+ }
2453
+ /**
2454
+ * Generate a semicircle of points around a center, from startAngle to startAngle + PI.
2455
+ */
2456
+ function semicircle(cx, cy, radius, startAngle, segments) {
2457
+ const points = [];
2458
+ for (let i = 0; i <= segments; i++) {
2459
+ const angle = startAngle + (Math.PI * i) / segments;
2460
+ points.push([cx + radius * Math.cos(angle), cy + radius * Math.sin(angle)]);
2461
+ }
2462
+ return points;
2463
+ }
2464
+ /**
2465
+ * Generate a closed polygon ring representing a buffer around a polyline.
2466
+ *
2467
+ * @param coords Line vertices in EPSG:3857.
2468
+ * @param distance Buffer width in meters (one side).
2469
+ * @param cap End cap style: 'round' or 'flat'.
2470
+ * @returns Closed ring (first == last point), or empty array if line is degenerate.
2471
+ */
2472
+ function generateBufferPolygon(coords, distance, cap) {
2473
+ if (coords.length < 2)
2474
+ return [];
2475
+ const n = coords.length;
2476
+ const left = [];
2477
+ const right = [];
2478
+ // Compute per-vertex offset using averaged normals at joins
2479
+ for (let i = 0; i < n; i++) {
2480
+ let nx, ny, dist;
2481
+ if (i === 0) {
2482
+ // First vertex — use first segment's normal
2483
+ dist = projectedDistance(coords[0][0], coords[0][1], coords[1][0], coords[1][1], distance);
2484
+ [nx, ny] = segmentNormal(coords[0][0], coords[0][1], coords[1][0], coords[1][1]);
2485
+ }
2486
+ else if (i === n - 1) {
2487
+ // Last vertex — use last segment's normal
2488
+ dist = projectedDistance(coords[n - 2][0], coords[n - 2][1], coords[n - 1][0], coords[n - 1][1], distance);
2489
+ [nx, ny] = segmentNormal(coords[n - 2][0], coords[n - 2][1], coords[n - 1][0], coords[n - 1][1]);
2490
+ }
2491
+ else {
2492
+ // Interior vertex — average normals of adjacent segments
2493
+ const dist1 = projectedDistance(coords[i - 1][0], coords[i - 1][1], coords[i][0], coords[i][1], distance);
2494
+ const dist2 = projectedDistance(coords[i][0], coords[i][1], coords[i + 1][0], coords[i + 1][1], distance);
2495
+ dist = (dist1 + dist2) / 2;
2496
+ const [n1x, n1y] = segmentNormal(coords[i - 1][0], coords[i - 1][1], coords[i][0], coords[i][1]);
2497
+ const [n2x, n2y] = segmentNormal(coords[i][0], coords[i][1], coords[i + 1][0], coords[i + 1][1]);
2498
+ nx = n1x + n2x;
2499
+ ny = n1y + n2y;
2500
+ const len = Math.hypot(nx, ny);
2501
+ if (len > 1e-10) {
2502
+ nx /= len;
2503
+ ny /= len;
2504
+ // Miter length factor: 1 / cos(half-angle between segments)
2505
+ const dot = n1x * nx + n1y * ny;
2506
+ const miterScale = dot > 0.5 ? 1 / dot : 2; // Clamp miter at ratio 2 to prevent spikes
2507
+ dist *= miterScale;
2508
+ }
2509
+ else {
2510
+ [nx, ny] = segmentNormal(coords[i - 1][0], coords[i - 1][1], coords[i][0], coords[i][1]);
2511
+ }
2512
+ }
2513
+ const x = coords[i][0];
2514
+ const y = coords[i][1];
2515
+ left.push([x + nx * dist, y + ny * dist]);
2516
+ right.push([x - nx * dist, y - ny * dist]);
2517
+ }
2518
+ // Assemble the polygon ring: left forward → end cap → right backward → start cap → close
2519
+ const ring = [];
2520
+ // Left side (forward)
2521
+ for (let i = 0; i < n; i++) {
2522
+ ring.push(left[i]);
2523
+ }
2524
+ // End cap
2525
+ if (cap === 'round') {
2526
+ const [n2x, n2y] = segmentNormal(coords[n - 2][0], coords[n - 2][1], coords[n - 1][0], coords[n - 1][1]);
2527
+ const endAngle = Math.atan2(-n2y, -n2x);
2528
+ const dist = projectedDistance(coords[n - 2][0], coords[n - 2][1], coords[n - 1][0], coords[n - 1][1], distance);
2529
+ ring.push(...semicircle(coords[n - 1][0], coords[n - 1][1], dist, endAngle, 8));
2530
+ }
2531
+ else {
2532
+ ring.push(right[n - 1]);
2533
+ }
2534
+ // Right side (backward)
2535
+ for (let i = n - 2; i >= 0; i--) {
2536
+ ring.push(right[i]);
2537
+ }
2538
+ // Start cap
2539
+ if (cap === 'round') {
2540
+ const [n1x, n1y] = segmentNormal(coords[0][0], coords[0][1], coords[1][0], coords[1][1]);
2541
+ const startAngle = Math.atan2(n1y, n1x);
2542
+ const dist = projectedDistance(coords[0][0], coords[0][1], coords[1][0], coords[1][1], distance);
2543
+ ring.push(...semicircle(coords[0][0], coords[0][1], dist, startAngle, 8));
2544
+ }
2545
+ // Close ring
2546
+ ring.push(ring[0].slice());
2547
+ return ring;
2548
+ }
2549
+
2550
+ /**
2551
+ * Extracts flat coordinate arrays from a feature's geometry.
2552
+ * Supports LineString and MultiLineString; returns empty array for others.
2553
+ */
2554
+ function extractLineCoords(geometry) {
2555
+ if (geometry instanceof LineString) {
2556
+ return [geometry.getCoordinates()];
2557
+ }
2558
+ if (geometry instanceof MultiLineString) {
2559
+ return geometry.getCoordinates();
2560
+ }
2561
+ return [];
2562
+ }
2563
+ class BufferDecorationManager {
2564
+ source = new VectorSource();
2565
+ layer;
2566
+ config;
2567
+ map;
2568
+ parentLayer;
2569
+ parentApi;
2570
+ moveEndKey;
2571
+ unsubCollection;
2572
+ unsubChanges;
2573
+ rafId = null;
2574
+ constructor(options) {
2575
+ this.config = options.config;
2576
+ this.map = options.map;
2577
+ this.parentLayer = options.parentLayer;
2578
+ this.parentApi = options.parentApi;
2579
+ const parentZ = this.parentLayer.getZIndex() ?? 0;
2580
+ this.layer = new VectorLayer({
2581
+ source: this.source,
2582
+ zIndex: parentZ,
2583
+ });
2584
+ this.layer.set('id', '__decoration_buffer');
2585
+ this.map.addLayer(this.layer);
2586
+ this.syncVisibility();
2587
+ this.syncOpacity();
2588
+ this.moveEndKey = this.map.on('moveend', () => this.scheduleUpdate());
2589
+ this.unsubCollection = this.parentApi.onModelsCollectionChanged(() => this.scheduleUpdate());
2590
+ this.unsubChanges = this.parentApi.onModelsChanged?.(() => this.scheduleUpdate());
2591
+ }
2592
+ scheduleUpdate() {
2593
+ if (this.rafId !== null)
2594
+ return;
2595
+ this.rafId = requestAnimationFrame(() => {
2596
+ this.rafId = null;
2597
+ this.rebuild();
2598
+ });
2599
+ }
2600
+ rebuild() {
2601
+ this.syncVisibility();
2602
+ this.syncOpacity();
2603
+ if (!this.parentLayer.getVisible()) {
2604
+ this.source.clear();
2605
+ return;
2606
+ }
2607
+ const parentSource = this.parentLayer.getSource();
2608
+ if (!parentSource) {
2609
+ this.source.clear();
2610
+ return;
2611
+ }
2612
+ const cap = this.config.cap ?? 'round';
2613
+ const style = this.config.style;
2614
+ const allFeatures = [];
2615
+ parentSource.getFeatures().forEach((feature) => {
2616
+ const geom = feature.getGeometry();
2617
+ if (!geom)
2618
+ return;
2619
+ const lines = extractLineCoords(geom);
2620
+ for (const coords of lines) {
2621
+ const ring = generateBufferPolygon(coords, this.config.distance, cap);
2622
+ if (ring.length === 0)
2623
+ continue;
2624
+ const f = new Feature({ geometry: new Polygon([ring]) });
2625
+ f.setStyle(Array.isArray(style) ? style : [style]);
2626
+ allFeatures.push(f);
2627
+ }
2628
+ });
2629
+ this.source.clear();
2630
+ if (allFeatures.length > 0) {
2631
+ this.source.addFeatures(allFeatures);
2632
+ }
2633
+ }
2634
+ syncVisibility() {
2635
+ this.layer.setVisible(this.parentLayer.getVisible());
2636
+ }
2637
+ syncOpacity() {
2638
+ this.layer.setOpacity(this.parentLayer.getOpacity());
2639
+ }
2640
+ dispose() {
2641
+ if (this.rafId !== null) {
2642
+ cancelAnimationFrame(this.rafId);
2643
+ this.rafId = null;
2644
+ }
2645
+ unByKey(this.moveEndKey);
2646
+ this.unsubCollection();
2647
+ this.unsubChanges?.();
2648
+ this.map.removeLayer(this.layer);
2649
+ }
2650
+ }
2651
+
2431
2652
  class LayerManager {
2432
2653
  map;
2433
2654
  layers = {};
@@ -2484,6 +2705,16 @@ class LayerManager {
2484
2705
  this.layers[descriptor.id] = layer;
2485
2706
  this.apis[descriptor.id] = api;
2486
2707
  this.map.addLayer(layer);
2708
+ if (descriptor.feature.decorations?.buffer) {
2709
+ const bufferManager = new BufferDecorationManager({
2710
+ map: this.map,
2711
+ parentLayer: layer,
2712
+ parentApi: api,
2713
+ config: descriptor.feature.decorations.buffer,
2714
+ });
2715
+ this.decorationManagers.push(bufferManager);
2716
+ layer.setZIndex((descriptor.zIndex ?? 0) + 1);
2717
+ }
2487
2718
  if (descriptor.feature.decorations?.arrows) {
2488
2719
  const decorationManager = new ArrowDecorationManager({
2489
2720
  map: this.map,