Skip to content

Instantly share code, notes, and snippets.

@FWSimon
Created March 22, 2016 13:12
Show Gist options
  • Save FWSimon/5ed0af62765e8f1151de to your computer and use it in GitHub Desktop.
Save FWSimon/5ed0af62765e8f1151de to your computer and use it in GitHub Desktop.
const VueGoogleMap = require('vue-google-maps');
module.exports = {
components: {
'google-map': VueGoogleMap.Map,
},
data: function () {
return {
};
},
props: {
center: {
type: Boolean,
default: false,
twoWay: true
}
},
ready: function () {
var langPrefix = $('#langPrefix').val(); //Get the Landcode from the hidden element in main template
var mapCoordinates;
//We check if the URL is dk or pl and center the map to the right country.
switch (langPrefix) {
case 'dk':
mapCoordinates = new google.maps.LatLng(56.16744, 11.36104);
break;
case 'pl':
mapCoordinates = new google.maps.LatLng(51.1977299, 19.0184122);
break;
default:
mapCoordinates = new google.maps.LatLng(56.16744, 11.36104);
break;
}
this.CreateMap(mapCoordinates);
},
methods: {
/**
* Set center properties.
*/
CreateMap: function (mapCoordinates) {
console.log('set properties');
var zoom = 7;
//Setup map properties
var mapProp = {
center : mapCoordinates,
zoom : zoom,
zoomControl : true,
mapTypeId : google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
};
//Init the map on the page
var map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
// To close other open windows
var prev_infowindow = false;
}
}
};
<google-map style="width: 100%; height: 100%; position: absolute; left:0; top:0" :center="{lat: 1.38, lng: 103.8}" :zoom="12"></google-map>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment