Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
var tipologies;

function successTipology(responseTip){
	if (responseTip){
		tipologies = responseTip.tipologie;
	}
}

function errorTipology(responseTip){
	//error
}

API.getTypologies(successTipology, errorTipology);

function getMarkersByGPSLocation(map, markers, infowindow, iconSmart, contents, tipologies){
	if (navigator.geolocation) {
		window.tipologies = tipologies;
		navigator.geolocation.getCurrentPosition(function(position) {
			var pos = {
				lat: position.coords.latitude,
				lng: position.coords.longitude
			};
			
			var icon = {
				url: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
				size: new google.maps.Size(71, 71),
				origin: new google.maps.Point(0, 0),
				anchor: new google.maps.Point(17, 34),
				scaledSize: new google.maps.Size(25, 25)
			};
			
			map.setCenter(pos);

			var place;
			var geocoder = new google.maps.Geocoder();
			var latlng = new google.maps.LatLng(pos.lat, pos.lng);
			geocoder.geocode({'latLng': latlng}, function(results, status) {
			if (status == google.maps.GeocoderStatus.OK) {
				//console.log(results)
				if (results[1]) {
				//formatted address
				place =  {name : results[0].formatted_address};       
				} else {
				place = {name : ""};
				}
				// Create a marker for place.
				markers.push(new google.maps.Marker({
					map: map,
					icon: icon,
					title: place.name,
					position: pos
				}));
				getMarkersBySearch(place, pos.lat, pos.lng, markers, window.tipologies, infowindow, map, iconSmart, contents);
			} else {
				alert("Posizione non trovata");
			}
			});
			
			
		}, function() {
			handleLocationError(true, markers, map.getCenter());
		});
	} else {
		// Browser doesn't support Geolocation
		handleLocationError(false, markers, map.getCenter());
	}
}

function getPlaceInfo(lat, lng){
	var geocoder = new google.maps.Geocoder();
	var latlng = new google.maps.LatLng(lat, lng);
    geocoder.geocode({'latLng': latlng}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
		//console.log(results)
        if (results[1]) {
         //formatted address
         return results[0].formatted_address;        
        } else {
          return false;
        }
      } else {
        return false;
      }
    });
}

function getMarkersBySearch(place, lat, lng, markers, tipologies, infowindow, map, iconSmart, contents){
	function success(response){
		if (response){
			// Create the tipologies menu and link it to the UI element.
			var containerList;
			var tipControlList
			var tipControl;
			if (document.getElementsByClassName("container-tip-list").length <= 0){
				containerList = document.createElement('div');
				containerList.id = "container-list";
				containerList.className = "container-tip-list";
				tipControlList = document.createElement('ul');
				tipControlList.className = "tipologies-list";
				tipControlList.id = "tip-control";
				tipControl = new TipControl(tipControlList, tipologies, markers, place.name, response.locals, map);
				containerList.appendChild(tipControlList);
				map.controls[google.maps.ControlPosition.TOP_RIGHT].push(containerList);
			} else {
				containerList = document.getElementById("container-list");
				var child = document.getElementById("tip-control");
				tipControlList = document.createElement('ul');
				tipControlList.className = "tipologies-list";
				tipControlList.id = "tip-control";
				tipControl = new TipControl(tipControlList, tipologies, markers, place.name, response.locals, map);
				containerList.replaceChild(tipControlList, child);
			}
			for (i=0; i<response.locals.length; i++){
				markers.push(new google.maps.Marker({
					map: map,
					icon: iconSmart,
					title: response.locals[i].nomelocale,
					position: new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon))
				}));
				var marker = markers[i+1];
				
				var name = response.locals[i].nomelocale ? response.locals[i].nomelocale : "";
				var rates = rating(response.locals[i].stelle);
				var charging = response.locals[i].n_punti_ricarica ? response.locals[i].n_punti_ricarica : 0;
				var description = response.locals[i].descrizione ? response.locals[i].descrizione : "";
				var address = response.locals[i].indirizzo ? response.locals[i].indirizzo : "";
				var email = response.locals[i].email ? response.locals[i].email : "";
				var site = response.locals[i].sito ? response.locals[i].sito : "";
				var idTip = response.locals[i].tipologia ? response.locals[i].tipologia : -1;
				var typName;
				
				for (var j=0; j<tipologies.length; j++){
					if (idTip > -1 && idTip == tipologies[j].id)
						typName = tipologies[j].tipologia;
				}
				
				var content = '<div id="content">'+
									'<div id="siteNotice">'+
									'</div>'+
									'<h1 id="firstHeading" class="firstHeading">' + name + '</h1>'+
									'<h4 id="secondHeading" class="secondHeading">' + typName + '</h4>' +
									'<div id="bodyContent">'+
										'<div id="rating">' + rates + '</div>' +											
										'<p>' + description + '</p>'+
										'<div id="charging"><p><b>Punti di ricarica: </b>' + charging + '</p></div>' +
										'<p><b>Indirizzo:</b> ' +  address + '</p>' +
										'<p><b>E-mail: </b>' + email + '</p>' +
										'<p><b>Sito: </b><a href="http://' + site + '" target="_blank">'+
										site + '</a></p>'+										
									'</div>'+
								'</div>';
				contents.push(content);
				google.maps.event.addListener(marker, 'click', (function(marker, i) {
						return function() {
								infowindow.setContent(contents[i]);
								infowindow.open(map, marker);
								infowindow.setPosition(new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon)));
							}
				})(marker, i));
			}
		}
	}
	
	function error(response){
		//error
	}
	
	API.getLocali(-1, lat, lng, 10000, success, error);
}


function TipControl(controlList, tipologies, markers, searchedMarker, listLocals, map) {
  controlList.style.padding = '0';
  var controlUI;
  var controlBackgroundUI;
  //var controlAllMarkerUI;
 
  if (tipologies){
	/*controlBackgroundUI = document.createElement('div');
	controlBackgroundUI.className = "li-background";
	controlAllMarkerUI = document.createElement('li');
	controlAllMarkerUI.className = "all-markers";
	controlAllMarkerUI.innerHTML = "<p><b>Tutti</b></p>";
	controlAllMarkerUI.style.textAlign = 'center';
	controlAllMarkerUI.style.backgroundColor = '#fff';
	controlBackgroundUI.appendChild(controlAllMarkerUI);
	controlList.appendChild(controlBackgroundUI);*/
	for(var i = 0; i<tipologies.length; i++){
		controlBackgroundUI = document.createElement('div')
		controlBackgroundUI.className = "li-background";
		controlUI = document.createElement('li');
		controlUI.style.backgroundColor = '#fff';
		controlUI.style.textAlign = 'center';
		controlUI.title = tipologies[i].tipologia;
		controlUI.className = tipologies[i].id;
		controlBackgroundUI.appendChild(controlUI);
		controlList.appendChild(controlBackgroundUI);
		var controlText = document.createElement('p');
		controlText.innerHTML = '<b>' + tipologies[i].tipologia + '</b>';
		controlUI.appendChild(controlText);
		
		google.maps.event.addDomListener(controlBackgroundUI, 'mouseover', function(){
			$(this).addClass("hover");
			$(this).find('p').addClass("hover");
		});
		
		google.maps.event.addDomListener(controlBackgroundUI, 'mouseout', function(){
			$(this).removeClass("hover");
			$(this).find('p').removeClass("hover");
		});
		
		// Setup click-event listener: filter marker by tipology
		google.maps.event.addDomListener(controlUI, 'click', function() {
			var that = this;
			var currents = [];
			if(markers.length > 0){
				for (var elem in listLocals){
					if (parseInt(that.getAttribute("class")) == listLocals[elem].tipologia){
						current = listLocals[elem].nomelocale;
						currents.push(current);
					}
				}
				
				markers.forEach(function(marker) {
					if(marker.title != searchedMarker && $.inArray(marker.title, currents) == -1)
						marker.setMap(null);
					else if(marker.title != searchedMarker && $.inArray(marker.title, currents) != -1){
						marker.setMap(map);
						marker.setVisible(true);
					}
				});
			}
		});
	}
  }
}


function initAutocomplete() {
	var map = new google.maps.Map(document.getElementById('map'), {
		center: {lat: 41.9109, lng: 12.4818},
		zoom: 13,
		mapTypeId: google.maps.MapTypeId.ROADMAP
	});
	//google.maps.event.trigger(map, 'resize');
	// Create the search box and link it to the UI element.
	google.maps.event.trigger(map, 'resize');
	var input = document.getElementById('pac-input');
	var searchBox = new google.maps.places.SearchBox(input);
	map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
	
	// Bias the SearchBox results towards current map's viewport.
	map.addListener('bounds_changed', function() {
		searchBox.setBounds(map.getBounds());
	});

	var markers = [];
	
	var myOptions = {
			disableAutoPan: false
			,pixelOffset: new google.maps.Size(-25, -5)
			,alignBottom: true
			,pane: "floatPane"
	};
	
	var infowindow = new google.maps.InfoWindow(myOptions);
	
	var iconeBase = "images/";
	
	var iconSmart = {
		url: iconeBase + "base.png",
		size: new google.maps.Size(71, 71),
		origin: new google.maps.Point(0, 0),
		anchor: new google.maps.Point(17, 34),
		scaledSize: new google.maps.Size(25, 25),			
	};
	
	var contents = [];
	
	getMarkersByGPSLocation(map, markers, infowindow, iconSmart, contents, tipologies);
		
	// [START region_getplaces]
	// Listen for the event fired when the user selects a prediction and retrieve
	// more details for that place.
	searchBox.addListener('places_changed', function() {
		var places = searchBox.getPlaces();
		var lat = places[0].geometry.location.lat();
		var lng = places[0].geometry.location.lng();
		if (places.length == 0) {
		return;
		}
	
		// Clear out the old markers.
		markers.forEach(function(marker) {
		marker.setMap(null);
		});
		markers = [];
	
		// For each place, get the icon, name and location.
		var bounds = new google.maps.LatLngBounds();
		
					
		places.forEach(function(place) {
		var icon = {
			url: place.icon,
			size: new google.maps.Size(71, 71),
			origin: new google.maps.Point(0, 0),
			anchor: new google.maps.Point(17, 34),
			scaledSize: new google.maps.Size(25, 25)
		};
		
		// Create a marker for each place.
		markers.push(new google.maps.Marker({
			map: map,
			icon: icon,
			title: place.name,
			position: place.geometry.location
		}));
		
		//var i;
		
		getMarkersBySearch(place, lat, lng, markers, tipologies, infowindow, map, iconSmart, contents);
		
		
		if (place.geometry.viewport) {
			// Only geocodes have viewport.
			bounds.union(place.geometry.viewport);
		} else {
			bounds.extend(place.geometry.location);
		}
		});
		map.fitBounds(bounds);
	});
	// [END region_getplaces]
}

Commits for Nextrek/Web/Smartcharging_search/js/maps-google.js

Diff revisions: vs.
Revision Author Commited Message
1036 Diff Diff LZicari picture LZicari Thu 17 Dec, 2015 13:45:09 +0000
1035 Diff Diff LZicari picture LZicari Thu 17 Dec, 2015 11:50:10 +0000
1034 Diff Diff LZicari picture LZicari Thu 17 Dec, 2015 09:30:59 +0000
1033 LZicari picture LZicari Tue 15 Dec, 2015 17:48:58 +0000