Merge pull request #62 from hansvn/bugfix/47-map-events
Add the option to add custom Google Maps events
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="vue-map-container">
|
<div class="vue-map-container" :class="$attrs.class">
|
||||||
<div ref="vue-map" class="vue-map"></div>
|
<div ref="vue-map" class="vue-map"></div>
|
||||||
<div class="vue-map-hidden">
|
<div class="vue-map-hidden">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
@@ -103,7 +103,8 @@ const customMethods = {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [mountableMixin],
|
mixins: [mountableMixin],
|
||||||
props: mappedPropsToVueProps(props),
|
props: mappedPropsToVueProps({...props, ...events.reduce((obj, eventName) => ({...obj, [`on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`.replace(/[-_]+(.)?/g, (_, c) => c ? c.toUpperCase() : '')]: Function}), {}) } ),
|
||||||
|
inheritAttrs: false,
|
||||||
|
|
||||||
provide() {
|
provide() {
|
||||||
this.$mapPromise = new Promise((resolve, reject) => {
|
this.$mapPromise = new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
export default (vueInst, googleMapsInst, events) => {
|
export default (vueInst, googleMapsInst, events) => {
|
||||||
for (let eventName of events) {
|
for (let eventName of events) {
|
||||||
if (vueInst.$gmapOptions.autobindAllEvents || vueInst.$attrs[eventName]) {
|
const propName = `on${eventName.charAt(0).toUpperCase()}${eventName.slice(1)}`.replace(/[-_]+(.)?/g, (_, c) => c ? c.toUpperCase() : '');
|
||||||
|
|
||||||
|
if (vueInst.$props[propName] || vueInst.$attrs[propName]) {
|
||||||
|
googleMapsInst.addListener(eventName, (ev) => {
|
||||||
|
vueInst.$emit(eventName, ev)
|
||||||
|
})
|
||||||
|
} else if (vueInst.$gmapOptions.autobindAllEvents || vueInst.$attrs[eventName]) {
|
||||||
googleMapsInst.addListener(eventName, (ev) => {
|
googleMapsInst.addListener(eventName, (ev) => {
|
||||||
vueInst.$emit(eventName, ev)
|
vueInst.$emit(eventName, ev)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user