* I prodotti, i prezzi e le caratteristiche possono variare senza preavviso anche a causa di errori e/o omissioni. Le immagini sono puramente indicative. Si consiglia di contattare il negozio di riferimento per verificare i dettagli e la validità dell'offerta. I prezzi delle offerte on line non sono comprensivi delle eventuali spese di spedizione
'
//+ generateTimeTable( shop.orari_pv )
+ 'Vai al Negozio '
return html //'
' + JSON.stringify( pv_data, null, 3 ) + '
'
}
// Data passed to this function is the pv.data attached to the marker.
function updateInfoWindow ( data )
{
console.log("updateInfoWindow");
var shop_info_html = generateShopInfo( data )
shop_info_el.innerHTML = shop_info_html
//var leaflets_html = generateLeaflets( leaflets_filtered )
//leaflets_el.innerHTML = leaflets_html
// Reset.
leaflet_idx = 0
leaflets_no = 0
leaflets_el.setAttribute( 'data-slot', leaflet_idx )
// Start the slideshow (only if we have more than one leaflet to show)
if ( leaflets_no > 1 )
{
slideshow_handle = setTimeout( doSlide, FREQUENCY )
}
switch ( leaflets_no )
{
case 0:
// Hide the whole vf-leaflets-browser
info_window_el.className = 'none'
break
case 1:
// Hide the ▲ and ▼ anchors
info_window_el.className = 'no-slide'
break
default:
info_window_el.className = ''
}
}
// http://stackoverflow.com/a/13274361
/*
function getBoundsZoomLevel(bounds, mapDim) {
var WORLD_DIM = { height: 256, width: 256 };
var ZOOM_MAX = 21;
function latRad(lat) {
var sin = Math.sin(lat * Math.PI / 180);
var radX2 = Math.log((1 + sin) / (1 - sin)) / 2;
return Math.max(Math.min(radX2, Math.PI), -Math.PI) / 2;
}
function zoom(mapPx, worldPx, fraction) {
return Math.floor(Math.log(mapPx / worldPx / fraction) / Math.LN2);
}
var ne = bounds.getNorthEast();
var sw = bounds.getSouthWest();
var latFraction = (latRad(ne.lat()) - latRad(sw.lat())) / Math.PI;
var lngDiff = ne.lng() - sw.lng();
var lngFraction = ((lngDiff < 0) ? (lngDiff + 360) : lngDiff) / 360;
var latZoom = zoom(mapDim.height, WORLD_DIM.height, latFraction);
var lngZoom = zoom(mapDim.width, WORLD_DIM.width, lngFraction);
return Math.min(latZoom, lngZoom, ZOOM_MAX);
}
*/
// Initialize the map
function initializeMap ( icons )
{
var marker_bounds
//var markers
var map_center
var mapOptions
var info_window
var info_window = new google.maps.InfoWindow({ content: info_window_el })
//
function closeInfoWindow ()
{
// Clear timer
//console.warn('!todo: clear slideshow timer')
clearTimeout( slideshow_handle )
// Close it.
info_window.close()
// Rewrite history
//window.history.replaceState( null, '', location.pathname + location.search + '#mappa' )
// Buggish per ora. da semplificare
}
gmap.closeInfoWindow = closeInfoWindow
//! Fires also when the info_window is not visualized
google.maps.event.addListener( info_window, 'content_changed', function ()
{
//console.warn( 'the infoWindow content did change' )
})
//! Do not use to update the content.
google.maps.event.addListener( info_window, 'domready', function ()
{
//console.warn( "the info_window\'s DOM is ready! (executed each time the info_window is displayed)" )
})
//! This event is not triggered when I programmatically close the infowindow.
google.maps.event.addListener( info_window, 'closeclick', function ()
{
//console.warn('closeclick')
// Invoke the cleanup routine.
closeInfoWindow()
//
window.history.replaceState( null, '', location.pathname + location.search + '#mappa' )
})
// Inline everything here.
// ×) preload the icons. injekt them instead.
// 2) generate the markers
marker_bounds = new google.maps.LatLngBounds()
//markers = data.puntivendita.map( function ( pv, i )
vf.app.gmap.data.puntivendita.forEach( function ( pv, i )
{
var latlng
var marker
latlng = new google.maps.LatLng( +pv.latitude, +pv.longitude )
marker_bounds.extend( latlng )
marker = new google.maps.Marker(
{
position: latlng,
//icon: icons[ 0 ], // current_icon_size_idx // getMarkerImageSuffix( gmap.ZOOM_INITIAL )],
title: pv.name,
// The z-index will have to change on roll-over
zIndex: i
})
// Store the information of the pv directly into the marker.
// Still missing the details about the "volantini" to be shown in the infoWindow
marker.data = pv
// Setup some listener on the marker
google.maps.event.addListener( marker, 'click', function ()
{
// Close the infowindow if already opened.
if ( info_window.map === map )
{
//info_window.close()
closeInfoWindow()
}
//console.log( JSON.stringify( this.data, null, 3 ))
//!neu! center the map on the marker before...
//map.setCenter( this.position )
// No way. innatural.
// Update the content of the info_window
updateInfoWindow( this.data )
// Present the info_window.
info_window.open( map, this )
//console.log(vf.app.gmap.data)
var log = 'Click sul punto vendita ID: ' + pv.id +', Nome: ' + pv.name + ', Catena: ' + vf.app.gmap.data.catena.name; //+ ', Provincia: ' + vf.app.gmap.data.provincia.nome_pro;
//console.log(log);
ga('send', 'event', 'Apertura mappa su punto vendita', 'Click', log);
// rewrite history
window.history.replaceState( null, '', location.pathname + location.search + '#mappa-' + pv.id )
})
// Make it front-most on rollover, only if the info_window is not visualized.
google.maps.event.addListener( marker, 'mouseover', function ()
{
if ( info_window.map == null )
marker.setZIndex( markers.length )
})
//return marker
markers.push( marker )
})
//return marker
// 3) extend bounds
// 4) initialize map using the center of the bounds.
map_center = marker_bounds.getCenter()
mapOptions =
{
zoom: 8,
center: map_center,
scrollwheel: true,
// https://developers.google.com/maps/documentation/javascript/controls
//disableDefaultUI: false,
panControl: false,
zoomControl: true,
zoomControlOptions:
{
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER
},
mapTypeControl: false, // Per ora, visto che il cambio di posizione è buggy...
scaleControl: true,
streetViewControl: false,
overviewMapControl: false
}
// Better to alias locally also.
// Questo va fatto alla fine, dopo aver piazzato i marker.
map = gmap.map = new google.maps.Map( gmap.el, mapOptions )
console.log('new google maps')
//last_zoom_id = getIconIdx( gmap.ZOOM_INITIAL )
// Process each marker ad assign to the map
markers.forEach( function ( marker )
{
marker.setMap( map )
marker.setIcon( "https://data.volantinofacile.it/" + vf.app.gmap.data.catena.logo.replace(":FORMAT", "pin") )
})
// marker Tu sei qui
var latlng
var whereIAm
var vfLocation = decodeURIComponent(getCookie("vf_location"));
if (vfLocation) {
var locationCookie = JSON.parse(vfLocation);
latlng = new google.maps.LatLng(+locationCookie.lat , +locationCookie.lng)
marker_bounds.extend( latlng )
whereIAm = new google.maps.Marker(
{
position: latlng,
icon: null,
title: "Tu sei qui!",
zIndex: markers.length + 1
})
var infoWhere = new google.maps.InfoWindow({ content: 'Tu sei qui!' })
google.maps.event.addListener( whereIAm, 'click', function ()
{
// Close the infowindow if already opened.
if ( info_window.map === map )
{
closeInfoWindow()
}
infoWhere.open( map, this )
})
// Make it front-most on rollover, only if the info_window is not visualized.
google.maps.event.addListener( whereIAm, 'mouseover', function ()
{
if ( infoWhere.map == null )
whereIAm.setZIndex( markers.length + 1 )
})
whereIAm.setIcon(null)
whereIAm.setMap(map)
}
//markers.push( whereIAm )
console.warn('BEFORE FITBOUNDS')
map.fitBounds( marker_bounds )
console.warn('JUST AFTER FITBOUNDS')
JUST_INITIALIZED = true
// Close the infoWindow if it is open when clicking on the map.
google.maps.event.addListener( map, 'click', function ()
{
if ( info_window.map == null )
{
//console.warn('not open')
}
else
{
closeInfoWindow()
window.history.replaceState( null, '', location.pathname + location.search + '#mappa' )
}
})
// Do something only the first time the map is loaded
google.maps.event.addListenerOnce( map, 'idle', function()
{
gmap.container.setAttribute( 'data-zoom', 14 )
last_center = map.getCenter()
})
// Too costly. do it on "idle"
google.maps.event.addListener( map, 'idle', function()
{
//console.warn( Date.now(), 'updating last known center' )
last_center = map.getCenter()
})
// Is this really necessary?
window.addEventListener( 'resize', function ()
{
google.maps.event.trigger( map, 'resize' )
// Lock position on resize to the last known center...
map.setCenter( last_center )
}
, false )
// √ Done (hopefully)
gmap.INITIALIZED = true
// ! call the callback if set
if ( __cb__ )
{
__cb__()
__cb__ = null
}
}
// Async script loading
function loadScript()
{
var script = document.createElement('script')
script.type = 'text/javascript'
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp'
+ '&callback=initializeGoogleMaps&key=AIzaSyABlhIDEeZ-GiU9XfFYcQMAcePg1LCz0qQ'
document.body.appendChild( script )
}
// Lazy initialization... (script callback)
// Definiamolo global con nome randomico e cancelliamolo subito dopo creazione.
console.warn('Random callback name:', (+Math.random().toFixed( 16 ).slice( 2 )).toString(16) )
//
function initializeGoogleMaps()
{
if ( gmap.INITIALIZED )
{
//console.warn( '(initializeGoogleMaps) Google Maps already initialized' )
return
}
// Preload the icons and initialize the map.
preloadMarkerIcons( initializeMap )
// Mark it as initialized
//gmap.INITIALIZED = true
}
gmap.initialize = function( cb )
{
if ( gmap.INITIALIZED )
{
//console.warn( '(initializeGoogleMapsLazy) Google Maps already initialized' )
cb && cb()
return
}
__cb__ = cb
loadScript()
}
gmap.gotoPuntoVendita = function ( pv )
{
// Find the marker.
var marker = markers.filter( function ( marker )
{
return marker.data === pv
})[0]
// Center the map on the marker...
map.setCenter( marker.position )
//console.warn( marker.position )
// mi sembra che tanto a prima botta non funziona. verifichiamo se dopo si.
// Si. serve. e serve farlo anche nel click però...
// No. troppo strano a farlo in quel modo...
//setTimeout( function (){
// Open the infowindow.
google.maps.event.trigger( marker, 'click' )
//}
//, 0 )
}
// Invoked from the ctrl when closing via the logo/close
gmap.close = function ()
{
gmap.closeInfoWindow()
}
gmap.markers = markers
vf.app.gmap = gmap
-->