-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmylocation.js
217 lines (171 loc) · 7.7 KB
/
mylocation.js
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
//http://econym.org.uk/gmap/example_hoverchange75.htm
//http://www.geocodezip.com/v3_MW_example_map2.html
//http://www.geocodezip.com/v3_MW_example_map3.html
//http://stackoverflow.com/questions/2764452/google-map-api-v3-link-markers-to-an-external-list
var googleMap = document.getElementById("googleMap");
var myCenter = new google.maps.LatLng(17.4994889, 78.3872775); //map Longitude and Lattitude
var markers = [],
gmarkers = [],
i = 0,
html, mylocation, country, content, destination, mylocationL, countryL;
var locInfo = new Array();
var infowindow;
(function initialize() {
// This function picks up the click and opens the corresponding info window
function myclick(i) {
debugger;
gmarkers[i].openInfoWindowHtml(htmls[i]);
}
//Map Options
var mapProp = {
center: myCenter,
zoom: 3,
disableDefaultUI: true,
//panControl: false,
//zoomControl: true,
//mapTypeControl: true,
//scaleControl: true,
//streetViewControl: false,
//overviewMapControl: false,
//rotateControl: false,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
var map = new google.maps.Map(googleMap, mapProp);
//Custom control
/*if ($('#newPos').length == 0) {
$('div.gmnoprint').last().parent().wrap('<div id="newPos" />');
}*/
html = '<ul>';
//load xml data in list
$.get("mylocation.xml", function (data) {
mylocationL = $(data).find('mylocation').size();
countryL = $(data).find('country').size();
$(data).find("mylocation").each(function () {
var eachMarker = $(this);
country = eachMarker.find("country").text();
content = eachMarker.find("content").text();
destination = eachMarker.find("destination").text();
var markerCoords = new google.maps.LatLng(
parseFloat(eachMarker.find("latitude").text()),
parseFloat(eachMarker.find("longitude").text())
);
var infoWin = "<div class='info-blob'>" + country + "</div>";
var marker = addMarker(infoWin, markerCoords, mylocation, country, content, destination);
// markers.push(marker);
});
html += '</ul>';
//add li's to info div
$('#locationList').html($(html));
/* var openDt = parseInt(openDate[0], 10),
openMo = parseInt(openDate[1], 10) + 3,
openYr = parseInt(openDate[2], 10);
var now = new Date(),
nowYear = now.getFullYear(),
nowMo = now.getMonth() + 1, // for getMonth(), January is 0
nowDay = now.getDate();
//alert(openMo+', '+nowMo);
if (nowMo < openMo) {
$('.new').toggle('hide');
marker.setIcon('https://www.google.com/mapfiles/marker_green.png');
}*/
//Header context
$('.hdrInfo').html('<span>' + countryL + ' countries</span>');
//Sort by alphabetical
var mylist = $('#locationList ul');
var listitems = mylist.children('li').get();
listitems.sort(function (a, b) {
return $(a).text().toUpperCase().localeCompare($(b).text().toUpperCase());
});
//update the sort order
$('#locationList ul').empty().append(listitems);
// alert($('#storeList ul > li').length);
//click on list item to hilighligt the marker with information
$('#locationList ul > li').each(function () {
var $li_id = parseInt($(this).attr("id"));
// alert($li_id);
$(this).on('click', function () {
google.maps.event.trigger(markers[$li_id], 'click');
/*for (var z = 0; z < storeInfo.length; z++) {
if (storeInfo[z].id == $li_id) {
var localStorename = storeInfo[z].storename;
var localCountry = storeInfo[z].country;
break;
}
}*/
$('.locDiv').animate({
marginLeft: '-300px'
});
//Title in information panel
//$('.infoDiv p.title').html(country);
//Inforamtion of each store in information panel
//$('.infoDiv p.info').html('<ul><li>Opening date:</li><li>' + openDate + '</li><li> Square metres:</li><li>' + sqrMetr + ' </li><li> Products:</li><li>' + product + '</li><li>Room settings:</li><li>' + roomsetng + ' </li><li>Real-life homes:</li><li>' + relhome + '</li><li> Cash lanes:</li><li>' + cashlanes + '</li><li> Restaurant seats: </li><li>' + restsets + '</li><li>Co-workers:</li><li> ' + cowrk + '</li><li>Parking space:</li><li> ' + prkspace + '</li></ul>');
});
});
});
// Create a marker for each XML entry
function addMarker(infoWin, markerCoords, mylocation, country, content, destination) {
// Place the new marker
var marker = new google.maps.Marker({
map: map,
icon: 'mark-on.png',
position: markerCoords
}); // end place the new marker
(destination === 'true') ? marker.setIcon('mark-on.png'): marker.setIcon('mark-off.png');
gmarkers[i] = marker;
//AddtoGeoInfo(i, storename, country, openDate, sqrMetr, product, roomsetng, relhome, cashlanes, restsets, cowrk, prkspace);
html += '<li id="' + i + '" class = "loc-list" >' + country + '</li>';
i++;
//// Add event listener. On marker click, close all open infoWindows open current infoWindow.
google.maps.event.addListener(marker, "click", function () {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({
content: infoWin
});
infowindow.open(map, marker);
$('.locDiv').animate({
marginLeft: '-300px'
});
//Title in information panel
$('.infoDiv p.title').html('<div class=""> ' + country + ' <span class="new">New</span></div>');
//Inforamtion of each store in information panel
$('.infoDiv p.info').html('<ul><li>' + content + '</li></ul>');
}); // end add event listener
/* google.maps.event.addListener(marker, 'mouseover', function () {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({ content: infoWin });
infowindow.open(map, marker);
});
google.maps.event.addListener(marker, 'mouseout', function () {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({ content: infoWin });
infowindow.close(map, marker);
});*/
// Display marker
markers.push(marker);
} // end addMarker();
/*function AddtoGeoInfo(id, storename, country, openDate, sqrMetr, product, roomsetng, relhome, cashlanes, restsets, cowrk, prkspace) {
var geoInfo = new Array();
geoInfo["id"] = id;
geoInfo["storename"] = storename;
geoInfo["country"] = country;
storeInfo.push(geoInfo);
}*/
//filter the list with alphebet
$('#searchInput').keyup(function () {
var valThis = $(this).val().toLowerCase();
if (valThis == "") {
$('#locationList ul > li').show();
} else {
$('#locationList ul > li').each(function () {
var text = $(this).text().toLowerCase();
(text.indexOf(valThis) >= 0) ? $(this).show(): $(this).hide();
});
};
});
$('p.alink').click(function () {
$('.locDiv').animate({
marginLeft: "0"
});
infowindow.close();
});
})();