Subversion Repository Public Repository

Nextrek

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

Diff revisions: vs.
  @@ -1,3 +1,75 @@
1 + var tipologies;
2 +
3 + function successTipology(responseTip){
4 + if (responseTip){
5 + tipologies = responseTip.tipologie;
6 + }
7 + }
8 +
9 + function errorTipology(responseTip){
10 + //error
11 + }
12 +
13 + API.getTypologies(successTipology, errorTipology);
14 +
15 +
16 + function TipControl(controlList, tipologies, markers, searchedMarker, listLocals, map) {
17 + controlList.style.padding = '0';
18 + var controlUI;
19 + var controlBackgroundUI;
20 + //window.storedMarkers = markers.length > 0 ? markers : [];
21 + if (tipologies){
22 + for(var i = 0; i<tipologies.length; i++){
23 + controlBackgroundUI = document.createElement('div')
24 + controlBackgroundUI.className = "li-background";
25 + controlUI = document.createElement('li');
26 + controlUI.style.backgroundColor = '#fff';
27 + controlUI.style.textAlign = 'center';
28 + controlUI.title = tipologies[i].tipologia;
29 + controlUI.className = tipologies[i].id;
30 + controlBackgroundUI.appendChild(controlUI);
31 + controlList.appendChild(controlBackgroundUI);
32 + var controlText = document.createElement('p');
33 + controlText.innerHTML = '<b>' + tipologies[i].tipologia + '</b>';
34 + controlUI.appendChild(controlText);
35 +
36 + google.maps.event.addDomListener(controlBackgroundUI, 'mouseover', function(){
37 + $(this).addClass("hover");
38 + $(this).find('p').addClass("hover");
39 + });
40 +
41 + google.maps.event.addDomListener(controlBackgroundUI, 'mouseout', function(){
42 + $(this).removeClass("hover");
43 + $(this).find('p').removeClass("hover");
44 + });
45 +
46 + // Setup click-event listener: filter marker by tipology
47 + google.maps.event.addDomListener(controlUI, 'click', function() {
48 + var that = this;
49 + var currents = [];
50 + if(markers.length > 0){
51 + for (var elem in listLocals){
52 + if (parseInt(that.getAttribute("class")) == listLocals[elem].tipologia){
53 + current = listLocals[elem].nomelocale;
54 + currents.push(current);
55 + }
56 + }
57 +
58 + markers.forEach(function(marker) {
59 + if(marker.title != searchedMarker && $.inArray(marker.title, currents) == -1)
60 + marker.setMap(null);
61 + else if(marker.title != searchedMarker && $.inArray(marker.title, currents) != -1){
62 + marker.setMap(map);
63 + marker.setVisible(true);
64 + }
65 + });
66 + }
67 + });
68 + }
69 + }
70 + }
71 +
72 +
1 73 function initAutocomplete() {
2 74 var map = new google.maps.Map(document.getElementById('map'), {
3 75 center: {lat: 41.9109, lng: 12.4818},
  @@ -15,8 +87,9 @@
15 87 map.addListener('bounds_changed', function() {
16 88 searchBox.setBounds(map.getBounds());
17 89 });
18 -
90 +
19 91 var markers = [];
92 +
20 93 // [START region_getplaces]
21 94 // Listen for the event fired when the user selects a prediction and retrieve
22 95 // more details for that place.
  @@ -37,18 +110,7 @@
37 110
38 111 // For each place, get the icon, name and location.
39 112 var bounds = new google.maps.LatLngBounds();
40 - var tipologies;
41 -
42 - function successTipology(responseTip){
43 - if (responseTip){
44 - tipologies = responseTip.tipologie;
45 - }
46 - }
47 113
48 - function errorTipology(responseTip){
49 - //error
50 - }
51 - API.getTypologies(successTipology, errorTipology);
52 114
53 115 places.forEach(function(place) {
54 116 var icon = {
  @@ -88,6 +150,13 @@
88 150
89 151 function success(response){
90 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 + }
91 160 for (i=0; i<response.locals.length; i++){
92 161 markers.push(new google.maps.Marker({
93 162 map: map,
  @@ -145,7 +214,6 @@
145 214
146 215 API.getLocali(-1, lat, lng, 10000, success, error);
147 216
148 -
149 217 if (place.geometry.viewport) {
150 218 // Only geocodes have viewport.
151 219 bounds.union(place.geometry.viewport);