Add info window component
This commit is contained in:
3
components/InfoWindow.vue
Normal file
3
components/InfoWindow.vue
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<slot></slot>
|
||||||
|
</template>
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>marker</div>
|
<div ref="markerRef" >
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { inject } from "vue";
|
import {inject, ref} from "vue";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: {
|
props: {
|
||||||
@@ -19,6 +21,8 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup(props) {
|
setup(props) {
|
||||||
|
const markerRef = ref();
|
||||||
|
|
||||||
const mapPromise = inject(
|
const mapPromise = inject(
|
||||||
"mapPromise"
|
"mapPromise"
|
||||||
);
|
);
|
||||||
@@ -26,8 +30,6 @@ export default {
|
|||||||
if (mapPromise) {
|
if (mapPromise) {
|
||||||
mapPromise.then((googleMap) => {
|
mapPromise.then((googleMap) => {
|
||||||
const infoWindow = new google.maps.InfoWindow();
|
const infoWindow = new google.maps.InfoWindow();
|
||||||
console.log(props.location.lat)
|
|
||||||
console.log(props.location.lng)
|
|
||||||
const options = {
|
const options = {
|
||||||
position: new google.maps.LatLng(
|
position: new google.maps.LatLng(
|
||||||
props.location.lat,
|
props.location.lat,
|
||||||
@@ -43,12 +45,17 @@ export default {
|
|||||||
...options,
|
...options,
|
||||||
});
|
});
|
||||||
marker.addListener("click", (event) => {
|
marker.addListener("click", (event) => {
|
||||||
infoWindow.setContent(props.infoWindow);
|
infoWindow.setContent(markerRef.value.innerHTML);
|
||||||
infoWindow.open(googleMap, marker);
|
infoWindow.open(googleMap, marker);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
markerRef,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
2
index.js
2
index.js
@@ -3,6 +3,7 @@ import Marker from './components/Marker'
|
|||||||
import Circle from './components/Circle'
|
import Circle from './components/Circle'
|
||||||
import Polygon from './components/Polygon'
|
import Polygon from './components/Polygon'
|
||||||
import Rectangle from './components/Rectangle'
|
import Rectangle from './components/Rectangle'
|
||||||
|
import InfoWindow from './components/InfoWindow'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
install: (app, options) => {
|
install: (app, options) => {
|
||||||
@@ -11,6 +12,7 @@ export default {
|
|||||||
app.component('Circle', Circle)
|
app.component('Circle', Circle)
|
||||||
app.component('Polygon', Polygon)
|
app.component('Polygon', Polygon)
|
||||||
app.component('Rectangle', Rectangle)
|
app.component('Rectangle', Rectangle)
|
||||||
|
app.component('InfoWindow', InfoWindow)
|
||||||
app.provide('apiKey', options.apiKey)
|
app.provide('apiKey', options.apiKey)
|
||||||
app.provide('mapIds', options.mapIds)
|
app.provide('mapIds', options.mapIds)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user