Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mollietaylor/parks
base: 8fb6e165cb
...
head fork: mollietaylor/parks
compare: c2699ce1d5
Checking mergeability… Don't worry, you can still create the pull request.
  • 3 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
35 index.html
@@ -12,17 +12,21 @@
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://mollietaylor.com/files/leaflet.ajax.js"></script>
+ <script src="parks.js"></script>
<style type="text/css">
#map {
height: 500px;
}
+
+ #distances {
+ text-align: left;
+ }
</style>
</head>
<body>
<h1>Atlanta Hikes</h1>
-<div id="map"></div>
+<div id="map"></div><div id="distances"></div>
<div id="links">
Map icons provided by <a href="http://mapicons.nicolasmollet.com/">Nicolas Mollet</a>.<br>
</div>
@@ -47,6 +51,29 @@
return R * c; // distance in km
}
+ // make array at beginning of function
+ var distances = [];
+ // returns distances to all parks in km:
+ function getAllDistances(obj, userLat, userLon) {
+ // loop
+ for (var i in obj.features) {
+ parkName = obj.features[i].properties.name;
+ parkLat = obj.features[i].geometry.coordinates[1];
+ parkLon = obj.features[i].geometry.coordinates[0];
+ distance = getDistance(parkLat, parkLon, userLat, userLon);
+ distances.push([parkName, distance]);
+ }
+ // return array
+ return distances;
+ }
+
+ function formatDistances(arr) {
+ for (var i in arr) {
+ dist = "<tr><td width=200>" + arr[i][1] + "</td><td width=50>km to</td><td>" + arr[i][0] + "</td></tr><br>";
+ $('#distances').append(dist);
+ }
+ }
+
var hikingIcon = L.icon({
iconUrl: 'hiking.png',
iconSize: [32, 37],
@@ -69,7 +96,7 @@
var marker = L.marker([e.latitude, e.longitude], {icon: hereIcon})
.bindPopup('You are here');
map.addLayer(marker);
- // console.log(getDistance(33.75, -84.38, e.latitude, e.longitude) + ' km'); // substitute first pair with location of a point
+ formatDistances(getAllDistances(parksList, e.latitude, e.longitude));
})
.on('locationerror', function(e){
console.log(e);
@@ -86,7 +113,7 @@
// console.log(getDistance(feature.geometry.coordinates[1],feature.geometry.coordinates[0], 33.75, -84.38) + ' km'); // substitute second pair with current location
};
- var hikeLayer = new L.GeoJSON.AJAX("parks.geojson", {
+ var hikeLayer = L.geoJson(parksList, {
onEachFeature: onEachHike,
pointToLayer: function(feature, latlng) {
return L.marker(latlng, {icon: hikingIcon});
View
25 parks.geojson → parks.js
@@ -1,9 +1,30 @@
-{
+parksList = {
"type": "FeatureCollection",
"features": [
+ // {
+ // "type": "Feature",
+ // "properties": {
+ // "name": "",
+ // "distance": ""
+ // },
+ // "geometry": {
+ // "type": "Point",
+ // "coordinates": []
+ // }
+ // },
{
"type": "Feature",
"properties": {
+ "name": "Skyhaven School",
+ "distance": "~0.5 miles"
+ },
+ "geometry": {
+ "type": "Point",
+ "coordinates": [-84.344338,33.725078]
+ }
+ },{
+ "type": "Feature",
+ "properties": {
"name": "DeKalb Memorial Park",
"distance": "~0.9 miles"
},
@@ -408,7 +429,7 @@
"distance": "~1 mile"
},
"geometry": {
- "type": "LineString",
+ "type": "Point",
"coordinates": [-84.351619,33.802711]
}
},{
View
4 trails.html
@@ -13,7 +13,7 @@
<![endif]-->
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
- <script type="text/javascript" src="http://mollietaylor.com/files/leaflet.ajax.js"></script>
+ <script type="text/javascript" src="trails.js"></script>
<style type="text/css">
#map {
height: 500px;
@@ -66,7 +66,7 @@
layer.bindPopup(feature.properties.name + "<br>Length of hike: " + feature.properties.distance);
};
- var hikeLayer = new L.GeoJSON.AJAX("trails.geojson", {
+ var hikeLayer = L.geoJson(trails, {
onEachFeature: onEachHike,
style: {color: '#3498db',
opacity: 1},
View
130 trails.geojson → trails.js
@@ -1,9 +1,137 @@
-{
+trails = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
+ "name" : "Skyhaven School",
+ "distance": "~0.5 miles",
+ "date": "2014/03/02"
+ },
+ "geometry": {
+ "type": "LineString",
+ "coordinates": [
+ [-84.344338,33.725078],
+ [-84.344542,33.725100],
+ [-84.344643,33.725079],
+ [-84.344738,33.725102],
+ [-84.344836,33.725121],
+ [-84.344931,33.725157],
+ [-84.345031,33.725150],
+ [-84.345121,33.725112],
+ [-84.345281,33.724968],
+ [-84.345380,33.724958],
+ [-84.345548,33.725033],
+ [-84.345554,33.725116],
+ [-84.345463,33.725084],
+ [-84.345406,33.725011],
+ [-84.345306,33.725025],
+ [-84.345229,33.725083],
+ [-84.345161,33.725142],
+ [-84.345420,33.725014],
+ [-84.345490,33.724947],
+ [-84.345561,33.724887],
+ [-84.345666,33.724876],
+ [-84.345773,33.724863],
+ [-84.345869,33.724819],
+ [-84.345957,33.724778],
+ [-84.346050,33.724812],
+ [-84.346155,33.724840],
+ [-84.346063,33.724785],
+ [-84.345984,33.724732],
+ [-84.346088,33.724776],
+ [-84.346181,33.724833],
+ [-84.346147,33.724894],
+ [-84.346189,33.724980],
+ [-84.346106,33.724938],
+ [-84.346252,33.724884],
+ [-84.346332,33.724935],
+ [-84.346477,33.724948],
+ [-84.346567,33.724990],
+ [-84.346657,33.725021],
+ [-84.346656,33.725105],
+ [-84.346613,33.725180],
+ [-84.346545,33.725260],
+ [-84.346591,33.725188],
+ [-84.346653,33.725114],
+ [-84.346691,33.725035],
+ [-84.346792,33.724985],
+ [-84.346854,33.724921],
+ [-84.346882,33.724837],
+ [-84.346777,33.724890],
+ [-84.346694,33.724849],
+ [-84.346593,33.724864],
+ [-84.346499,33.724891],
+ [-84.346433,33.724955],
+ [-84.346393,33.725033],
+ [-84.346326,33.724972],
+ [-84.346253,33.725028],
+ [-84.346160,33.725001],
+ [-84.346132,33.724917],
+ [-84.346161,33.724837],
+ [-84.346229,33.724772],
+ [-84.346327,33.724751],
+ [-84.346404,33.724691],
+ [-84.346479,33.724641],
+ [-84.346570,33.724683],
+ [-84.346672,33.724688],
+ [-84.347062,33.724755],
+ [-84.347076,33.724839],
+ [-84.347079,33.724920],
+ [-84.347160,33.724827],
+ [-84.346922,33.724995],
+ [-84.346944,33.725090],
+ [-84.346808,33.725069],
+ [-84.346804,33.725153],
+ [-84.346724,33.725105],
+ [-84.346675,33.725035],
+ [-84.346407,33.725043],
+ [-84.346390,33.724962],
+ [-84.346380,33.724877],
+ [-84.346417,33.724922],
+ [-84.346422,33.725009],
+ [-84.346344,33.725068],
+ [-84.346252,33.725097],
+ [-84.346160,33.725064],
+ [-84.346063,33.725076],
+ [-84.345964,33.725099],
+ [-84.345814,33.725110],
+ [-84.345800,33.725193],
+ [-84.345892,33.725170],
+ [-84.345895,33.725089],
+ [-84.345914,33.725007],
+ [-84.345883,33.725056],
+ [-84.345978,33.725030],
+ [-84.346079,33.725012],
+ [-84.346180,33.724982],
+ [-84.346269,33.725018],
+ [-84.346170,33.725009],
+ [-84.346083,33.724969],
+ [-84.346010,33.724909],
+ [-84.345914,33.724939],
+ [-84.345827,33.724978],
+ [-84.345734,33.725014],
+ [-84.345635,33.725030],
+ [-84.345531,33.725042],
+ [-84.345440,33.725082],
+ [-84.345336,33.725102],
+ [-84.345243,33.725133],
+ [-84.345129,33.725147],
+ [-84.345021,33.725141],
+ [-84.344921,33.725155],
+ [-84.344819,33.725141],
+ [-84.344721,33.725149],
+ [-84.344617,33.725144],
+ [-84.344518,33.725164],
+ [-84.344413,33.725170],
+ [-84.344302,33.725144],
+ [-84.344234,33.725073],
+ [-84.344218,33.724984]
+ ]
+ }
+ },{
+ "type": "Feature",
+ "properties": {
"name": "DeKalb Memorial Park",
"distance": "~0.9 miles",
"date": "2014/02/09"

No commit comments for this range

Something went wrong with that request. Please try again.