@rousen/react-naver-maps 0.0.14 → 0.1.0
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/components/Circle.d.ts +36 -0
- package/dist/components/Circle.d.ts.map +1 -0
- package/dist/components/DataLayer.d.ts +52 -0
- package/dist/components/DataLayer.d.ts.map +1 -0
- package/dist/components/Ellipse.d.ts +36 -0
- package/dist/components/Ellipse.d.ts.map +1 -0
- package/dist/components/Map.d.ts.map +1 -1
- package/dist/components/Polygon.d.ts +32 -7
- package/dist/components/Polygon.d.ts.map +1 -1
- package/dist/components/Rectangle.d.ts +36 -0
- package/dist/components/Rectangle.d.ts.map +1 -0
- package/dist/index.d.ts +211 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +414 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +417 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -162,7 +162,7 @@ const useScriptLoader = ({ ncpKeyId, submodules, disableGL, }) => {
|
|
|
162
162
|
return { isScriptLoaded };
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
const EVENT_TO_PROP$
|
|
165
|
+
const EVENT_TO_PROP$7 = {
|
|
166
166
|
init: "onInit",
|
|
167
167
|
zoomstart: "onZoomStart",
|
|
168
168
|
zoomend: "onZoomEnd",
|
|
@@ -208,6 +208,9 @@ const Map = react.forwardRef(({ id, mapTypeId = "normal", ncpKeyId, children, ma
|
|
|
208
208
|
react.useEffect(() => {
|
|
209
209
|
if (!isScriptLoaded || !containerRef.current)
|
|
210
210
|
return;
|
|
211
|
+
if (id === "current") {
|
|
212
|
+
throw new Error("id cannot be 'current' use other id");
|
|
213
|
+
}
|
|
211
214
|
const newInstance = new naver.maps.Map(containerRef.current, {
|
|
212
215
|
...mapOptions,
|
|
213
216
|
gl: !disableGL,
|
|
@@ -226,8 +229,8 @@ const Map = react.forwardRef(({ id, mapTypeId = "normal", ncpKeyId, children, ma
|
|
|
226
229
|
const handlersRef = react.useRef({});
|
|
227
230
|
react.useEffect(() => {
|
|
228
231
|
const next = {};
|
|
229
|
-
Object.keys(EVENT_TO_PROP$
|
|
230
|
-
const propKey = EVENT_TO_PROP$
|
|
232
|
+
Object.keys(EVENT_TO_PROP$7).forEach((eventKey) => {
|
|
233
|
+
const propKey = EVENT_TO_PROP$7[eventKey];
|
|
231
234
|
const fn = eventProps[propKey];
|
|
232
235
|
if (typeof fn === "function")
|
|
233
236
|
next[eventKey] = fn;
|
|
@@ -243,7 +246,7 @@ const Map = react.forwardRef(({ id, mapTypeId = "normal", ncpKeyId, children, ma
|
|
|
243
246
|
if (!mapInstance)
|
|
244
247
|
return;
|
|
245
248
|
const disposers = [];
|
|
246
|
-
Object.keys(EVENT_TO_PROP$
|
|
249
|
+
Object.keys(EVENT_TO_PROP$7).forEach((eventKey) => {
|
|
247
250
|
const listener = naver.maps.Event.addListener(mapInstance, eventKey, (...args) => {
|
|
248
251
|
handlersRef.current[eventKey]?.(...args);
|
|
249
252
|
});
|
|
@@ -265,7 +268,7 @@ const Map = react.forwardRef(({ id, mapTypeId = "normal", ncpKeyId, children, ma
|
|
|
265
268
|
Map.displayName = "Map";
|
|
266
269
|
|
|
267
270
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
268
|
-
const EVENT_TO_PROP$
|
|
271
|
+
const EVENT_TO_PROP$6 = {
|
|
269
272
|
click: "onClick",
|
|
270
273
|
position_changed: "onPositionChanged",
|
|
271
274
|
rightclick: "onRightclick",
|
|
@@ -291,7 +294,7 @@ const Marker = react.forwardRef((props, ref) => {
|
|
|
291
294
|
const options = {};
|
|
292
295
|
Object.keys(props).forEach((key) => {
|
|
293
296
|
const propKey = key;
|
|
294
|
-
if (Object.values(EVENT_TO_PROP$
|
|
297
|
+
if (Object.values(EVENT_TO_PROP$6).includes(propKey)) {
|
|
295
298
|
const value = props[propKey];
|
|
296
299
|
if (value !== undefined) {
|
|
297
300
|
eventProps[propKey] = value;
|
|
@@ -389,8 +392,8 @@ const Marker = react.forwardRef((props, ref) => {
|
|
|
389
392
|
const handlersRef = react.useRef({});
|
|
390
393
|
react.useEffect(() => {
|
|
391
394
|
const next = {};
|
|
392
|
-
Object.keys(EVENT_TO_PROP$
|
|
393
|
-
const propKey = EVENT_TO_PROP$
|
|
395
|
+
Object.keys(EVENT_TO_PROP$6).forEach((eventKey) => {
|
|
396
|
+
const propKey = EVENT_TO_PROP$6[eventKey];
|
|
394
397
|
const fn = eventProps[propKey];
|
|
395
398
|
if (typeof fn === "function")
|
|
396
399
|
next[eventKey] = fn;
|
|
@@ -401,7 +404,7 @@ const Marker = react.forwardRef((props, ref) => {
|
|
|
401
404
|
if (!instance)
|
|
402
405
|
return;
|
|
403
406
|
const disposers = [];
|
|
404
|
-
Object.keys(EVENT_TO_PROP$
|
|
407
|
+
Object.keys(EVENT_TO_PROP$6).forEach((eventKey) => {
|
|
405
408
|
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
406
409
|
handlersRef.current[eventKey]?.(...args);
|
|
407
410
|
});
|
|
@@ -511,47 +514,310 @@ const Overlay = ({ children, ...options }) => {
|
|
|
511
514
|
};
|
|
512
515
|
|
|
513
516
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
514
|
-
const
|
|
517
|
+
const EVENT_TO_PROP$5 = {
|
|
518
|
+
click: "onClick",
|
|
519
|
+
dblclick: "onDblclick",
|
|
520
|
+
rightclick: "onRightclick",
|
|
521
|
+
mousedown: "onMouseDown",
|
|
522
|
+
mouseup: "onMouseUp",
|
|
523
|
+
mouseover: "onMouseOver",
|
|
524
|
+
mouseout: "onMouseOut",
|
|
525
|
+
mouseenter: "onMouseEnter",
|
|
526
|
+
mouseleave: "onMouseLeave",
|
|
527
|
+
};
|
|
528
|
+
const Polygon = react.forwardRef((props, ref) => {
|
|
515
529
|
const { current: map } = useMap();
|
|
516
|
-
const [instance, setInstance] = react.useState(
|
|
517
|
-
const
|
|
530
|
+
const [instance, setInstance] = react.useState();
|
|
531
|
+
const eventProps = {};
|
|
532
|
+
const options = {};
|
|
533
|
+
Object.keys(props).forEach((key) => {
|
|
534
|
+
const propKey = key;
|
|
535
|
+
if (Object.values(EVENT_TO_PROP$5).includes(propKey)) {
|
|
536
|
+
const value = props[propKey];
|
|
537
|
+
if (value !== undefined) {
|
|
538
|
+
eventProps[propKey] = value;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
else {
|
|
542
|
+
const value = props[key];
|
|
543
|
+
if (value !== undefined) {
|
|
544
|
+
options[key] = value;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
});
|
|
518
548
|
react.useEffect(() => {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
549
|
+
if (!map)
|
|
550
|
+
return undefined;
|
|
551
|
+
const newInstance = new naver.maps.Polygon(options);
|
|
552
|
+
setInstance(newInstance);
|
|
553
|
+
newInstance.setMap(map);
|
|
554
|
+
return () => {
|
|
555
|
+
if (!map)
|
|
556
|
+
return;
|
|
557
|
+
newInstance.setMap(null);
|
|
522
558
|
};
|
|
523
|
-
}, [
|
|
559
|
+
}, [map]);
|
|
524
560
|
react.useEffect(() => {
|
|
525
561
|
if (!instance)
|
|
526
562
|
return;
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
563
|
+
instance.setOptions(options);
|
|
564
|
+
}, [instance, options]);
|
|
565
|
+
const handlersRef = react.useRef({});
|
|
566
|
+
react.useEffect(() => {
|
|
567
|
+
const next = {};
|
|
568
|
+
Object.keys(EVENT_TO_PROP$5).forEach((eventKey) => {
|
|
569
|
+
const propKey = EVENT_TO_PROP$5[eventKey];
|
|
570
|
+
const fn = eventProps[propKey];
|
|
571
|
+
if (typeof fn === "function")
|
|
572
|
+
next[eventKey] = fn;
|
|
532
573
|
});
|
|
574
|
+
handlersRef.current = next;
|
|
575
|
+
}, [eventProps]);
|
|
576
|
+
react.useEffect(() => {
|
|
577
|
+
if (!instance)
|
|
578
|
+
return;
|
|
579
|
+
const disposers = [];
|
|
580
|
+
Object.keys(EVENT_TO_PROP$5).forEach((eventKey) => {
|
|
581
|
+
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
582
|
+
handlersRef.current[eventKey]?.(...args);
|
|
583
|
+
});
|
|
584
|
+
disposers.push(() => naver.maps.Event.removeListener(listener));
|
|
585
|
+
});
|
|
586
|
+
return () => disposers.forEach((d) => d());
|
|
587
|
+
}, [instance]);
|
|
588
|
+
react.useImperativeHandle(ref, () => instance, [instance]);
|
|
589
|
+
return null;
|
|
590
|
+
});
|
|
591
|
+
Polygon.displayName = "Polygon";
|
|
592
|
+
|
|
593
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
594
|
+
const EVENT_TO_PROP$4 = {
|
|
595
|
+
click: "onClick",
|
|
596
|
+
dblclick: "onDblclick",
|
|
597
|
+
rightclick: "onRightclick",
|
|
598
|
+
mousedown: "onMouseDown",
|
|
599
|
+
mouseup: "onMouseUp",
|
|
600
|
+
mouseover: "onMouseOver",
|
|
601
|
+
mouseout: "onMouseOut",
|
|
602
|
+
mouseenter: "onMouseEnter",
|
|
603
|
+
mouseleave: "onMouseLeave",
|
|
604
|
+
};
|
|
605
|
+
const Polyline = react.forwardRef((props, ref) => {
|
|
606
|
+
const { current: map } = useMap();
|
|
607
|
+
const [instance, setInstance] = react.useState();
|
|
608
|
+
const eventProps = {};
|
|
609
|
+
const options = {};
|
|
610
|
+
Object.keys(props).forEach((key) => {
|
|
611
|
+
const propKey = key;
|
|
612
|
+
if (Object.values(EVENT_TO_PROP$4).includes(propKey)) {
|
|
613
|
+
const value = props[propKey];
|
|
614
|
+
if (value !== undefined) {
|
|
615
|
+
eventProps[propKey] = value;
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
const value = props[key];
|
|
620
|
+
if (value !== undefined) {
|
|
621
|
+
options[key] = value;
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
react.useEffect(() => {
|
|
626
|
+
if (!map)
|
|
627
|
+
return undefined;
|
|
628
|
+
const newInstance = new naver.maps.Polyline(options);
|
|
629
|
+
setInstance(newInstance);
|
|
630
|
+
newInstance.setMap(map);
|
|
533
631
|
return () => {
|
|
534
|
-
|
|
632
|
+
if (!map)
|
|
633
|
+
return;
|
|
634
|
+
newInstance.setMap(null);
|
|
535
635
|
};
|
|
636
|
+
}, [map]);
|
|
637
|
+
const handlersRef = react.useRef({});
|
|
638
|
+
react.useEffect(() => {
|
|
639
|
+
const next = {};
|
|
640
|
+
Object.keys(EVENT_TO_PROP$4).forEach((eventKey) => {
|
|
641
|
+
const propKey = EVENT_TO_PROP$4[eventKey];
|
|
642
|
+
const fn = eventProps[propKey];
|
|
643
|
+
if (typeof fn === "function")
|
|
644
|
+
next[eventKey] = fn;
|
|
645
|
+
});
|
|
646
|
+
handlersRef.current = next;
|
|
647
|
+
}, [eventProps]);
|
|
648
|
+
react.useEffect(() => {
|
|
649
|
+
if (!instance)
|
|
650
|
+
return;
|
|
651
|
+
const disposers = [];
|
|
652
|
+
Object.keys(EVENT_TO_PROP$4).forEach((eventKey) => {
|
|
653
|
+
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
654
|
+
handlersRef.current[eventKey]?.(...args);
|
|
655
|
+
});
|
|
656
|
+
disposers.push(() => naver.maps.Event.removeListener(listener));
|
|
657
|
+
});
|
|
658
|
+
return () => disposers.forEach((d) => d());
|
|
536
659
|
}, [instance]);
|
|
660
|
+
react.useImperativeHandle(ref, () => instance, [instance]);
|
|
661
|
+
return null;
|
|
662
|
+
});
|
|
663
|
+
Polyline.displayName = "Polyline";
|
|
664
|
+
|
|
665
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
666
|
+
const EVENT_TO_PROP$3 = {
|
|
667
|
+
click: "onClick",
|
|
668
|
+
dblclick: "onDblclick",
|
|
669
|
+
rightclick: "onRightclick",
|
|
670
|
+
mousedown: "onMouseDown",
|
|
671
|
+
mouseup: "onMouseUp",
|
|
672
|
+
mouseover: "onMouseOver",
|
|
673
|
+
mouseout: "onMouseOut",
|
|
674
|
+
mouseenter: "onMouseEnter",
|
|
675
|
+
mouseleave: "onMouseLeave",
|
|
676
|
+
};
|
|
677
|
+
const Rectangle = react.forwardRef((props, ref) => {
|
|
678
|
+
const { current: map } = useMap();
|
|
679
|
+
const [instance, setInstance] = react.useState();
|
|
680
|
+
const eventProps = {};
|
|
681
|
+
const options = {};
|
|
682
|
+
Object.keys(props).forEach((key) => {
|
|
683
|
+
const propKey = key;
|
|
684
|
+
if (Object.values(EVENT_TO_PROP$3).includes(propKey)) {
|
|
685
|
+
const value = props[propKey];
|
|
686
|
+
if (value !== undefined) {
|
|
687
|
+
eventProps[propKey] = value;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
const value = props[key];
|
|
692
|
+
if (value !== undefined) {
|
|
693
|
+
options[key] = value;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
});
|
|
537
697
|
react.useEffect(() => {
|
|
538
698
|
if (!map)
|
|
539
|
-
return;
|
|
540
|
-
const newInstance = new naver.maps.
|
|
541
|
-
newInstance.setMap(map);
|
|
699
|
+
return undefined;
|
|
700
|
+
const newInstance = new naver.maps.Rectangle(options);
|
|
542
701
|
setInstance(newInstance);
|
|
702
|
+
newInstance.setMap(map);
|
|
543
703
|
return () => {
|
|
704
|
+
if (!map)
|
|
705
|
+
return;
|
|
544
706
|
newInstance.setMap(null);
|
|
545
707
|
};
|
|
546
708
|
}, [map]);
|
|
547
709
|
react.useEffect(() => {
|
|
548
|
-
instance
|
|
549
|
-
|
|
710
|
+
if (!instance)
|
|
711
|
+
return;
|
|
712
|
+
instance.setOptions(options);
|
|
713
|
+
}, [instance, options]);
|
|
714
|
+
const handlersRef = react.useRef({});
|
|
715
|
+
react.useEffect(() => {
|
|
716
|
+
const next = {};
|
|
717
|
+
Object.keys(EVENT_TO_PROP$3).forEach((eventKey) => {
|
|
718
|
+
const propKey = EVENT_TO_PROP$3[eventKey];
|
|
719
|
+
const fn = eventProps[propKey];
|
|
720
|
+
if (typeof fn === "function")
|
|
721
|
+
next[eventKey] = fn;
|
|
722
|
+
});
|
|
723
|
+
handlersRef.current = next;
|
|
724
|
+
}, [eventProps]);
|
|
725
|
+
react.useEffect(() => {
|
|
726
|
+
if (!instance)
|
|
727
|
+
return;
|
|
728
|
+
const disposers = [];
|
|
729
|
+
Object.keys(EVENT_TO_PROP$3).forEach((eventKey) => {
|
|
730
|
+
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
731
|
+
handlersRef.current[eventKey]?.(...args);
|
|
732
|
+
});
|
|
733
|
+
disposers.push(() => naver.maps.Event.removeListener(listener));
|
|
734
|
+
});
|
|
735
|
+
return () => disposers.forEach((d) => d());
|
|
736
|
+
}, [instance]);
|
|
737
|
+
react.useImperativeHandle(ref, () => instance, [instance]);
|
|
550
738
|
return null;
|
|
739
|
+
});
|
|
740
|
+
Rectangle.displayName = "Rectangle";
|
|
741
|
+
|
|
742
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
743
|
+
const EVENT_TO_PROP$2 = {
|
|
744
|
+
click: "onClick",
|
|
745
|
+
dblclick: "onDblclick",
|
|
746
|
+
rightclick: "onRightclick",
|
|
747
|
+
mousedown: "onMouseDown",
|
|
748
|
+
mouseup: "onMouseUp",
|
|
749
|
+
mouseover: "onMouseOver",
|
|
750
|
+
mouseout: "onMouseOut",
|
|
751
|
+
mouseenter: "onMouseEnter",
|
|
752
|
+
mouseleave: "onMouseLeave",
|
|
551
753
|
};
|
|
754
|
+
const Circle = react.forwardRef((props, ref) => {
|
|
755
|
+
const { current: map } = useMap();
|
|
756
|
+
const [instance, setInstance] = react.useState();
|
|
757
|
+
const eventProps = {};
|
|
758
|
+
const options = {};
|
|
759
|
+
Object.keys(props).forEach((key) => {
|
|
760
|
+
const propKey = key;
|
|
761
|
+
if (Object.values(EVENT_TO_PROP$2).includes(propKey)) {
|
|
762
|
+
const value = props[propKey];
|
|
763
|
+
if (value !== undefined) {
|
|
764
|
+
eventProps[propKey] = value;
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
else {
|
|
768
|
+
const value = props[key];
|
|
769
|
+
if (value !== undefined) {
|
|
770
|
+
options[key] = value;
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
});
|
|
774
|
+
react.useEffect(() => {
|
|
775
|
+
if (!map)
|
|
776
|
+
return undefined;
|
|
777
|
+
const newInstance = new naver.maps.Circle(options);
|
|
778
|
+
setInstance(newInstance);
|
|
779
|
+
newInstance.setMap(map);
|
|
780
|
+
return () => {
|
|
781
|
+
if (!map)
|
|
782
|
+
return;
|
|
783
|
+
newInstance.setMap(null);
|
|
784
|
+
};
|
|
785
|
+
}, [map]);
|
|
786
|
+
react.useEffect(() => {
|
|
787
|
+
if (!instance)
|
|
788
|
+
return;
|
|
789
|
+
instance.setOptions(options);
|
|
790
|
+
}, [instance, options]);
|
|
791
|
+
const handlersRef = react.useRef({});
|
|
792
|
+
react.useEffect(() => {
|
|
793
|
+
const next = {};
|
|
794
|
+
Object.keys(EVENT_TO_PROP$2).forEach((eventKey) => {
|
|
795
|
+
const propKey = EVENT_TO_PROP$2[eventKey];
|
|
796
|
+
const fn = eventProps[propKey];
|
|
797
|
+
if (typeof fn === "function")
|
|
798
|
+
next[eventKey] = fn;
|
|
799
|
+
});
|
|
800
|
+
handlersRef.current = next;
|
|
801
|
+
}, [eventProps]);
|
|
802
|
+
react.useEffect(() => {
|
|
803
|
+
if (!instance)
|
|
804
|
+
return;
|
|
805
|
+
const disposers = [];
|
|
806
|
+
Object.keys(EVENT_TO_PROP$2).forEach((eventKey) => {
|
|
807
|
+
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
808
|
+
handlersRef.current[eventKey]?.(...args);
|
|
809
|
+
});
|
|
810
|
+
disposers.push(() => naver.maps.Event.removeListener(listener));
|
|
811
|
+
});
|
|
812
|
+
return () => disposers.forEach((d) => d());
|
|
813
|
+
}, [instance]);
|
|
814
|
+
react.useImperativeHandle(ref, () => instance, [instance]);
|
|
815
|
+
return null;
|
|
816
|
+
});
|
|
817
|
+
Circle.displayName = "Circle";
|
|
552
818
|
|
|
553
819
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
554
|
-
const EVENT_TO_PROP = {
|
|
820
|
+
const EVENT_TO_PROP$1 = {
|
|
555
821
|
click: "onClick",
|
|
556
822
|
dblclick: "onDblclick",
|
|
557
823
|
rightclick: "onRightclick",
|
|
@@ -562,14 +828,14 @@ const EVENT_TO_PROP = {
|
|
|
562
828
|
mouseenter: "onMouseEnter",
|
|
563
829
|
mouseleave: "onMouseLeave",
|
|
564
830
|
};
|
|
565
|
-
const
|
|
831
|
+
const Ellipse = react.forwardRef((props, ref) => {
|
|
566
832
|
const { current: map } = useMap();
|
|
567
833
|
const [instance, setInstance] = react.useState();
|
|
568
834
|
const eventProps = {};
|
|
569
835
|
const options = {};
|
|
570
836
|
Object.keys(props).forEach((key) => {
|
|
571
837
|
const propKey = key;
|
|
572
|
-
if (Object.values(EVENT_TO_PROP).includes(propKey)) {
|
|
838
|
+
if (Object.values(EVENT_TO_PROP$1).includes(propKey)) {
|
|
573
839
|
const value = props[propKey];
|
|
574
840
|
if (value !== undefined) {
|
|
575
841
|
eventProps[propKey] = value;
|
|
@@ -585,7 +851,7 @@ const Polyline = react.forwardRef((props, ref) => {
|
|
|
585
851
|
react.useEffect(() => {
|
|
586
852
|
if (!map)
|
|
587
853
|
return undefined;
|
|
588
|
-
const newInstance = new naver.maps.
|
|
854
|
+
const newInstance = new naver.maps.Ellipse(options);
|
|
589
855
|
setInstance(newInstance);
|
|
590
856
|
newInstance.setMap(map);
|
|
591
857
|
return () => {
|
|
@@ -594,11 +860,16 @@ const Polyline = react.forwardRef((props, ref) => {
|
|
|
594
860
|
newInstance.setMap(null);
|
|
595
861
|
};
|
|
596
862
|
}, [map]);
|
|
863
|
+
react.useEffect(() => {
|
|
864
|
+
if (!instance)
|
|
865
|
+
return;
|
|
866
|
+
instance.setOptions(options);
|
|
867
|
+
}, [instance, options]);
|
|
597
868
|
const handlersRef = react.useRef({});
|
|
598
869
|
react.useEffect(() => {
|
|
599
870
|
const next = {};
|
|
600
|
-
Object.keys(EVENT_TO_PROP).forEach((eventKey) => {
|
|
601
|
-
const propKey = EVENT_TO_PROP[eventKey];
|
|
871
|
+
Object.keys(EVENT_TO_PROP$1).forEach((eventKey) => {
|
|
872
|
+
const propKey = EVENT_TO_PROP$1[eventKey];
|
|
602
873
|
const fn = eventProps[propKey];
|
|
603
874
|
if (typeof fn === "function")
|
|
604
875
|
next[eventKey] = fn;
|
|
@@ -609,7 +880,7 @@ const Polyline = react.forwardRef((props, ref) => {
|
|
|
609
880
|
if (!instance)
|
|
610
881
|
return;
|
|
611
882
|
const disposers = [];
|
|
612
|
-
Object.keys(EVENT_TO_PROP).forEach((eventKey) => {
|
|
883
|
+
Object.keys(EVENT_TO_PROP$1).forEach((eventKey) => {
|
|
613
884
|
const listener = naver.maps.Event.addListener(instance, eventKey, (...args) => {
|
|
614
885
|
handlersRef.current[eventKey]?.(...args);
|
|
615
886
|
});
|
|
@@ -620,13 +891,124 @@ const Polyline = react.forwardRef((props, ref) => {
|
|
|
620
891
|
react.useImperativeHandle(ref, () => instance, [instance]);
|
|
621
892
|
return null;
|
|
622
893
|
});
|
|
623
|
-
|
|
894
|
+
Ellipse.displayName = "Ellipse";
|
|
895
|
+
|
|
896
|
+
const EVENT_TO_PROP = {
|
|
897
|
+
addfeature: "onAddFeature",
|
|
898
|
+
removefeature: "onRemoveFeature",
|
|
899
|
+
setfeature: "onSetFeature",
|
|
900
|
+
setgeometry: "onSetGeometry",
|
|
901
|
+
setproperty: "onSetProperty",
|
|
902
|
+
removeproperty: "onRemoveProperty",
|
|
903
|
+
click: "onClick",
|
|
904
|
+
dblclick: "onDblclick",
|
|
905
|
+
rightclick: "onRightclick",
|
|
906
|
+
mousedown: "onMouseDown",
|
|
907
|
+
mouseup: "onMouseUp",
|
|
908
|
+
mouseover: "onMouseOver",
|
|
909
|
+
mouseout: "onMouseOut",
|
|
910
|
+
mousemove: "onMouseMove",
|
|
911
|
+
};
|
|
912
|
+
const DataLayer = ({ type, url, autoStyle = true, style, onLoad, onError, ...eventProps }) => {
|
|
913
|
+
const { current: map } = useMap();
|
|
914
|
+
const [layer, setLayer] = react.useState();
|
|
915
|
+
const cleanUpFeatures = react.useMemo(() => {
|
|
916
|
+
return (target) => {
|
|
917
|
+
target.getAllFeature().forEach((feature) => {
|
|
918
|
+
target.removeFeature(feature);
|
|
919
|
+
});
|
|
920
|
+
};
|
|
921
|
+
}, []);
|
|
922
|
+
react.useEffect(() => {
|
|
923
|
+
if (!map)
|
|
924
|
+
return;
|
|
925
|
+
const newLayer = new naver.maps.Data();
|
|
926
|
+
newLayer.setMap(map);
|
|
927
|
+
setLayer(newLayer);
|
|
928
|
+
return () => {
|
|
929
|
+
newLayer.setMap(null);
|
|
930
|
+
setLayer(undefined);
|
|
931
|
+
};
|
|
932
|
+
}, [map]);
|
|
933
|
+
react.useEffect(() => {
|
|
934
|
+
if (!layer)
|
|
935
|
+
return;
|
|
936
|
+
const controller = new AbortController();
|
|
937
|
+
const load = async () => {
|
|
938
|
+
try {
|
|
939
|
+
cleanUpFeatures(layer);
|
|
940
|
+
const response = await fetch(url, { signal: controller.signal });
|
|
941
|
+
if (!response.ok) {
|
|
942
|
+
throw new Error(`Failed to fetch data layer: ${response.status}`);
|
|
943
|
+
}
|
|
944
|
+
if (type === "geojson") {
|
|
945
|
+
const geojson = (await response.json());
|
|
946
|
+
if (!controller.signal.aborted) {
|
|
947
|
+
layer.addGeoJson(geojson, autoStyle);
|
|
948
|
+
onLoad?.(layer);
|
|
949
|
+
}
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
const text = await response.text();
|
|
953
|
+
if (controller.signal.aborted)
|
|
954
|
+
return;
|
|
955
|
+
const xml = new DOMParser().parseFromString(text, "text/xml");
|
|
956
|
+
if (type === "gpx")
|
|
957
|
+
layer.addGpx(xml, autoStyle);
|
|
958
|
+
if (type === "kml")
|
|
959
|
+
layer.addKml(xml, autoStyle);
|
|
960
|
+
onLoad?.(layer);
|
|
961
|
+
}
|
|
962
|
+
catch (error) {
|
|
963
|
+
if (controller.signal.aborted)
|
|
964
|
+
return;
|
|
965
|
+
onError?.(error);
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
load();
|
|
969
|
+
return () => controller.abort();
|
|
970
|
+
}, [layer, type, url, autoStyle, cleanUpFeatures, onLoad, onError]);
|
|
971
|
+
react.useEffect(() => {
|
|
972
|
+
if (!layer || style === undefined)
|
|
973
|
+
return;
|
|
974
|
+
layer.setStyle(style);
|
|
975
|
+
}, [layer, style]);
|
|
976
|
+
const handlersRef = react.useRef({});
|
|
977
|
+
react.useEffect(() => {
|
|
978
|
+
const next = {};
|
|
979
|
+
Object.keys(EVENT_TO_PROP).forEach((eventKey) => {
|
|
980
|
+
const propKey = EVENT_TO_PROP[eventKey];
|
|
981
|
+
const fn = eventProps[propKey];
|
|
982
|
+
if (typeof fn === "function") {
|
|
983
|
+
next[eventKey] = fn;
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
handlersRef.current = next;
|
|
987
|
+
}, [eventProps]);
|
|
988
|
+
react.useEffect(() => {
|
|
989
|
+
if (!layer)
|
|
990
|
+
return;
|
|
991
|
+
const disposers = [];
|
|
992
|
+
Object.keys(EVENT_TO_PROP).forEach((eventKey) => {
|
|
993
|
+
const listener = naver.maps.Event.addListener(layer, eventKey, (...args) => {
|
|
994
|
+
handlersRef.current[eventKey]?.(...args);
|
|
995
|
+
});
|
|
996
|
+
disposers.push(() => naver.maps.Event.removeListener(listener));
|
|
997
|
+
});
|
|
998
|
+
return () => disposers.forEach((d) => d());
|
|
999
|
+
}, [layer]);
|
|
1000
|
+
return null;
|
|
1001
|
+
};
|
|
624
1002
|
|
|
1003
|
+
exports.Circle = Circle;
|
|
1004
|
+
exports.DataLayer = DataLayer;
|
|
1005
|
+
exports.Ellipse = Ellipse;
|
|
625
1006
|
exports.Map = Map;
|
|
626
1007
|
exports.MapProvider = MapProvider;
|
|
627
1008
|
exports.Marker = Marker;
|
|
628
1009
|
exports.Overlay = Overlay;
|
|
629
1010
|
exports.Polygon = Polygon;
|
|
630
1011
|
exports.Polyline = Polyline;
|
|
1012
|
+
exports.Rectangle = Rectangle;
|
|
631
1013
|
exports.useMap = useMap;
|
|
632
1014
|
//# sourceMappingURL=index.js.map
|