I am learning angular and I want to include a map in an angular partial. As i have done it it loads on the partial, but only if you reload the page.
The google maps script + API Key is included in the index.html
At the moment the script is inlcuded like this in the partial
<!-- map -->
<div id="map" class="col-lg-12">
<script type="text/javascript" src="js/map.js"></script>
</div>
<!-- /map -->
My page controller is empty, as I understand it i somehow have to call it here
app.controller('PageCtrl', function (/* $scope, $location, $http */) {
console.log("Page Controller ready");
});
And the map.js:
function init() {
var e = {
zoom: 8,
center: new google.maps.LatLng(12.00, 12.00),
styles: [{
featureType: "all",
elementType: "all",
stylers: [{
visibility: "on"
}]
}, {
featureType: "all",
elementType: "labels",
stylers: [{
visibility: "off"
}, {
saturation: "-100"
}]
}, {
featureType: "all",
elementType: "labels.text.fill",
stylers: [{
saturation: 36
}, {
color: "#000000"
}, {
lightness: 40
}, {
visibility: "off"
}]
}, {
featureType: "all",
elementType: "labels.text.stroke",
stylers: [{
visibility: "off"
}, {
color: "#000000"
}, {
lightness: 16
}]
}, {
featureType: "all",
elementType: "labels.icon",
stylers: [{
visibility: "off"
}]
}, {
featureType: "administrative",
elementType: "geometry.fill",
stylers: [{
color: "#000000"
}, {
lightness: 20
}]
}, {
featureType: "administrative",
elementType: "geometry.stroke",
stylers: [{
color: "#000000"
}, {
lightness: 17
}, {
weight: 1.2
}]
}, {
featureType: "landscape",
elementType: "geometry",
stylers: [{
color: "#000000"
}, {
lightness: 20
}]
}, {
featureType: "landscape",
elementType: "geometry.fill",
stylers: [{
color: "#4d6059"
}]
}, {
featureType: "landscape",
elementType: "geometry.stroke",
stylers: [{
color: "#4d6059"
}]
}, {
featureType: "landscape.natural",
elementType: "geometry.fill",
stylers: [{
color: "#4d6059"
}]
}, {
featureType: "poi",
elementType: "geometry",
stylers: [{
lightness: 21
}]
}, {
featureType: "poi",
elementType: "geometry.fill",
stylers: [{
color: "#4d6059"
}]
}, {
featureType: "poi",
elementType: "geometry.stroke",
stylers: [{
color: "#4d6059"
}]
}, {
featureType: "road",
elementType: "geometry",
stylers: [{
visibility: "on"
}, {
color: "#7f8d89"
}]
}, {
featureType: "road",
elementType: "geometry.fill",
stylers: [{
color: "#7f8d89"
}]
}, {
featureType: "road.highway",
elementType: "geometry.fill",
stylers: [{
color: "#7f8d89"
}, {
lightness: 17
}]
}, {
featureType: "road.highway",
elementType: "geometry.stroke",
stylers: [{
color: "#7f8d89"
}, {
lightness: 29
}, {
weight: .2
}]
}, {
featureType: "road.arterial",
elementType: "geometry",
stylers: [{
color: "#000000"
}, {
lightness: 18
}]
}, {
featureType: "road.arterial",
elementType: "geometry.fill",
stylers: [{
color: "#7f8d89"
}]
}, {
featureType: "road.arterial",
elementType: "geometry.stroke",
stylers: [{
color: "#7f8d89"
}]
}, {
featureType: "road.local",
elementType: "geometry",
stylers: [{
color: "#000000"
}, {
lightness: 16
}]
}, {
featureType: "road.local",
elementType: "geometry.fill",
stylers: [{
color: "#7f8d89"
}]
}, {
featureType: "road.local",
elementType: "geometry.stroke",
stylers: [{
color: "#7f8d89"
}]
}, {
featureType: "transit",
elementType: "geometry",
stylers: [{
color: "#000000"
}, {
lightness: 19
}]
}, {
featureType: "water",
elementType: "all",
stylers: [{
color: "#2b3638"
}, {
visibility: "on"
}]
}, {
featureType: "water",
elementType: "geometry",
stylers: [{
color: "#2b3638"
}, {
lightness: 17
}]
}, {
featureType: "water",
elementType: "geometry.fill",
stylers: [{
color: "#24282b"
}]
}, {
featureType: "water",
elementType: "geometry.stroke",
stylers: [{
color: "#24282b"
}]
}, {
featureType: "water",
elementType: "labels",
stylers: [{
visibility: "off"
}]
}, {
featureType: "water",
elementType: "labels.text",
stylers: [{
visibility: "off"
}]
}, {
featureType: "water",
elementType: "labels.text.fill",
stylers: [{
visibility: "off"
}]
}, {
featureType: "water",
elementType: "labels.text.stroke",
stylers: [{
visibility: "off"
}]
}, {
featureType: "water",
elementType: "labels.icon",
stylers: [{
visibility: "off"
}]
}]
},
t = document.getElementById("map"),
l = new google.maps.Map(t, e);
new google.maps.Marker({
position: new google.maps.LatLng(48.84, 12.95),
map: l,
title: "Snazzy!"
})
}
google.maps.event.addDomListener(window, "load", init);
My guess is the part
google.maps.event.addDomListener(window, "load", init);
has to happen in the controller, but I cant make it work.