Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Asks user for permission to use current location and changes the map … #7

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions site.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ var dcBikeLanes = L.mapbox.featureLayer().addTo(map);
dcBikeLanes.loadURL('./DC_bikelanes.geojson')
.on('ready', done);

// Try to get user's current location and set the view
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
map.setView([position.coords.latitude, position.coords.longitude], 16);
});
}

function done() {
dcBikeLanes.setStyle({ color: 'green', weight: 2 });

Expand All @@ -19,12 +26,17 @@ function done() {
if (isNaN(radius)) radius = 500;

var buffer = turf.buffer(dcBikeLanes.getGeoJSON(), radius/5280, 'miles');
bufferLayer.setGeoJSON(buffer)
.setStyle({
"fill": "#FF69B4",
"stroke": "#FF69B4",
"stroke-width": 2
});

// Each buffer feature object needs to have the properties set individually
for (var i=0; i<buffer.features.length; i++) {
buffer.features[i].properties = {
'fill': '#56B6DB',
'stroke': '#1A3742',
'stroke-width': 2
}
}

bufferLayer.setGeoJSON(buffer);
}

run();
Expand Down