-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaps.js
More file actions
214 lines (154 loc) · 4.67 KB
/
Copy pathMaps.js
File metadata and controls
214 lines (154 loc) · 4.67 KB
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
Locations = new Meteor.Collection("locations")
if (Meteor.isClient) {
var jsMap
var pos = Locations.find({}).fetch()
Template.actualMap.rendered = function(){
var myOptions = {
zoom: 4,
minZoom: 4,
center: new google.maps.LatLng(39.0997265 , -94.57856670000001 ),
mapTypeId: 'roadmap',
disableDefaultUI: true
};
jsMap = new google.maps.Map($('#map')[0], myOptions);
console.log(typeof jsMap)
return jsMap
}
Template.myMap.greeting = function () {
return "Welcome to Maps.";
};
Template.myMap.events({
'click input' : function () {
// template data, if any, is available in 'this'
// console.log(Session.get("currentSess"))
}
});
var myMarkers = []
var height = function(){
return 40+40
}
var width = function(width){
width = width+=20
return width
}
var mapURL = function(){
if (mapholes < 10)
return "/red.png"
return "/tick-mark-blue.png"
}
var mapIcon={
url: "/tick-mark-blue.png",
scaledSize: {
width: width(30),
height: height(),
widthUnit: "px",
heightUnit: "px"}
}
var mapIcon2={
url: "/tick-mark-blue.png",
scaledSize: {width: 30, height:30, widthUnit: "px", heightUnit: "px"}
}
Template.myMap.rendered = function(){
$(document).ready(function(){
//Set marker from db
var geocoder = new google.maps.Geocoder()
var pos = Locations.find({}).fetch();
var iconObj = function(){
if(elem.holes > 20)
return "/red.png"
return "/tick-mark-blue.png"
}
$.each(pos, function (i, elem) {
var newLatLng = new google.maps.LatLng(elem.whole.jb, elem.whole.kb);
var marker = new google.maps.Marker({
position: newLatLng,
map: jsMap,
draggable: false,
animation: google.maps.Animation.DROP,
icon: {
url: function(){
if(elem.holes > 20)
return "/red.png"
return "/tick-mark-blue.png"
}(),
scaledSize: {width: 30 + elem.holes, height:30 + elem.holes, widthUnit: "px", heightUnit: "px"}
},
id: i
});
console.log(elem.holes)
google.maps.event.addListener(marker, 'click', function(){
Session.set("mapID", elem._id)
console.log("Listener")
})
google.maps.event.addListener(marker, 'dblclick', function(){
console.log("DOUBLE CLICK")
var self = this
resize = function(){
self.setIcon(mapIcon)
console.log("SECRET DOUBLE CLICK FUNCTION")
}
})
myMarkers.push(marker)
})
//Grab location from input
$("#encodeSubmit").click(function(){
var address = $("#address").val()
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
jsMap.setCenter(results[0].geometry.location);
var pointzzz = results[0].geometry.location
console.log("Important LatLng " + pointzzz)
console.log(results[0].geometry.location.jb)
console.log(results[0].geometry.location.kb)
x = results[0].geometry.location.jb
y = results[0].geometry.location.kb
//make sure x&y don't already exist
if(!Locations.find({x: x, y:y}).count()>0){
//Insert X&Y coordinates
Locations.insert({
whole: results[0].geometry.location,
x: x,
y: y,
holes: 0,
free: true
})
//And plant new marker.
var marker = new google.maps.Marker({
position: pointzzz,
map: jsMap,
draggable:false,
animation: google.maps.Animation.DROP
});
}//end if
else{
(function(){
console.log("Already exists")
$("#alertArea").append("<div class='alert alert-error'>Already Exists</div>")
setTimeout(function(){
$('#alertArea').empty()},1000)
})()
}
}
})
})
})
}
Template.render.foo = function(){
var xar = Session.get("mapID")
return Locations.find({"_id": xar})
}
Template.render.events({
'click #augment' : function () {
console.log("Clicked'")
Locations.update(Session.get("mapID"), {$inc: {holes: 1}})
//call a function which increases icon size
currentMarker = myMarkers[2]
google.maps.event.trigger(currentMarker, 'dblclick', resize());
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}