vue-yandex-maps
vue-yandex-maps is a plugin for vue.js that adds yandex-map custom element.
Install
npm install vue-yandex-maps --save
CommonJS
You can use any build tool which supports commonjs
:
// register globally
const YmapPlugin = require('vue-yandex-maps');
Vue.use(YmapPlugin)
// or for a single instance
const { yandexMap, ymapMarker } = require('vue-yandex-maps');
new Vue({
components: { yandexMap, ymapMarker }
})
Or in ES2015:
// register globally
import YmapPlugin from 'vue-yandex-maps'
Vue.use(YmapPlugin)
// or for a single instance
import { yandexMap, ymapMarker } from 'vue-yandex-maps'
new Vue({
components: { yandexMap, ymapMarker }
})
Usage
Use <yandex-map>
tag to enable the map instance and use attributes to define map options.
You may define placemarks on your map by using <ymap-marker>
tag or set an array of objects with placemark options through <yandex-map>
attribute placemarks
. You also can use both methods together.
The Map instance rerender when changed link on array with markers in placemarks
property or marker coordinates if marker is a component.
Type of marker in marker-type
attribute can be:
- Placemark
- Polyline
- Rectangle
- Polygon
- Circle
<yandex-map
:coords="[54.62896654088406, 39.731893822753904]"
zoom="10"
style="width: 600px; height: 600px;"
:cluster-options="{
1: {clusterDisableClickZoom: true}
}"
:behaviors="['ruler']"
:controls="['trafficControl']"
:placemarks="placemarks" //
map-type="hybrid"
@map-was-initialized="initHandler"
>
<ymap-marker
marker-type="placemark"
:coords="[54.7, 39.7]"
hint-content="Hint content 1"
:balloon="{header: 'header', body: 'body', footer: 'footer'}"
:icon="{color: 'green', glyph: 'cinema'}"
cluster-name="1"
></ymap-marker>
<ymap-marker
marker-type="placemark"
:coords="[54.6, 39.8]"
hint-content="Hint content 1"
:balloon="{header: 'header', body: 'body', footer: 'footer'}"
:icon="{color: 'green', glyph: 'cinema'}"
cluster-name="1"
></ymap-marker>
<ymap-marker
marker-type="circle"
:coords="[54.62896654088406, 39.731893822753904]"
circle-radius="1600"
hint-content="Hint content 1"
:marker-fill="{color: '#000000', opacity: 0.4}"
:marker-stroke="{color: '#ff0000', width: 5}"
:balloon="{header: 'header', body: 'body', footer: 'footer'}"
></ymap-marker>
</yandex-map>
data() {
return {
placemarks: [
{
coords: [54.8, 39.8],
properties: {}, // define properties here
options: {}, // define options here
clusterName: "1",
callbacks: { click: function() {} }
}
]
}
}