Skip to content

Instantly share code, notes, and snippets.

@ggondim
Last active July 2, 2020 19:24
Show Gist options
  • Save ggondim/7480e18c29b38120e0e507c3fe6371c7 to your computer and use it in GitHub Desktop.
Save ggondim/7480e18c29b38120e0e507c3fe6371c7 to your computer and use it in GitHub Desktop.
vue2-google-maps custom control
<template>
<div :id="id">
<slot>
CustomControl
</slot>
</div>
</template>
<script>
import { MapElementFactory } from 'vue2-google-maps';
class CustomControl {
constructor({ map, position, id }) {
this.map = map;
this.position = position;
this.id = id;
}
setOptions() {}
}
const GMapCustomControl = MapElementFactory({
name: 'customControl',
ctr: () => CustomControl,
events: [],
mappedProps: {
options: { type: Object },
},
props: {
position: { type: String, default: 'TOP_CENTER' },
id: { type: String, default: (Date.now().toString()) }
},
beforeCreate(options) {
// eslint-disable-next-line no-param-reassign
options.position = this.position;
options.id = this.id;
},
afterCreate({ map, position, id }, opts) {
const element = document.getElementById(id);
const pos = google.maps.ControlPosition[position];
map.controls[pos].push(element);
},
});
export default {
extends: GMapCustomControl,
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment