-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
389 lines (345 loc) · 13.4 KB
/
index.html
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Find a Farmers Market Near You in New York City</title>
<link rel="stylesheet" href="css/foundation.css">
<script src="js/vendor/custom.modernizr.js"></script>
<style>
/* Testing sticky map stuff, will move to CSS file once solved */
#geo-wrapper img {
max-width:none;
}
.page-wrap {
min-height: 100%;
/* equal to footer height */
margin-bottom: -142px;
}
.page-wrap:after {
content: "";
display: block;
}
.footer, .page-wrap:after {
/* .push must be the same height as footer */
height: 142px;
}
@media all and (max-width: 980px) {
#fixit {
position:relative;
}
}
@media all and (min-width: 980px) {
#fixit {
position:fixed;
max-width:553px;
}
}
</style>
</head>
<body>
<div class="row page-wrap">
<div class="large-12 columns">
<div class="row">
<div class="large-12 columns">
<h1>Find a Farmers Market Near You in New York City</h1>
<hr />
</div>
</div>
<div class="row">
<div class="large-7 columns">
<!--
Need to figure out how to submit with Enter key elegantly, tried
$('#inputTextAddress').keydown(function(event){
if(event.keyCode==13){
$('#searchAddress').trigger('click');
}
});
-->
<form onsubmit="$('#searchAddress').trigger('click');return false">
<input type="text" id="inputTextAddress" placeholder="Address or Zip Code">
</form>
</div>
<div class="large-1 columns">
<a href="#" id="searchAddress" class="button prefix"><i class="foundicon-search"></i></a>
</div>
<div class="large-1 columns">
<p>OR</p>
</div>
<div class="large-3 columns">
<a href="#" id="geolocateMe" class="small button">Nearby</a>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="panel">
<h4>Farmers Markets near <span id="location"></span></h4>
</div>
</div>
</div>
<div class="row">
<div class="large-5 columns">
<div id="markets">
<div class="panel">
<p>This is an alpha-level app, so far. To find a farmers market within 1 mile of a given location, type an address in the search bar or allow the browser to auto-detect your location when you click on the "Nearby" button.</p>
<p>Features I plan to add:</p>
<ul>
<li>Distance from current location: XX mi</li>
<li>Products available</li>
<li>Better website links</li>
<li>Detect whether a market is open or closed at time of search</li>
<li>Prioritize order of markets based on distance and open/closed</li>
<li>local storage or cache</li>
</ul>
</div>
</div>
</div>
<div class="large-7 columns" style="height:425px;">
<div id="fixit" style="width:100%; height:425px;">
<div id="geo-wrapper" style="height:425px; width:100%;" class="panel"></div>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns"> </div>
</div>
</div>
</div>
<div class="row footer">
<div class="large-12 columns">
<hr/ >
<p>Please direct questions or comments to: <a class="footerLink" href="mailto:mtaylor@megantaylor.org">mtaylor@megantaylor.org</a>.</p>
<p>This project was originally concieved as an app to find an open farmers market near a user's location. You can see the seed of the idea on my <a target="_blank" class="footerLink" href="http://www.megantaylor.org/2012/12/13/visualizing-farmers-markets-in-nyc/">blog</a>. I finally got a chance to start working on it while taking Thinkful's Front-end Web Development class in the fall of 2013.</p>
<p>Farmers Market data from <a target="_blank" class="footerLink" href="https://data.ny.gov">State of New York Open Data</a>. Design and development by <a target="_blank" class="footerLink" href="http://www.megantaylor.org">Megan Taylor</a>.</p>
</div>
</div>
<script>
document.write('<script src=' + ('__proto__' in {} ? 'js/vendor/zepto' : 'js/vendor/jquery') + '.js><\/script>')
</script>
<script src="js/foundation.min.js"></script>
<script>
$(document).foundation();
</script>
<script type="text/javascript"
src="js/geoposition/geoPosition.js"></script>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyAufQG3-_yBGqDKE7dTf53zpqkhUKC8tao&sensor=true"></script>
<script>
// Initializing Google Maps stuff
$( document ).ready(function() {
initialize();
});
google.maps.visualRefresh = true;
var geocoder;
var map;
var infowindow;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(40.6700, -73.9400);
var myOptions = {
zoom: 10,
center: latlng,
scrollwheel: false, //this totally doesn't work?!
MapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($('#geo-wrapper')[0], myOptions);
}
// Grab address from input field, send to Google geocoder, set map to center on address, create location marker
$("#searchAddress").click(function() {
var sAddress = $('#inputTextAddress').attr('value');
geocoder.geocode({
'address': sAddress
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latitude = results[0].geometry.location.lat();
var longitude = results[0].geometry.location.lng();
map = new google.maps.Map($('#geo-wrapper')[0]); //clear map on new search
map.setCenter(results[0].geometry.location);
map.setZoom(14);
var marker = new google.maps.Marker({ //this is a red location marker
map: map,
draggable: false,
title: 'You are here (more or less)',
position: results[0].geometry.location
});
//is there a more elegant, DRY way to deal with the markers?
codeLatLng(latitude, longitude);
getResults(latitude, longitude);
//at some point, put these lat/lng points into variables
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
});
//Need to figure out how to get Enter key to trigger the searchAddress click function
//$('#inputTextAddress').keydown(function(event){
// if(event.keyCode==13){
// $('#searchAddress').click();
// }
//});
//Browser support for geolocation messages
$(function () {
if (geoPosition.init()) {
} else {
alert('Your browser does not support geolocation.');
}
});
//If user clicks "Nearby" button, try to find location via browser
$('#geolocateMe').click(function() {
geoPosition.getCurrentPosition(showMap, showMapError);
});
//If geolocation fails
function showMapError() {
alert('Unable to determine your location.');
}
//If geolocation succeeds, set new map center, create marker for location, call codeLatLng function and getResults function
function showMap(loc) {
map = new google.maps.Map($('#geo-wrapper')[0]); //clear map on new search
var center = new google.maps.LatLng(loc.coords.latitude, loc.coords.longitude);
console.log(loc.coords.latitude, loc.coords.longitude);
map.setCenter(center);
map.setZoom(14);
var marker = new google.maps.Marker({ //this is a red location marker
map: map,
position: center,
draggable: false,
title: 'You are here (more or less)'
});
codeLatLng(loc.coords.latitude, loc.coords.longitude);
getResults(loc.coords.latitude, loc.coords.longitude);
}
//Reverse geocoder to put user's location in top panel
function codeLatLng(lat, lng) {
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({
'latLng': latlng
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
$('#location').text(results[1].formatted_address);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}
//Add a marker for each farmers market near search location, change marker to green, create infowindow, run selectMarket function
function addMarker(location, marketName, panelID) {
var marker = new google.maps.Marker({ //this is a green market icon
map: map,
position: location,
draggable: false,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
title: marketName
});
//when you click on a marker, open infowindow closes, highlighted panel turns nuetral, then calls two functions to open new infowindow and highlight / scroll to matching panel
google.maps.event.addListener(marker, 'click', function () {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({
content: "<p>" + marketName + "</p>"
});
$('.panel').removeClass("highlight");
infowindow.open(map, marker);
selectMarket(panelID);
});
}
//highlight panel in left column correlating to marker and scroll map to panel. this needs work, still playing with stuff
function selectMarket(panelID) {
//console.log('#'+ panelID + '');
//$('#'+ panelID + '').attr( 'name', 'foo' );
//$('html,body').animate({scrollTop: div[name='foo'].offset().top},'slow');
//$('#'+ panelID + '').attr( 'name', '' );
$('#' + panelID + '').addClass("highlight");
window.location = '#' + panelID + '';
}
//finally getting actual farmers market data from data.ny.gov
function getResults(lat, lng) {
var url = "http://data.ny.gov/resource/n6w2-gz88.json?$where=within_circle(location_points, " + lat + "," + lng + ", 1610)";
//1610 is one mile in meters. at some point might have distance slider, will need to put distance into a variable
$.get(url, function (data) {
$("#markets").empty(); //empty left column for new results
for (var i = 0; i < data.length; i++) {
var website = '';
var current = data[i];
if (current.market_link.url !== "") {
website = "<a target='_blank' href=" + current.market_link.url + ">Website</a>"; //link to market website, if any
}
var panelID = current.market_name.replace(/\s+/g, ''); //create ID for panels for targeting with selectMarket function
var panel = $('<div class="panel" id="' + panelID + '"><h5>' + current.market_name + '</h5> <p>' + current.location + '<br /> <a target="_blank" href=' + encodeURI("http://maps.google.com?q=" + current.latitude + "," + current.longitude + "") + '>Map</a><br /> Open ' + current.operation_hours + "<br />" + current.operation_season + '<br /> ' + website + '</div>');
//dump market data into panel!
$("#markets").append(panel);
var newMarker = new google.maps.LatLng(current.latitude, current.longitude);
var newMarkerTitle = current.market_name;
addMarker(newMarker, newMarkerTitle, panelID); //create markers for farmers markets
//getUSDAResults(parseFloat(current.latitude), parseFloat(current.longitude));
}
if (data.length === 0) {
var emptyPanel = $('<div class="panel" id="noMarkets"><p>Oops! I couldn\'t find a farmers market within 1 mile of your location. This app only supports searches within New York City. Please try again!</p></div>');
$("#markets").append(emptyPanel);
}
});
}
/*
USDA API STUFF
function getUSDAResults(lat, lng) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
// submit a get request to the restful service mktDetail.
url: "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/locSearch?lat=" + lat + "&lng=" + lng,
dataType: 'jsonp',
success: function(data) {
searchResultsHandler(data);
},
error : function(err, req) {
console.log("Your browser broke!");
} });
}
//iterate through the JSON result object.
function searchResultsHandler(searchresults) {
for (var key in searchresults) {
//console.log(key);
var results = searchresults[key];
for (var i = 0; i < results.length; i++) {
var result = results[i];
for (var key in result) {
//only do an alert on the first search result
if (i == 0) {
console.log(result.id);
}
}
}
}
}
*/
/* function getDetails(id) {
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
// submit a get request to the restful service mktDetail.
url: "http://search.ams.usda.gov/farmersmarkets/v1/data.svc/mktDetail?id=" + id,
dataType: 'jsonp',
success: function(data) {
detailResultsHandler(data, id);
},
error : function(err, req) {
console.log("Your browser broke!");
} });
}
//iterate through the JSON result object.
function detailResultsHandler(detailresults, id) {
for (var key in detailresults) {
//console.log(key);
var results = detailresults[key];
//console.log(results);
}
*/
</script>
<!--
SOMEDAY CODE
<p style="float:right; color:#C60F13;"><i class="foundicon-clock"></i> Closed Now</p><p style="float:right; color:#457A1A;"><i class="foundicon-clock"></i> Open Now</p><p style="clear:both;">Distance from current location: XX mi</p><p>Products: Products</p><p><a href="http://www.yelp.com/biz/staten-island-ferry-whitehall-terminal-greenmarket-ny">Yelp</a></p> -->
</body>
</html>