(function() { window.onload = function(){ // Creating an object literal containing the properties we want to pass to the map var options = { zoom: $.defaultZoom, center: new google.maps.LatLng($.defaultLat,$.defaultLng), mapTypeId: google.maps.MapTypeId.ROADMAP, }; // Calling the constructor, thereby initializing the map var map = new google.maps.Map(document.getElementById('map'), options); var infowindowopts = { maxWidth: 274, }; if ($.tryCurrentLocation) { if (typeof(navigator.geolocation) != 'undefined') { navigator.geolocation.getCurrentPosition(function(position) { lat = position.coords.latitude; lng = position.coords.longitude; var position = new google.maps.LatLng(lat, lng); map.setOptions({ center: position, zoom: 12 }); }); } } var iw = new google.maps.InfoWindow(); iw.setOptions(infowindowopts); icons = new Array(); icons['cafes-and-restaurants'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/restaurant.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['volvo'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/volvo.png', new google.maps.Size(32,31), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['shopping'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/fashion.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['destinations'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/place-of-interest.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['crossroads-where-you-meet-others'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/meeting-spot.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['hotel-or-inn'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/hotel.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['other-services'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/provisions.png', new google.maps.Size(32,37), new google.maps.Point(0,0), new google.maps.Point(0,37) ); icons['ikea'] = new google.maps.MarkerImage('/templates/nordstjernan/icons/ikea.gif', new google.maps.Size(43,17), new google.maps.Point(0,0), new google.maps.Point(0,37) ); var markerGroups = { "cafes-and-restaurants": [], "volvo": [], "shopping": [], "destinations": [], "crossroads-where-you-meet-others": [], "hotel-or-inn": [], "other-services": [], "ikea": [] }; $.getJSON('/places/?c=json', function(data) { $.each(data, function(i,place) { // Creating a marker var marker = new google.maps.Marker({ position: new google.maps.LatLng(place.lat, place.lng), map: map, title: place.name, address: place.address, icon: icons[place.iconName] }); if (place.iconName) { markerGroups[place.iconName].push(marker); } google.maps.event.addListener(map, 'click', function() { iw.close(); }); google.maps.event.addListener(marker, 'click', function() { if(iw) { iw.close(); } iw.setContent( '
'+place.category+'
'+ '
'+place.name+'

'+ '
'+place.address+'
'+ '
'+place.text+'' ); iw.open(map, marker); }); }); $.markerGroups = markerGroups; }); } })();