-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjavascript.js
184 lines (165 loc) · 5.8 KB
/
javascript.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
var currentInfoWindow;
var map;
var markers = []
var markerIcons = []
$(document).ready(function () {
var initialLocation;
var siberia = new google.maps.LatLng(60, 105);
var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
var browserSupportFlag = new Boolean();
var InfoWindowCount = 0
//check if a marker already exist
function checkMarkers(title){
for (i = markers.length; i--;)
if (markers[i].title == title)
return true;
addMarker(title)
return false;
}
//generates a new marker in the local array
function Marker(title){
this.title = title
}
//make a new marker and add to local array
function addMarker(title){
var marker = new Marker(title)
markers.push(marker)
return
}
//checks the local array if a marker is already a fav
// function checkFav(title){
// for (i = favorites.length; i--;)
// if (favorites[i].title == title)
// return true;
// return false;
// }
// //deletes a marker from the local array when deleting from DB
// function deleteFav(title){
// for (var i = 0; i < markers.length; i++)
// if (favorites[i].title == title){
// favorites.splice(i, 1);
// return true}
// return null;
// }
// //generates a fav for local array
// function Fav(title){
// this.title = title
// }
// //adds a fav to local favs array when adding to DB. Can just use title because that is what it will be looked up as
// function addFav(title){
// var favorite = new Fav(title)
// favorites.push(favorite)
// return
// }
function initialize() {
//turn off points of interest (POI) markers so people can only look at the info boxes generated by this app
var myStyles =[
{
featureType: "poi",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];
mapOptions = {
//center: new google.maps.LatLng(40.710926,-73.95885700000001),
zoom:16,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: myStyles,
disableDefaultUI: true
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
infoWidth = 350
if ( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
infoWidth = 500
}
var lat, lng = map.getCenter()
// Try W3C Geolocation (Preferred)
if(navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function(position) {
initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
map.setCenter(initialLocation);
}, function() {
handleNoGeolocation(browserSupportFlag);
});
}
// Browser doesn't support Geolocation
else {
browserSupportFlag = false;
handleNoGeolocation(browserSupportFlag);
}
function handleNoGeolocation(errorFlag) {
if (errorFlag == true) {
alert("Geolocation service failed.");
initialLocation = newyork;
} else {
alert("Your browser doesn't support geolocation. We've placed you in Siberia.");
initialLocation = siberia;
}
map.setCenter(initialLocation);
}
google.maps.event.addListener(map, 'idle', function(evt) {
writeMarker();
});
}
function writeMarker() {
//set map center
c = map.getCenter();
var lat = c.k;
var lng = c.B;
var url = 'https://api.geonames.org/findNearbyWikipedia?lat='+ lat +'&lng='+ lng +'&maxRows=10&username=andyjt';
//get the data
$.get(url, function (data) {
//iterate through the data
$(data).find("entry").each(function(){
//check to see if the marker was already made
if (checkMarkers($(this).find("title").text()) === false) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng($(this).find("lat").text(), $(this).find("lng").text()),
});
marker.setIcon("assets/img/MapMarker.png");
var infowindow = new google.maps.InfoWindow({
maxWidth: infoWidth,
content:'<div id="content">'+
'<div id="siteNotice">'+
'</div>'+
'<h1 id="firstHeading" class="firstHeading">'+$(this).find("title").text()+'</h1>'+
'<div id="bodyContent">'+
'<p>'+$(this).find("summary").text()+' <a href="'+$(this).find("wikipediaUrl").text()+'" target="_blank">Wikipedia Entry</a></p>'+
'</div>'+
'</div>'+
'</div>'
});
google.maps.event.addListener(marker, 'click', function() {
if (currentInfoWindow) currentInfoWindow.close();
infowindow.open(map,marker);
currentInfoWindow = infowindow;
$("#"+InfoWindowCount).click(function(){
alert('hi')
// if (marker.getIcon() === "/assets/MapMarker.png") {
// marker.setIcon("/assets/MapMarker1.png");
// }else{
// marker.setIcon("/assets/MapMarker.png");
// }
});
});
marker.set("id", -InfoWindowCount)
marker.setMap(map);
markerIcons.push(marker)
InfoWindowCount += 1
}
});
},"xml");
}
google.maps.event.addDomListener(window, 'load', initialize);
//controls the expanding of the about me and signin div
$("#about").hover(
function() {
$(this).find(".dynamic").slideDown();
},
function() {
$(this).find(".dynamic").slideUp();
});
});