Subversion Repository Public Repository

Nextrek

Diff Revisions 1034 vs 1035 for /Web/Smartcharging_search/js/maps-google.js

Diff revisions: vs.
  @@ -12,13 +12,165 @@
12 12
13 13 API.getTypologies(successTipology, errorTipology);
14 14
15 + function getMarkersByGPSLocation(map, markers, infowindow, iconSmart, contents, tipologies){
16 + if (navigator.geolocation) {
17 + window.tipologies = tipologies;
18 + navigator.geolocation.getCurrentPosition(function(position) {
19 + var pos = {
20 + lat: position.coords.latitude,
21 + lng: position.coords.longitude
22 + };
23 +
24 + var place = {name : getPlaceInfo(pos.lat, pos.lng) != false ? getPlaceInfo(pos.lat, pos.lng) : ""};
25 +
26 + var icon = {
27 + url: "https://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
28 + size: new google.maps.Size(71, 71),
29 + origin: new google.maps.Point(0, 0),
30 + anchor: new google.maps.Point(17, 34),
31 + scaledSize: new google.maps.Size(25, 25)
32 + };
33 +
34 + // Create a marker for place.
35 + markers.push(new google.maps.Marker({
36 + map: map,
37 + icon: icon,
38 + title: 'Posizione Attuale',
39 + position: pos
40 + }));
41 +
42 + map.setCenter(pos);
43 +
44 + getMarkersBySearch(place, pos.lat, pos.lng, markers, window.tipologies, infowindow, map, iconSmart, contents);
45 +
46 + }, function() {
47 + handleLocationError(true, markers, map.getCenter());
48 + });
49 + } else {
50 + // Browser doesn't support Geolocation
51 + handleLocationError(false, markers, map.getCenter());
52 + }
53 + }
54 +
55 + function getPlaceInfo(lat, lng){
56 + var geocoder = new google.maps.Geocoder();
57 + var latlng = new google.maps.LatLng(lat, lng);
58 + geocoder.geocode({'latLng': latlng}, function(results, status) {
59 + if (status == google.maps.GeocoderStatus.OK) {
60 + //console.log(results)
61 + if (results[1]) {
62 + //formatted address
63 + return results[0].formatted_address;
64 + } else {
65 + return false;
66 + }
67 + } else {
68 + return false;
69 + }
70 + });
71 + }
72 +
73 + function getMarkersBySearch(place, lat, lng, markers, tipologies, infowindow, map, iconSmart, contents){
74 + function success(response){
75 + if (response){
76 + // Create the tipologies menu and link it to the UI element.
77 + var containerList;
78 + var tipControlList
79 + var tipControl;
80 + if (document.getElementsByClassName("container-tip-list").length <= 0){
81 + containerList = document.createElement('div');
82 + containerList.id = "container-list";
83 + containerList.className = "container-tip-list";
84 + tipControlList = document.createElement('ul');
85 + tipControlList.className = "tipologies-list";
86 + tipControlList.id = "tip-control";
87 + tipControl = new TipControl(tipControlList, tipologies, markers, place.name, response.locals, map);
88 + containerList.appendChild(tipControlList);
89 + map.controls[google.maps.ControlPosition.TOP_RIGHT].push(containerList);
90 + } else {
91 + containerList = document.getElementById("container-list");
92 + var child = document.getElementById("tip-control");
93 + tipControlList = document.createElement('ul');
94 + tipControlList.className = "tipologies-list";
95 + tipControlList.id = "tip-control";
96 + tipControl = new TipControl(tipControlList, tipologies, markers, place.name, response.locals, map);
97 + containerList.replaceChild(tipControlList, child);
98 + }
99 + for (i=0; i<response.locals.length; i++){
100 + markers.push(new google.maps.Marker({
101 + map: map,
102 + icon: iconSmart,
103 + title: response.locals[i].nomelocale,
104 + position: new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon))
105 + }));
106 + var marker = markers[i+1];
107 +
108 + var name = response.locals[i].nomelocale ? response.locals[i].nomelocale : "";
109 + var rates = rating(response.locals[i].stelle);
110 + var charging = response.locals[i].n_punti_ricarica ? response.locals[i].n_punti_ricarica : 0;
111 + var description = response.locals[i].descrizione ? response.locals[i].descrizione : "";
112 + var address = response.locals[i].indirizzo ? response.locals[i].indirizzo : "";
113 + var email = response.locals[i].email ? response.locals[i].email : "";
114 + var site = response.locals[i].sito ? response.locals[i].sito : "";
115 + var idTip = response.locals[i].tipologia ? response.locals[i].tipologia : -1;
116 + var typName;
117 +
118 + for (var j=0; j<tipologies.length; j++){
119 + if (idTip > -1 && idTip == tipologies[j].id)
120 + typName = tipologies[j].tipologia;
121 + }
122 +
123 + var content = '<div id="content">'+
124 + '<div id="siteNotice">'+
125 + '</div>'+
126 + '<h1 id="firstHeading" class="firstHeading">' + name + '</h1>'+
127 + '<h4 id="secondHeading" class="secondHeading">' + typName + '</h4>' +
128 + '<div id="bodyContent">'+
129 + '<div id="rating">' + rates + '</div>' +
130 + '<p>' + description + '</p>'+
131 + '<div id="charging"><p><b>Punti di ricarica: </b>' + charging + '</p></div>' +
132 + '<p><b>Indirizzo:</b> ' + address + '</p>' +
133 + '<p><b>E-mail: </b>' + email + '</p>' +
134 + '<p><b>Sito: </b><a href="http://' + site + '" target="_blank">'+
135 + site + '</a></p>'+
136 + '</div>'+
137 + '</div>';
138 + contents.push(content);
139 + google.maps.event.addListener(marker, 'click', (function(marker, i) {
140 + return function() {
141 + infowindow.setContent(contents[i]);
142 + infowindow.open(map, marker);
143 + infowindow.setPosition(new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon)));
144 + }
145 + })(marker, i));
146 + }
147 + }
148 + }
149 +
150 + function error(response){
151 + //error
152 + }
153 +
154 + API.getLocali(-1, lat, lng, 10000, success, error);
155 + }
156 +
15 157
16 158 function TipControl(controlList, tipologies, markers, searchedMarker, listLocals, map) {
17 159 controlList.style.padding = '0';
18 160 var controlUI;
19 161 var controlBackgroundUI;
20 - //window.storedMarkers = markers.length > 0 ? markers : [];
162 + //var controlAllMarkerUI;
163 +
21 164 if (tipologies){
165 + /*controlBackgroundUI = document.createElement('div');
166 + controlBackgroundUI.className = "li-background";
167 + controlAllMarkerUI = document.createElement('li');
168 + controlAllMarkerUI.className = "all-markers";
169 + controlAllMarkerUI.innerHTML = "<p><b>Tutti</b></p>";
170 + controlAllMarkerUI.style.textAlign = 'center';
171 + controlAllMarkerUI.style.backgroundColor = '#fff';
172 + controlBackgroundUI.appendChild(controlAllMarkerUI);
173 + controlList.appendChild(controlBackgroundUI);*/
22 174 for(var i = 0; i<tipologies.length; i++){
23 175 controlBackgroundUI = document.createElement('div')
24 176 controlBackgroundUI.className = "li-background";
  @@ -90,6 +242,29 @@
90 242
91 243 var markers = [];
92 244
245 + var myOptions = {
246 + disableAutoPan: false
247 + ,pixelOffset: new google.maps.Size(-25, -5)
248 + ,alignBottom: true
249 + ,pane: "floatPane"
250 + };
251 +
252 + var infowindow = new google.maps.InfoWindow(myOptions);
253 +
254 + var iconeBase = "images/";
255 +
256 + var iconSmart = {
257 + url: iconeBase + "base.png",
258 + size: new google.maps.Size(71, 71),
259 + origin: new google.maps.Point(0, 0),
260 + anchor: new google.maps.Point(17, 34),
261 + scaledSize: new google.maps.Size(25, 25),
262 + };
263 +
264 + var contents = [];
265 +
266 + getMarkersByGPSLocation(map, markers, infowindow, iconSmart, contents, tipologies);
267 +
93 268 // [START region_getplaces]
94 269 // Listen for the event fired when the user selects a prediction and retrieve
95 270 // more details for that place.
  @@ -106,7 +281,6 @@
106 281 marker.setMap(null);
107 282 });
108 283 markers = [];
109 - var iconeBase = "images/";
110 284
111 285 // For each place, get the icon, name and location.
112 286 var bounds = new google.maps.LatLngBounds();
  @@ -121,14 +295,6 @@
121 295 scaledSize: new google.maps.Size(25, 25)
122 296 };
123 297
124 - var iconSmart = {
125 - url: iconeBase + "base.png",
126 - size: new google.maps.Size(71, 71),
127 - origin: new google.maps.Point(0, 0),
128 - anchor: new google.maps.Point(17, 34),
129 - scaledSize: new google.maps.Size(25, 25),
130 - };
131 -
132 298 // Create a marker for each place.
133 299 markers.push(new google.maps.Marker({
134 300 map: map,
  @@ -137,82 +303,10 @@
137 303 position: place.geometry.location
138 304 }));
139 305
140 - var myOptions = {
141 - disableAutoPan: false
142 - ,pixelOffset: new google.maps.Size(-25, -5)
143 - ,alignBottom: true
144 - ,pane: "floatPane"
145 - };
146 -
147 - var infowindow = new google.maps.InfoWindow(myOptions);
148 - var i;
149 - var contents = [];
150 -
151 - function success(response){
152 - if (response){
153 - // Create the tipologies menu and link it to the UI element.
154 - if (!tipControlList){
155 - var tipControlList = document.createElement('ul');
156 - tipControlList.className = "tipologies-list";
157 - var tipControl = new TipControl(tipControlList, tipologies, markers, place.name, response.locals, map);
158 - map.controls[google.maps.ControlPosition.TOP_RIGHT].push(tipControlList);
159 - }
160 - for (i=0; i<response.locals.length; i++){
161 - markers.push(new google.maps.Marker({
162 - map: map,
163 - icon: iconSmart,
164 - title: response.locals[i].nomelocale,
165 - position: new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon))
166 - }));
167 - var marker = markers[i+1];
168 -
169 - var name = response.locals[i].nomelocale ? response.locals[i].nomelocale : "";
170 - var rates = rating(response.locals[i].stelle);
171 - var charging = response.locals[i].n_punti_ricarica ? response.locals[i].n_punti_ricarica : 0;
172 - var description = response.locals[i].descrizione ? response.locals[i].descrizione : "";
173 - var address = response.locals[i].indirizzo ? response.locals[i].indirizzo : "";
174 - var email = response.locals[i].email ? response.locals[i].email : "";
175 - var site = response.locals[i].sito ? response.locals[i].sito : "";
176 - var idTip = response.locals[i].tipologia ? response.locals[i].tipologia : -1;
177 - var typName;
178 -
179 - for (var j=0; j<tipologies.length; j++){
180 - if (idTip > -1 && idTip == tipologies[j].id)
181 - typName = tipologies[j].tipologia;
182 - }
183 -
184 - var content = '<div id="content">'+
185 - '<div id="siteNotice">'+
186 - '</div>'+
187 - '<h1 id="firstHeading" class="firstHeading">' + name + '</h1>'+
188 - '<h4 id="secondHeading" class="secondHeading">' + typName + '</h4>' +
189 - '<div id="bodyContent">'+
190 - '<div id="rating">' + rates + '</div>' +
191 - '<p>' + description + '</p>'+
192 - '<div id="charging"><p><b>Punti di ricarica: </b>' + charging + '</p></div>' +
193 - '<p><b>Indirizzo:</b> ' + address + '</p>' +
194 - '<p><b>E-mail: </b>' + email + '</p>' +
195 - '<p><b>Sito: </b><a href="http://' + site + '" target="_blank">'+
196 - site + '</a></p>'+
197 - '</div>'+
198 - '</div>';
199 - contents.push(content);
200 - google.maps.event.addListener(marker, 'click', (function(marker, i) {
201 - return function() {
202 - infowindow.setContent(contents[i]);
203 - infowindow.open(map, marker);
204 - infowindow.setPosition(new google.maps.LatLng(parseFloat(response.locals[i].lat), parseFloat(response.locals[i].lon)));
205 - }
206 - })(marker, i));
207 - }
208 - }
209 - }
306 + //var i;
210 307
211 - function error(response){
212 - //error
213 - }
308 + getMarkersBySearch(place, lat, lng, markers, tipologies, infowindow, map, iconSmart, contents);
214 309
215 - API.getLocali(-1, lat, lng, 10000, success, error);
216 310
217 311 if (place.geometry.viewport) {
218 312 // Only geocodes have viewport.