Add marker popups

This commit is contained in:
Emanuel Mutschlechner
2020-01-06 20:43:43 +01:00
parent d3a34d0326
commit 3a2d2e2368
14 changed files with 485 additions and 163 deletions

View File

@@ -1,7 +1,10 @@
import {fadeElementIn, isDefined, logError, openUrl} from '../utils/helper';
import {dispatchEventMarkerClicked} from '../utils/dispatchEvent';
const name = 'google';
export default {
NAME: 'google',
name,
createMap(element, mapData) {
if (!isDefined(window.google)) {
logError('google is undefined');
@@ -26,8 +29,8 @@ export default {
return map;
},
createMarker(map, markerData) {
const {title, lat, lng, url, icon, iconSize, iconAnchor} = markerData;
createMarker(element, map, markerData) {
const {title, lat, lng, url, popup, icon, iconSize, iconAnchor} = markerData;
const markerOptions = {
position: new window.google.maps.LatLng(lat, lng),
@@ -50,11 +53,17 @@ export default {
const marker = new window.google.maps.Marker(markerOptions);
if (url) {
marker.addListener('click', () => {
marker.addListener('click', () => {
dispatchEventMarkerClicked(name, element, map, marker);
if (popup) {
const infoWindow = new window.google.maps.InfoWindow({
content: popup
});
infoWindow.open(map, marker);
} else if (url) {
openUrl(url);
});
}
}
});
return marker;
},