Skip to content

Commit

Permalink
feat(Rectangle): add Rectangle Component
Browse files Browse the repository at this point in the history
  • Loading branch information
Dongkyuuuu committed Sep 27, 2021
1 parent 3879aac commit 68c1fa2
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 4 deletions.
24 changes: 22 additions & 2 deletions playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
:initLayers="initLayers"
@onLoad="loadMap($event)"
>
<naver-ellipse
<naver-rectangle
:bounds="rectangleBounds"
@onLoad="loadRectangle($event)"
></naver-rectangle>
<!-- <naver-ellipse
:bounds="ellipseBounds"
@onLoad="loadEllpise($event)"
></naver-ellipse>
></naver-ellipse> -->
<!-- <naver-circle
:latitude="37.566616443521745"
:longitude="126.97837068565364"
Expand Down Expand Up @@ -50,6 +54,7 @@ import {
NaverInfoWindow,
NaverCircle,
NaverEllipse,
NaverRectangle,
} from "../dist/vue3-naver-maps";
export default defineComponent({
Expand All @@ -59,6 +64,7 @@ export default defineComponent({
NaverInfoWindow,
NaverCircle,
NaverEllipse,
NaverRectangle,
},
name: "App",
setup: (props, { emit }) => {
Expand All @@ -73,6 +79,13 @@ export default defineComponent({
west: 126.97837068565364,
east: 127.97837068565364,
});
const rectangle = ref<naver.maps.Rectangle>();
const rectangleBounds = ref<naver.maps.BoundsLiteral>({
south: 37.566616443521745,
north: 38.566616443521745,
west: 126.97837068565364,
east: 127.97837068565364,
});
const infoWindowOptions = ref<naver.maps.InfoWindowOptions>();
const isOpen = ref<boolean>(false);
const mapSize = reactive({
Expand Down Expand Up @@ -112,6 +125,10 @@ export default defineComponent({
ellipse.value = ellpiseObject;
console.log(ellipse.value);
};
const loadRectangle = (rectangleObject: naver.maps.Rectangle) => {
rectangle.value = rectangleObject;
console.log(rectangle.value);
};
const openInfoWindow = () => {
// console.log("openAction: ", infoWindow.value);
Expand Down Expand Up @@ -150,6 +167,9 @@ export default defineComponent({
ellipse,
ellipseBounds,
loadEllpise,
rectangle,
rectangleBounds,
loadRectangle,
};
},
});
Expand Down
63 changes: 63 additions & 0 deletions src/components/Rectangle.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template></template>

<script lang="ts">
import {
defineComponent,
PropType,
inject,
ref,
toRefs,
onMounted,
onUnmounted,
watchEffect,
} from "vue";
import { naverMapObject } from "../injectionKeys";
import { UI_EVENT_RECTANGLE, addEventRectangle } from "../utils";
export default defineComponent({
name: "Rectangle",
emits: [...UI_EVENT_RECTANGLE, "onLoad"],
props: {
bounds: {
type: Object as PropType<naver.maps.Bounds | naver.maps.BoundsLiteral>,
required: true,
},
options: {
type: Object as PropType<naver.maps.RectangleOptions>,
default: {},
},
},
setup: (props, { emit }) => {
const map = inject(naverMapObject)!;
const rectangle = ref<naver.maps.Rectangle>();
const { bounds, options } = toRefs(props);
const createRectangle = () => {
rectangle.value = new window.naver.maps.Rectangle(
Object.assign(
{
map: map.value!,
bounds: bounds.value,
},
options.value
)
);
addEventRectangle(emit, rectangle.value);
emit("onLoad", rectangle.value);
};
const setRectangle = (newOptions: naver.maps.RectangleOptions) => {
rectangle.value!.setOptions(newOptions);
};
onMounted(() => {
watchEffect(() => {
const newOptions = options.value;
if (!map.value) return;
rectangle.value ? setRectangle(newOptions) : createRectangle();
});
});
onUnmounted(() => rectangle.value!.setMap(null));
},
});
</script>
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@ import NaverMarker from "./components/Marker.vue";
import NaverInfoWindow from "./components/InfoWindow.vue";
import NaverCircle from "./components/Circle.vue";
import NaverEllipse from "./components/Ellipse.vue";
import NaverRectangle from "./components/Rectangle.vue";

// export * from "./apis";
export { naverV3 } from "./types";

/**
* Export Components
*/
export { NaverMaps, NaverMarker, NaverInfoWindow, NaverCircle, NaverEllipse };
export {
NaverMaps,
NaverMarker,
NaverInfoWindow,
NaverCircle,
NaverEllipse,
NaverRectangle,
};

export default install;
5 changes: 5 additions & 0 deletions src/utils/eventAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
UI_EVENT_INFOWINDOW,
UI_EVENT_CIRCLE,
UI_EVENT_ELLIPSE,
UI_EVENT_RECTANGLE,
} from "./eventList";

export function addEvent(emit: any, target: any, name: string) {
Expand Down Expand Up @@ -31,3 +32,7 @@ export function addEventCircle(emit: any, target: naver.maps.Circle) {
export function addEventEllipse(emit: any, target: naver.maps.Ellipse) {
UI_EVENT_ELLIPSE.forEach((name) => addEvent(emit, target, name));
}

export function addEventRectangle(emit: any, target: naver.maps.Rectangle) {
UI_EVENT_RECTANGLE.forEach((name) => addEvent(emit, target, name));
}
18 changes: 17 additions & 1 deletion src/utils/eventList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export const UI_EVENT_CIRCLE = [
];

/**
* Naver Circle UI Event
* Naver Ellipse UI Event
*/
export const UI_EVENT_ELLIPSE = [
"bounds_changed",
Expand All @@ -118,3 +118,19 @@ export const UI_EVENT_ELLIPSE = [
"visible_changed",
"zIndex_changed",
];

/**
* Naver Rectangle UI Event
*/
export const UI_EVENT_RECTANGLE = [
"bounds_changed",
"click",
"clickable_changed",
"dblclick",
"mousedown",
"mouseout",
"mouseover",
"mouseup",
"visible_changed",
"zIndex_changed",
];

0 comments on commit 68c1fa2

Please sign in to comment.