1 2/* 3 * LIBRERIA CUSTOM MAP 4 * 5 * Esempio di codice per l'attivazione della custom map: 6 * <div class="" id="INSERIRE SEMPRE ID" data-location="[[LATITUDINE, LOGITUDINE, MESSAGGIO], [LATITUDINE, LOGITUDINE, MESSAGGIO]]"></div> 7 * 8 */ 9 10(function($){ 11 12 $.fn.setCustomMap = function(settings){ 13 14 var settings = $.extend({},settings), 15 data = eval(settings.data.location); 16 17 if( data.length == 0 ){ alert('NO DATA'); return false; } 18 19 var mapDiv = document.getElementById($(this).attr('id')), 20 map, 21 geocoder = new google.maps.Geocoder() 22 bounds = new google.maps.LatLngBounds(), 23 locations = data[0].locations, 24 locationCount = 0, 25 zoom = data[0].zoom, 26 custom_marker = data[0].markericon, 27 markers = [], 28 currentinfowindow = null, 29 style = [{ }]; 30 31 /* 32 if( typeof custom_marker !== 'undefined' ) 33 custom_marker = custom_marker.split('|'); 34 else 35 custom_marker = new Array(); 36 */ 37 38 if( locations.length != 0 ) setCustomMapInit(); 39 else{ 40 console.log('ERRORE: Nessuna location inserita.'); 41 return false; 42 } 43 44 45 /* 46 * Funzione di inizializzazione della mappa 47 */ 48 49 function setCustomMapInit(){ 50 51 var minZoomLevel = 2; 52 if(!zoom) zoom = 15; 53 54 // SETTAGGI MAPPA 55 56 var mapSettings = { 57 zoom : parseInt(zoom), 58 center : { lat: 0, lng: 0 }, 59 navigationControl : true, 60 mapTypeControl : false, 61 mapTypeId : google.maps.MapTypeId.ROADMAP, 62 //mapTypeId : google.maps.MapTypeId.TERRAIN, 63 panControl : false, 64 zoomControl : true, 65 zoomControlOptions : { 66 style: google.maps.ZoomControlStyle.SMALL, 67 position: google.maps.ControlPosition.LEFT_TOP 68 }, 69 scaleControl : true, 70 streetViewControl : false, 71 fullscreenControl : true, 72 draggable : true, 73 disableDoubleClickZoom: false, 74 scrollwheel : false, 75 disableDefaultUI : true, 76 styles : settings.style, 77 }; 78 79 // INIZIALIZZAZIONE DELLA MAPPA 80 81 map = new google.maps.Map(mapDiv, mapSettings); 82 83 $.each(locations, function(index, value){ 84 85 var address = [ $(this)[0], $(this)[1], $(this)[2] ]; 86 87 // SETTAGGI MARKER 88 89 markers[index] = new google.maps.Marker({ 90 map: map, 91 icon: { 92 url: custom_marker, 93 // This marker is 60 pixels wide by 60 pixels tall. 94 size: new google.maps.Size(20,20), 95 // The origin for this image is 0,0. 96 origin: new google.maps.Point(0, 0), 97 // The anchor for this image is the base of the flagpole 98 anchor: new google.maps.Point(10,20) 99 }, 100 position: { lat: address[0], lng: address[1] }, 101 draggable: false 102 }); 103 104 // INSERIMENTO DEL MARKER NELLA MAPPA 105 106 markers[index].setMap(map); 107 108 // SE PRESENTE DEL TESTO, ATTIVAZIONE INFOWINDOW 109 110 if( address[2] ) addInfo( markers[index], address[2], { lat: address[0], lng: address[1] }, 0 ); 111 112 // AGGIUNTA DEL MARKER PER IL CENTRAMENTO DELLA MAPPA 113 114 if( locations.length == 1 ){ map.setZoom(zoom); map.setCenter({ lat: address[0], lng: address[1] }); } 115 else extendBounds({ lat: address[0], lng: address[1] }); 116 117 }); 118 119 // CENTRA LA MAPPA 120 121 google.maps.event.addDomListener(window, 'resize', function(){ 122 var center = map.getCenter(); 123 google.maps.event.trigger(map, 'resize'); 124 map.setCenter(center); 125 }); 126 127 // LIMITA IL LIVELLO DI ZOOM 128 129 google.maps.event.addListener(map, 'zoom_changed', function(){ 130 if( map.getZoom() < minZoomLevel ) map.setZoom(minZoomLevel); 131 }); 132 133 } 134 135 136 137 /* 138 * Funzione di creazione del infowindow 139 * INPUT: marker, messaggio da visualizzare all'interno dell'infowindow, posizione del puntatore, apertura automatica dell'infowindow (1) o al click (0). 140 */ 141 142 143 144 function addInfo( marker, message, position, open ){ 145 146 var infowindow = new google.maps.InfoWindow({ 147 content: message, 148 position: position 149 }); 150 151 if(open) infowindow.open( map, marker ); 152 153 google.maps.event.addListener( marker, 'click', function(){ 154 if( currentinfowindow != null ) currentinfowindow.close(); 155 infowindow.open(map,marker); 156 currentinfowindow = infowindow; 157 }); 158 159 google.maps.event.addListener( map, 'click', function(){ 160 infowindow.close(); 161 }); 162 163 } 164 165 166 167 /* 168 * Funzione per il centramento della mappa in base alle posizioni inserite 169 * INPUT: posizione. 170 */ 171 172 function extendBounds( latlng ){ 173 ++locationCount; 174 bounds.extend(latlng); 175 if(locationCount == locations.length) map.fitBounds(bounds); 176 } 177 178 return map; 179 180 }; 181 182})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.