-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtrackliz.js
220 lines (186 loc) · 7.25 KB
/
trackliz.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
218
219
220
Markers = new Mongo.Collection('markers');
if (Meteor.isClient)
{
Accounts.ui.config({
passwordSignupFields: "USERNAME_ONLY"
});
}
if (Meteor.isClient) {
Template.map.onCreated(function() {
GoogleMaps.ready('map', function(map) {
//Add a new marker with the given properties
google.maps.event.addListener(map.instance, 'click', function(event) {
//Store marker on database
Markers.insert({
lat: event.latLng.lat(),
lng: event.latLng.lng(),
score: 0,
issue_desc: "please describe the issue",
comments: "tell us about it",
});
});
var markers = {};
//add Elizabeth Trail on map
var ctaLayer = new google.maps.KmlLayer({
url: 'https://dl.dropboxusercontent.com/u/7958625/ElizabethRiverTrail.kml.xml',
map: map.instance
});
Markers.find().observe({
added: function(document) {
// add marker on the actual Google map
var marker = new google.maps.Marker({
draggable: true,
animation: google.maps.Animation.DROP,
position: new google.maps.LatLng(document.lat, document.lng),
map: map.instance,
id: document._id
});
google.maps.event.addListener(marker, 'dragend', function(event) {
Markers.update(marker.id, {
$set: {
lat: event.latLng.lat(),
lng: event.latLng.lng()
}
});
});
markers[document._id] = marker;
//ADD marker listener here so that a new window can be popped up
var dbMarker = Markers.findOne(marker.id);
var contentString = '<div id="content">' +
'<div id="marker_info">' +
'<h1> Current Info:</h1>' +
'<p>Latitude: ' + dbMarker.lat + '</p>' +
'<p>Longitube: ' + dbMarker.lng + '</p>' +
'<p>Scores: ' + dbMarker.score + '</p>' +
'<p>-------------------------</p>' +
'</div> ' +
'<form class="info_box">' +
'Issue Description: <br>' +
'<input type="text" name="' + dbMarker.issue_desc + '"><br>' +
'Comments: <br>' +
'<textarea name="comments" rows="4" cols="30">' +
dbMarker.comments + '</textarea><br>' +
'<input type="button" name="thumbup" value="Thumbup" >' +
'<input type="button" name="thumbdown" value="ThumbDown" >' +
'</form>"' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('mouseover', function() {
infowindow.open(map.instance, marker);
});
infowindow.addEventListener('rightclick', function(){
infowindow.getElementById("thumbup").addEventListener("click", function() {
//alert("Hello World!");
infowindow.close();
Markers.update(marker.id, {
$set: {
score: 10
}
});
infowindow.open(map.instance, marker);
});
infowindow.close();
});
/*
infowindow.getElementById("thumbup").addEventListener("click", function() {
//alert("Hello World!");
//dbMarker.score = dbMarker.score + 1;
infowindow.close();
Markers.update(marker.id, {
$set: {
score: 10
}
});
//infowindow.open(map.instance, marker);
});
*/
},
changed: function(newDocument, oldDocument) {
markers[newDocument._id].setPosition({
lat: newDocument.lat,
lng: newDocument.lng
});
},
removed: function(oldDocument) {
markers[oldDocument._id].setMap(null);
google.maps.event.clearInstanceListeners(markers[oldDocument._id]);
delete markers[oldDocument._id];
}
/*
document.getElementById("thumbup").addEventListener("click", function() {
alert("Hello World!");
});
*/
});
});
});
//client code
Meteor.startup(function() {
GoogleMaps.load();
});
Template.body.helpers({
exampleMapOptions: function() {
// Make sure the maps API has loaded
if (GoogleMaps.loaded()) {
var options = {
center: new google.maps.LatLng(36.8, -76.285),
//center: new google.maps.LatLng(41.876, -87.624),
zoom: 10
};
return options;
}
}
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.
/*
function initMap() {
var uluru = {
lat: -25.363,
lng: 131.044
};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
var contentString = '<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<h1 id="firstHeading" class="firstHeading">Uluru</h1>' +
'<div id="bodyContent">' +
'<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
'sandstone rock formation in the southern part of the ' +
'Northern Territory, central Australia. It lies 335 km (208 mi) ' +
'south west of the nearest large town, Alice Springs; 450 km ' +
'(280 mi) by road. Kata Tjuta and Uluru are the two major ' +
'features of the Uluru - Kata Tjuta National Park. Uluru is ' +
'sacred to the Pitjantjatjara and Yankunytjatjara, the ' +
'Aboriginal people of the area. It has many springs, waterholes, ' +
'rock caves and ancient paintings. Uluru is listed as a World ' +
'Heritage Site.</p>' +
'<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">' +
'https://en.wikipedia.org/w/index.php?title=Uluru</a> ' +
'(last visited June 22, 2009).</p>' +
'</div>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var marker = new google.maps.Marker({
position: uluru,
map: map,
title: 'Uluru (Ayers Rock)'
});
marker.addListener('click', function() {
infowindow.open(map, marker);
});
}
*/