map-ol-utils 0.1.10 → 0.1.12
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/dist/index.cjs +55 -33
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +55 -33
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -144,9 +144,7 @@ var removeOverlays = (key = "") => {
|
|
|
144
144
|
overlays.forEach((overlay) => instance.removeOverlay(overlay));
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
|
-
var removeAnimationMarker = () =>
|
|
148
|
-
removeOverlays("_isAnimationMarker");
|
|
149
|
-
};
|
|
147
|
+
var removeAnimationMarker = () => removeOverlays("_isAnimationMarker");
|
|
150
148
|
var createAnimationMarker = (imgUrl, data) => {
|
|
151
149
|
removeAnimationMarker();
|
|
152
150
|
const { width, height, lnglat, crsForm } = data;
|
|
@@ -428,6 +426,37 @@ var buildMassMarksStyles = (getImgUrlFn) => {
|
|
|
428
426
|
return massMarksStyles;
|
|
429
427
|
};
|
|
430
428
|
};
|
|
429
|
+
var selectEventHandle = (vectorLayer, feature) => {
|
|
430
|
+
const data = feature.getProperties();
|
|
431
|
+
const { activeStyle } = data;
|
|
432
|
+
feature.setStyle(activeStyle);
|
|
433
|
+
emitter_default.emit("selected-feature", data);
|
|
434
|
+
vectorLayer.set("_hasActive", true);
|
|
435
|
+
if (vectorLayer.get("_isDynamic")) {
|
|
436
|
+
const activeImage = activeStyle.getImage();
|
|
437
|
+
setTimeout(() => {
|
|
438
|
+
emitter_default.emit(
|
|
439
|
+
"dynamic-marker",
|
|
440
|
+
Object.assign({}, data.rawData || {}, {
|
|
441
|
+
lnglat: data.lnglat,
|
|
442
|
+
style: data.style,
|
|
443
|
+
crsForm: data.crsForm,
|
|
444
|
+
width: activeImage.getWidth(),
|
|
445
|
+
height: activeImage.getHeight()
|
|
446
|
+
})
|
|
447
|
+
);
|
|
448
|
+
}, 1e3);
|
|
449
|
+
}
|
|
450
|
+
const isAutoFit = vectorLayer.get("_isAutoFit");
|
|
451
|
+
if (isAutoFit) {
|
|
452
|
+
const view = instance.getView();
|
|
453
|
+
view.animate({
|
|
454
|
+
duration: 1e3,
|
|
455
|
+
zoom: view.getZoom(),
|
|
456
|
+
center: (0, import_extent.getCenter)(feature.getGeometry().getExtent())
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
};
|
|
431
460
|
var createSelectByLayer = (vectorLayer) => {
|
|
432
461
|
const interaction = new import_interaction.Select({
|
|
433
462
|
style: null,
|
|
@@ -452,34 +481,14 @@ var createSelectByLayer = (vectorLayer) => {
|
|
|
452
481
|
const { selected, deselected } = evt;
|
|
453
482
|
if (selected.length) {
|
|
454
483
|
const feature = selected[0];
|
|
455
|
-
const
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
emitter_default.emit(
|
|
464
|
-
"dynamic-marker",
|
|
465
|
-
Object.assign({}, data.rawData || {}, {
|
|
466
|
-
lnglat: data.lnglat,
|
|
467
|
-
style: data.style,
|
|
468
|
-
crsForm: data.crsForm,
|
|
469
|
-
width: activeImage.getWidth(),
|
|
470
|
-
height: activeImage.getHeight()
|
|
471
|
-
})
|
|
472
|
-
);
|
|
473
|
-
}, 1e3);
|
|
474
|
-
}
|
|
475
|
-
const isAutoFit = vectorLayer.get("_isAutoFit");
|
|
476
|
-
if (isAutoFit) {
|
|
477
|
-
const view = instance.getView();
|
|
478
|
-
view.animate({
|
|
479
|
-
duration: 1e3,
|
|
480
|
-
zoom: view.getZoom(),
|
|
481
|
-
center: (0, import_extent.getCenter)(feature.getGeometry().getExtent())
|
|
482
|
-
});
|
|
484
|
+
const isClusterLayer = vectorLayer.get("_isClusterLayer");
|
|
485
|
+
if (isClusterLayer) {
|
|
486
|
+
const features = feature.get("features");
|
|
487
|
+
if (features.length === 1) {
|
|
488
|
+
selectEventHandle(vectorLayer, features[0]);
|
|
489
|
+
}
|
|
490
|
+
} else {
|
|
491
|
+
selectEventHandle(vectorLayer, feature);
|
|
483
492
|
}
|
|
484
493
|
}
|
|
485
494
|
if (deselected.length) {
|
|
@@ -636,7 +645,7 @@ var createOverlay = (config = { id: "popup-container", positioning: "top-center"
|
|
|
636
645
|
var createClusterLayer = (dataList, config) => {
|
|
637
646
|
const count = dataList.length;
|
|
638
647
|
const styleCache = {};
|
|
639
|
-
const { distance, minDistance, buildStyle, singleStyles, computedRadius } = config;
|
|
648
|
+
const { distance, minDistance, openClick, buildStyle, singleStyles, computedRadius } = config;
|
|
640
649
|
const innerComputedRadius = (size) => Math.pow(size / count, 1 / 18);
|
|
641
650
|
styleCache[1] = singleStyles;
|
|
642
651
|
const innerBuildStyle = (feature) => {
|
|
@@ -668,11 +677,15 @@ var createClusterLayer = (dataList, config) => {
|
|
|
668
677
|
if (Array.isArray(style)) {
|
|
669
678
|
const tempFeature = feature.get("features")[0];
|
|
670
679
|
const index = tempFeature.get("styleIndex");
|
|
680
|
+
tempFeature.setProperties({
|
|
681
|
+
unActiveStyle: style[index],
|
|
682
|
+
activeStyle: style[index + style.length / 2]
|
|
683
|
+
});
|
|
671
684
|
return style[index];
|
|
672
685
|
}
|
|
673
686
|
return style;
|
|
674
687
|
};
|
|
675
|
-
|
|
688
|
+
const vectorLayer = new import_Vector.default({
|
|
676
689
|
zIndex: 200,
|
|
677
690
|
style: (feature) => buildStyle ? buildStyle(feature) : innerBuildStyle(feature),
|
|
678
691
|
source: new import_Cluster.default({
|
|
@@ -687,6 +700,15 @@ var createClusterLayer = (dataList, config) => {
|
|
|
687
700
|
})
|
|
688
701
|
})
|
|
689
702
|
});
|
|
703
|
+
vectorLayer.setProperties({
|
|
704
|
+
_isCustom: true,
|
|
705
|
+
_isVectorLayer: true,
|
|
706
|
+
_isClusterLayer: true
|
|
707
|
+
});
|
|
708
|
+
if (openClick) {
|
|
709
|
+
createSelectByLayer(vectorLayer);
|
|
710
|
+
}
|
|
711
|
+
return vectorLayer;
|
|
690
712
|
};
|
|
691
713
|
|
|
692
714
|
// src/create-map.ts
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -77,9 +77,7 @@ var removeOverlays = (key = "") => {
|
|
|
77
77
|
overlays.forEach((overlay) => instance.removeOverlay(overlay));
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
|
-
var removeAnimationMarker = () =>
|
|
81
|
-
removeOverlays("_isAnimationMarker");
|
|
82
|
-
};
|
|
80
|
+
var removeAnimationMarker = () => removeOverlays("_isAnimationMarker");
|
|
83
81
|
var createAnimationMarker = (imgUrl, data) => {
|
|
84
82
|
removeAnimationMarker();
|
|
85
83
|
const { width, height, lnglat, crsForm } = data;
|
|
@@ -361,6 +359,37 @@ var buildMassMarksStyles = (getImgUrlFn) => {
|
|
|
361
359
|
return massMarksStyles;
|
|
362
360
|
};
|
|
363
361
|
};
|
|
362
|
+
var selectEventHandle = (vectorLayer, feature) => {
|
|
363
|
+
const data = feature.getProperties();
|
|
364
|
+
const { activeStyle } = data;
|
|
365
|
+
feature.setStyle(activeStyle);
|
|
366
|
+
emitter_default.emit("selected-feature", data);
|
|
367
|
+
vectorLayer.set("_hasActive", true);
|
|
368
|
+
if (vectorLayer.get("_isDynamic")) {
|
|
369
|
+
const activeImage = activeStyle.getImage();
|
|
370
|
+
setTimeout(() => {
|
|
371
|
+
emitter_default.emit(
|
|
372
|
+
"dynamic-marker",
|
|
373
|
+
Object.assign({}, data.rawData || {}, {
|
|
374
|
+
lnglat: data.lnglat,
|
|
375
|
+
style: data.style,
|
|
376
|
+
crsForm: data.crsForm,
|
|
377
|
+
width: activeImage.getWidth(),
|
|
378
|
+
height: activeImage.getHeight()
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
}, 1e3);
|
|
382
|
+
}
|
|
383
|
+
const isAutoFit = vectorLayer.get("_isAutoFit");
|
|
384
|
+
if (isAutoFit) {
|
|
385
|
+
const view = instance.getView();
|
|
386
|
+
view.animate({
|
|
387
|
+
duration: 1e3,
|
|
388
|
+
zoom: view.getZoom(),
|
|
389
|
+
center: getCenter(feature.getGeometry().getExtent())
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
};
|
|
364
393
|
var createSelectByLayer = (vectorLayer) => {
|
|
365
394
|
const interaction = new Select({
|
|
366
395
|
style: null,
|
|
@@ -385,34 +414,14 @@ var createSelectByLayer = (vectorLayer) => {
|
|
|
385
414
|
const { selected, deselected } = evt;
|
|
386
415
|
if (selected.length) {
|
|
387
416
|
const feature = selected[0];
|
|
388
|
-
const
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
emitter_default.emit(
|
|
397
|
-
"dynamic-marker",
|
|
398
|
-
Object.assign({}, data.rawData || {}, {
|
|
399
|
-
lnglat: data.lnglat,
|
|
400
|
-
style: data.style,
|
|
401
|
-
crsForm: data.crsForm,
|
|
402
|
-
width: activeImage.getWidth(),
|
|
403
|
-
height: activeImage.getHeight()
|
|
404
|
-
})
|
|
405
|
-
);
|
|
406
|
-
}, 1e3);
|
|
407
|
-
}
|
|
408
|
-
const isAutoFit = vectorLayer.get("_isAutoFit");
|
|
409
|
-
if (isAutoFit) {
|
|
410
|
-
const view = instance.getView();
|
|
411
|
-
view.animate({
|
|
412
|
-
duration: 1e3,
|
|
413
|
-
zoom: view.getZoom(),
|
|
414
|
-
center: getCenter(feature.getGeometry().getExtent())
|
|
415
|
-
});
|
|
417
|
+
const isClusterLayer = vectorLayer.get("_isClusterLayer");
|
|
418
|
+
if (isClusterLayer) {
|
|
419
|
+
const features = feature.get("features");
|
|
420
|
+
if (features.length === 1) {
|
|
421
|
+
selectEventHandle(vectorLayer, features[0]);
|
|
422
|
+
}
|
|
423
|
+
} else {
|
|
424
|
+
selectEventHandle(vectorLayer, feature);
|
|
416
425
|
}
|
|
417
426
|
}
|
|
418
427
|
if (deselected.length) {
|
|
@@ -569,7 +578,7 @@ var createOverlay = (config = { id: "popup-container", positioning: "top-center"
|
|
|
569
578
|
var createClusterLayer = (dataList, config) => {
|
|
570
579
|
const count = dataList.length;
|
|
571
580
|
const styleCache = {};
|
|
572
|
-
const { distance, minDistance, buildStyle, singleStyles, computedRadius } = config;
|
|
581
|
+
const { distance, minDistance, openClick, buildStyle, singleStyles, computedRadius } = config;
|
|
573
582
|
const innerComputedRadius = (size) => Math.pow(size / count, 1 / 18);
|
|
574
583
|
styleCache[1] = singleStyles;
|
|
575
584
|
const innerBuildStyle = (feature) => {
|
|
@@ -601,11 +610,15 @@ var createClusterLayer = (dataList, config) => {
|
|
|
601
610
|
if (Array.isArray(style)) {
|
|
602
611
|
const tempFeature = feature.get("features")[0];
|
|
603
612
|
const index = tempFeature.get("styleIndex");
|
|
613
|
+
tempFeature.setProperties({
|
|
614
|
+
unActiveStyle: style[index],
|
|
615
|
+
activeStyle: style[index + style.length / 2]
|
|
616
|
+
});
|
|
604
617
|
return style[index];
|
|
605
618
|
}
|
|
606
619
|
return style;
|
|
607
620
|
};
|
|
608
|
-
|
|
621
|
+
const vectorLayer = new VectorLayer({
|
|
609
622
|
zIndex: 200,
|
|
610
623
|
style: (feature) => buildStyle ? buildStyle(feature) : innerBuildStyle(feature),
|
|
611
624
|
source: new Cluster({
|
|
@@ -620,6 +633,15 @@ var createClusterLayer = (dataList, config) => {
|
|
|
620
633
|
})
|
|
621
634
|
})
|
|
622
635
|
});
|
|
636
|
+
vectorLayer.setProperties({
|
|
637
|
+
_isCustom: true,
|
|
638
|
+
_isVectorLayer: true,
|
|
639
|
+
_isClusterLayer: true
|
|
640
|
+
});
|
|
641
|
+
if (openClick) {
|
|
642
|
+
createSelectByLayer(vectorLayer);
|
|
643
|
+
}
|
|
644
|
+
return vectorLayer;
|
|
623
645
|
};
|
|
624
646
|
|
|
625
647
|
// src/create-map.ts
|