aur-openlayers 19.6.4 → 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 +63 -63
- package/fesm2022/aur-openlayers.mjs +389 -11
- package/fesm2022/aur-openlayers.mjs.map +1 -1
- package/lib/map-framework/public/types.d.ts +52 -0
- package/lib/map-framework/runtime/decorations/arrow-decoration-manager.d.ts +27 -0
- package/lib/map-framework/runtime/decorations/buffer-decoration-manager.d.ts +27 -0
- package/lib/map-framework/runtime/decorations/generate-buffer-polygon.d.ts +9 -0
- package/lib/map-framework/runtime/layer-manager.d.ts +1 -0
- package/package.json +1 -1
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.
|
|
@@ -9,6 +9,9 @@ import Collection from 'ol/Collection';
|
|
|
9
9
|
import DragPan from 'ol/interaction/DragPan';
|
|
10
10
|
import Modify from 'ol/interaction/Modify';
|
|
11
11
|
import * as Observable from 'ol/Observable';
|
|
12
|
+
import { unByKey } from 'ol/Observable';
|
|
13
|
+
import { LineString, MultiLineString, Point, Polygon } from 'ol/geom';
|
|
14
|
+
import { toLonLat } from 'ol/proj';
|
|
12
15
|
|
|
13
16
|
class LibService {
|
|
14
17
|
constructor() { }
|
|
@@ -24,18 +27,18 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImpo
|
|
|
24
27
|
|
|
25
28
|
class LibComponent {
|
|
26
29
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: LibComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
27
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.18", type: LibComponent, isStandalone: true, selector: "lib-lib", ngImport: i0, template: `
|
|
28
|
-
<p>
|
|
29
|
-
lib works!
|
|
30
|
-
</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>
|
|
31
34
|
`, isInline: true, styles: [""] });
|
|
32
35
|
}
|
|
33
36
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.18", ngImport: i0, type: LibComponent, decorators: [{
|
|
34
37
|
type: Component,
|
|
35
|
-
args: [{ selector: 'lib-lib', imports: [], template: `
|
|
36
|
-
<p>
|
|
37
|
-
lib works!
|
|
38
|
-
</p>
|
|
38
|
+
args: [{ selector: 'lib-lib', imports: [], template: `
|
|
39
|
+
<p>
|
|
40
|
+
lib works!
|
|
41
|
+
</p>
|
|
39
42
|
` }]
|
|
40
43
|
}] });
|
|
41
44
|
|
|
@@ -1585,7 +1588,7 @@ class StyleCache {
|
|
|
1585
1588
|
}
|
|
1586
1589
|
}
|
|
1587
1590
|
|
|
1588
|
-
const resolveMaybeFn = (value, args) => {
|
|
1591
|
+
const resolveMaybeFn$1 = (value, args) => {
|
|
1589
1592
|
if (typeof value === 'function') {
|
|
1590
1593
|
return value(...args);
|
|
1591
1594
|
}
|
|
@@ -1620,7 +1623,7 @@ const createStyleFunction = (options) => {
|
|
|
1620
1623
|
resolution,
|
|
1621
1624
|
zoom: map?.getView().getZoom(),
|
|
1622
1625
|
};
|
|
1623
|
-
let opts = resolveMaybeFn(style.base, [model, view]);
|
|
1626
|
+
let opts = resolveMaybeFn$1(style.base, [model, view]);
|
|
1624
1627
|
if (style.states) {
|
|
1625
1628
|
const featureStates = orderStates(getFeatureStates(feature), style.statePriority);
|
|
1626
1629
|
featureStates.forEach((state) => {
|
|
@@ -1628,7 +1631,7 @@ const createStyleFunction = (options) => {
|
|
|
1628
1631
|
if (!patchFactory) {
|
|
1629
1632
|
return;
|
|
1630
1633
|
}
|
|
1631
|
-
const patch = resolveMaybeFn(patchFactory, [model, view]);
|
|
1634
|
+
const patch = resolveMaybeFn$1(patchFactory, [model, view]);
|
|
1632
1635
|
opts = applyPatch(opts, patch);
|
|
1633
1636
|
});
|
|
1634
1637
|
}
|
|
@@ -2292,6 +2295,360 @@ class PopupHost {
|
|
|
2292
2295
|
}
|
|
2293
2296
|
}
|
|
2294
2297
|
|
|
2298
|
+
const resolveMaybeFn = (value, args) => typeof value === 'function' ? value(...args) : value;
|
|
2299
|
+
/**
|
|
2300
|
+
* Extracts flat coordinate arrays from a feature's geometry.
|
|
2301
|
+
* Supports LineString and MultiLineString; returns empty array for others.
|
|
2302
|
+
*/
|
|
2303
|
+
function extractLineCoords$1(geometry) {
|
|
2304
|
+
if (geometry instanceof LineString) {
|
|
2305
|
+
return [geometry.getCoordinates()];
|
|
2306
|
+
}
|
|
2307
|
+
if (geometry instanceof MultiLineString) {
|
|
2308
|
+
return geometry.getCoordinates();
|
|
2309
|
+
}
|
|
2310
|
+
return [];
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2313
|
+
* Generate arrow points along a polyline at a given interval (meters in EPSG:3857).
|
|
2314
|
+
*/
|
|
2315
|
+
function generateArrowPoints(coords, intervalMeters, offsetRatio) {
|
|
2316
|
+
if (coords.length < 2 || intervalMeters <= 0)
|
|
2317
|
+
return [];
|
|
2318
|
+
const arrows = [];
|
|
2319
|
+
let accumulated = intervalMeters * offsetRatio;
|
|
2320
|
+
for (let i = 0; i < coords.length - 1; i++) {
|
|
2321
|
+
const ax = coords[i][0], ay = coords[i][1];
|
|
2322
|
+
const bx = coords[i + 1][0], by = coords[i + 1][1];
|
|
2323
|
+
const segLen = Math.hypot(bx - ax, by - ay);
|
|
2324
|
+
const rotation = Math.atan2(bx - ax, by - ay);
|
|
2325
|
+
while (accumulated <= segLen) {
|
|
2326
|
+
const t = accumulated / segLen;
|
|
2327
|
+
arrows.push({
|
|
2328
|
+
coordinate: [ax + t * (bx - ax), ay + t * (by - ay)],
|
|
2329
|
+
rotation,
|
|
2330
|
+
});
|
|
2331
|
+
accumulated += intervalMeters;
|
|
2332
|
+
}
|
|
2333
|
+
accumulated -= segLen;
|
|
2334
|
+
}
|
|
2335
|
+
return arrows;
|
|
2336
|
+
}
|
|
2337
|
+
class ArrowDecorationManager {
|
|
2338
|
+
source = new VectorSource();
|
|
2339
|
+
layer;
|
|
2340
|
+
config;
|
|
2341
|
+
map;
|
|
2342
|
+
parentLayer;
|
|
2343
|
+
parentApi;
|
|
2344
|
+
moveEndKey;
|
|
2345
|
+
unsubCollection;
|
|
2346
|
+
unsubChanges;
|
|
2347
|
+
rafId = null;
|
|
2348
|
+
constructor(options) {
|
|
2349
|
+
this.config = options.config;
|
|
2350
|
+
this.map = options.map;
|
|
2351
|
+
this.parentLayer = options.parentLayer;
|
|
2352
|
+
this.parentApi = options.parentApi;
|
|
2353
|
+
const parentZ = this.parentLayer.getZIndex() ?? 0;
|
|
2354
|
+
this.layer = new VectorLayer({
|
|
2355
|
+
source: this.source,
|
|
2356
|
+
zIndex: parentZ + 2,
|
|
2357
|
+
});
|
|
2358
|
+
this.layer.set('id', `__decoration_arrows`);
|
|
2359
|
+
this.map.addLayer(this.layer);
|
|
2360
|
+
this.syncVisibility();
|
|
2361
|
+
this.syncOpacity();
|
|
2362
|
+
this.moveEndKey = this.map.on('moveend', () => this.scheduleUpdate());
|
|
2363
|
+
this.unsubCollection = this.parentApi.onModelsCollectionChanged(() => this.scheduleUpdate());
|
|
2364
|
+
this.unsubChanges = this.parentApi.onModelsChanged?.(() => this.scheduleUpdate());
|
|
2365
|
+
}
|
|
2366
|
+
scheduleUpdate() {
|
|
2367
|
+
if (this.rafId !== null)
|
|
2368
|
+
return;
|
|
2369
|
+
this.rafId = requestAnimationFrame(() => {
|
|
2370
|
+
this.rafId = null;
|
|
2371
|
+
this.rebuild();
|
|
2372
|
+
});
|
|
2373
|
+
}
|
|
2374
|
+
rebuild() {
|
|
2375
|
+
this.syncVisibility();
|
|
2376
|
+
this.syncOpacity();
|
|
2377
|
+
if (!this.parentLayer.getVisible()) {
|
|
2378
|
+
this.source.clear();
|
|
2379
|
+
return;
|
|
2380
|
+
}
|
|
2381
|
+
const view = this.map.getView();
|
|
2382
|
+
const resolution = view.getResolution() ?? 1;
|
|
2383
|
+
const styleView = { resolution, zoom: view.getZoom() };
|
|
2384
|
+
const interval = resolveMaybeFn(this.config.interval, [styleView]);
|
|
2385
|
+
const offsetRatio = this.config.offsetRatio ?? 0.5;
|
|
2386
|
+
const parentSource = this.parentLayer.getSource();
|
|
2387
|
+
if (!parentSource) {
|
|
2388
|
+
this.source.clear();
|
|
2389
|
+
return;
|
|
2390
|
+
}
|
|
2391
|
+
const allArrows = [];
|
|
2392
|
+
parentSource.getFeatures().forEach((feature) => {
|
|
2393
|
+
const geom = feature.getGeometry();
|
|
2394
|
+
if (!geom)
|
|
2395
|
+
return;
|
|
2396
|
+
const lines = extractLineCoords$1(geom);
|
|
2397
|
+
for (const coords of lines) {
|
|
2398
|
+
const arrows = generateArrowPoints(coords, interval, offsetRatio);
|
|
2399
|
+
allArrows.push(...arrows);
|
|
2400
|
+
}
|
|
2401
|
+
});
|
|
2402
|
+
const features = allArrows.map((arrow, i) => {
|
|
2403
|
+
const f = new Feature({ geometry: new Point(arrow.coordinate) });
|
|
2404
|
+
f.setId(`__arrow_${i}`);
|
|
2405
|
+
const styleResult = this.config.style({ rotation: arrow.rotation, view: styleView });
|
|
2406
|
+
f.setStyle(Array.isArray(styleResult) ? styleResult : [styleResult]);
|
|
2407
|
+
return f;
|
|
2408
|
+
});
|
|
2409
|
+
this.source.clear();
|
|
2410
|
+
if (features.length > 0) {
|
|
2411
|
+
this.source.addFeatures(features);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
syncVisibility() {
|
|
2415
|
+
this.layer.setVisible(this.parentLayer.getVisible());
|
|
2416
|
+
}
|
|
2417
|
+
syncOpacity() {
|
|
2418
|
+
this.layer.setOpacity(this.parentLayer.getOpacity());
|
|
2419
|
+
}
|
|
2420
|
+
dispose() {
|
|
2421
|
+
if (this.rafId !== null) {
|
|
2422
|
+
cancelAnimationFrame(this.rafId);
|
|
2423
|
+
this.rafId = null;
|
|
2424
|
+
}
|
|
2425
|
+
unByKey(this.moveEndKey);
|
|
2426
|
+
this.unsubCollection();
|
|
2427
|
+
this.unsubChanges?.();
|
|
2428
|
+
this.map.removeLayer(this.layer);
|
|
2429
|
+
}
|
|
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
|
+
|
|
2295
2652
|
class LayerManager {
|
|
2296
2653
|
map;
|
|
2297
2654
|
layers = {};
|
|
@@ -2300,6 +2657,7 @@ class LayerManager {
|
|
|
2300
2657
|
scheduler;
|
|
2301
2658
|
popupHost;
|
|
2302
2659
|
ctx;
|
|
2660
|
+
decorationManagers = [];
|
|
2303
2661
|
constructor(map, schema) {
|
|
2304
2662
|
this.map = map;
|
|
2305
2663
|
const popupHost = schema.options?.popupHost ? new PopupHost(schema.options.popupHost) : undefined;
|
|
@@ -2347,6 +2705,25 @@ class LayerManager {
|
|
|
2347
2705
|
this.layers[descriptor.id] = layer;
|
|
2348
2706
|
this.apis[descriptor.id] = api;
|
|
2349
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
|
+
}
|
|
2718
|
+
if (descriptor.feature.decorations?.arrows) {
|
|
2719
|
+
const decorationManager = new ArrowDecorationManager({
|
|
2720
|
+
map: this.map,
|
|
2721
|
+
parentLayer: layer,
|
|
2722
|
+
parentApi: api,
|
|
2723
|
+
config: descriptor.feature.decorations.arrows,
|
|
2724
|
+
});
|
|
2725
|
+
this.decorationManagers.push(decorationManager);
|
|
2726
|
+
}
|
|
2350
2727
|
});
|
|
2351
2728
|
this.interactions = new InteractionManager({
|
|
2352
2729
|
ctx,
|
|
@@ -2378,6 +2755,7 @@ class LayerManager {
|
|
|
2378
2755
|
this.interactions.dispose();
|
|
2379
2756
|
this.popupHost?.dispose();
|
|
2380
2757
|
this.scheduler.dispose();
|
|
2758
|
+
this.decorationManagers.forEach((dm) => dm.dispose());
|
|
2381
2759
|
Object.values(this.layers).forEach((layer) => this.map.removeLayer(layer));
|
|
2382
2760
|
}
|
|
2383
2761
|
}
|