Skip to content

Track "current location" and show as a blue dot. #75

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Binary file added tnm/client/static/images/ledlightblue_16px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tnm/client/static/images/ledlightblue_48px.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion tnm/client/static/tnm.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ $(function() {

var geolocate = function() {
Transit.tryGeolocating(
function(latlng) { map.center(latlng); },
function(latlng) {
Transit.current.set = true;
Transit.current.location = latlng;
map.center(latlng);
},
function(error) { map.center(); });
}

Expand Down
21 changes: 21 additions & 0 deletions tnm/client/static/transit.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,26 @@ Transit._leafletMap.prototype.overlay = function(overlayID, overlay) {
stop.layer = stop_marker;
layers.addLayer(stop_marker);
}

// Build current location marker
if (Transit.current && Transit.current.set) {
var icon = new Transit._leafletMap.CurrentIcon(),
current_marker = new L.Marker(Transit.current.location, {icon : icon}),
popup_content = '<h3><br>Current<br>location</h3>';
current_marker.bindPopup(popup_content);
layers.addLayer(current_marker);
}

oldLayer && this.map.removeLayer(oldLayer);
this.layers[overlayID] = layers;
this.hiddenLayers[overlayID] = [];
this.map.addLayer(layers);
}

Transit.current = new Object();
Transit.current.set = false;
Transit.current.location = new L.LatLng(0, 0);

Transit._leafletMap.prototype.radius = function(latlng, radius_m) {
var radius = this.layers['radius'];
if (radius) {
Expand All @@ -427,3 +440,11 @@ Transit._leafletMap.TransitIcon = L.Icon.extend({
iconAnchor: new L.Point(13, 13),
popupAnchor: new L.Point(0, 0)
});

Transit._leafletMap.CurrentIcon = L.Icon.extend({
iconUrl: '/static/images/ledlightblue_16px.png',
shadowUrl: '',
iconSize: new L.Point(16, 16),
iconAnchor: new L.Point(13, 13),
popupAnchor: new L.Point(0, 0)
});