longdo-map-vue
v3.1.1
Published
Longdo Map component for Vue.js
Downloads
499
Readme
Installation
You can easily install by using npm
npm i longdo-map-vue
Usage
First, you need to get a Longdo Map API key. Then, after you have Longdo Map API key and component installed, you need to register it to your Vue project.
There are two ways of registering component:
Register component globally
This is a recommended way of registering component
In your main.js
or similar file:
import { createApp } from 'vue'
import App from './App.vue'
import LongdoMap from 'longdo-map-vue'
createApp(App)
.use(LongdoMap, {
load: {
apiKey: 'YOUR_LONGDO_MAP_API_KEY',
}
})
.mount('#app')
Then you can use <longdo-map />
in your component template.
<template>
<longdo-map />
</template>
Register component locally
In your component file, for example Foo.vue
:
<script setup>
import { LongdoMapLoad, LongdoMap } from 'longdo-map-vue'
LongdoMapLoad({
apiKey: 'YOUR_LONGDO_MAP_API_KEY',
})
</script>
<template>
<longdo-map />
</template>
You can import more components if you want, for example:
import { LongdoMapLoad, LongdoMap, LongdoMapMarker, LongdoMapPolyline } from 'longdo-map-vue'
Examples
Add a polygon to Longdo Map:
<script setup>
const locationList = [
{ lon: 99, lat: 14 },
{ lon: 100, lat: 13 },
{ lon: 102, lat: 13 },
{ lon: 103, lat: 14 }
]
</script>
<template>
<longdo-map>
<longdo-map-polygon
:location="locationList"
:lineWidth="2"
:lineColor="'rgba(0, 0, 0, 1)'"
:fillColor="'rgba(255, 0, 0, 0.4)'"
/>
</longdo-map>
</template>
Add multiple markers to Longdo Map:
<template>
<longdo-map :zoom="10" :last-view="false">
<longdo-map-marker
v-for="(item, i) in markers"
:key="i"
:location="item.location"
:title="item.title"
:detail="item.detail"
/>
</longdo-map>
</template>
Using Longdo Map object:
<script setup>
function loadMap(map) {
map.Layers.setBase(longdo.Layers.NORMAL)
}
function addMarker(marker) {
console.log(marker.location())
}
</script>
<template>
<longdo-map @load="loadMap">
<longdo-map-marker @add="addMarker" :location="{ lon: 99, lat: 14 }" />
</longdo-map>
</template>
Components
- longdo-map
- longdo-map-marker
- longdo-map-dot
- longdo-map-circle
- longdo-map-rectangle
- longdo-map-polyline
- longdo-map-polycurve
- longdo-map-polygon
Map
- Props
- Event:
@load="Function(object)"
<longdo-map :zoom="10" :last-view="false" />
Overlay
- Props
- Event:
@add="Function(object)"
<longdo-map>
<longdo-map-marker :location="{ lon: 99, lat: 14 }" :title="'Home'" :detail="'My home'" />
</longdo-map>
Geometry
longdo-map-dot
, longdo-map-circle
, longdo-map-rectangle
, longdo-map-polyline
, longdo-map-polycurve
, longdo-map-polygon
- Props
- Event:
@add="Function(object)"
<longdo-map>
<longdo-map-polygon
:location="[{ lon: 100.123, lat: 13.579 }, ...]"
:lineWidth="2"
:lineColor="'rgba(0, 0, 0, 1)'"
:fillColor="'rgba(255, 0, 0, 0.4)'"
/>
</longdo-map>