-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(polygon): add Polygon Component
- Loading branch information
1 parent
12b7361
commit 772c880
Showing
5 changed files
with
116 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<template></template> | ||
|
||
<script lang="ts"> | ||
import { | ||
defineComponent, | ||
PropType, | ||
inject, | ||
ref, | ||
toRefs, | ||
onMounted, | ||
onUnmounted, | ||
watchEffect, | ||
} from "vue"; | ||
import { naverMapObject } from "../injectionKeys"; | ||
import { UI_EVENT_POLYGON, addEventPolygon } from "../utils"; | ||
export default defineComponent({ | ||
name: "Polygon", | ||
emits: [...UI_EVENT_POLYGON, "onLoad"], | ||
props: { | ||
paths: { | ||
type: Array as PropType< | ||
| naver.maps.ArrayOfCoords | ||
| naver.maps.KVOArrayOfCoords | ||
| naver.maps.ArrayOfCoordsLiteral | ||
>, | ||
required: true, | ||
}, | ||
options: { | ||
type: Object as PropType<naver.maps.PolygonOptions>, | ||
default: {}, | ||
}, | ||
}, | ||
setup: (props, { emit }) => { | ||
const map = inject(naverMapObject)!; | ||
const polygon = ref<naver.maps.Polygon>(); | ||
const { options, paths } = toRefs(props); | ||
const createPolygon = () => { | ||
polygon.value = new window.naver.maps.Polygon( | ||
Object.assign( | ||
{ | ||
map: map.value, | ||
paths: paths.value, | ||
}, | ||
options.value | ||
) | ||
); | ||
addEventPolygon(emit, polygon.value); | ||
emit("onLoad", polygon.value); | ||
}; | ||
const setPolygon = (newOptions: naver.maps.PolygonOptions) => { | ||
polygon.value!.setOptions(newOptions); | ||
}; | ||
onMounted(() => { | ||
watchEffect(() => { | ||
const newOptions = options.value; | ||
if (!map.value) return; | ||
polygon.value ? setPolygon(newOptions) : createPolygon(); | ||
}); | ||
}); | ||
onUnmounted(() => polygon.value!.setMap(null)); | ||
}, | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters