-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add color-coded routes and extremely basic route and station tooltips to map #103
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,50 @@ | ||
export function initializeMap(coordinates, stations, iconUrl) { | ||
export function initializeMap(coordinates, stations, iconUrl, routes) { | ||
// Initialize the map at center of city | ||
var map = L.map('map').setView(coordinates, 13); | ||
|
||
// Add a tile layer | ||
L.tileLayer('https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png', { | ||
attribution: | ||
'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, © <a href="https://carto.com/attribution">CARTO</a>', | ||
// attribution: | ||
// 'Map data (c) <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, (c) <a href="https://carto.com/attribution">CARTO</a>', | ||
subdomains: 'abcd', | ||
maxZoom: 19, | ||
}).addTo(map); | ||
|
||
// Custom icon for smaller markers | ||
var smallIcon = L.icon({ | ||
iconUrl: iconUrl, // URL to a smaller icon image | ||
iconSize: [15, 15], | ||
iconSize: [15, 15], | ||
iconAnchor: [6, 6], | ||
}); | ||
|
||
var markers = L.markerClusterGroup(); | ||
var markers = L.markerClusterGroup({ | ||
disableClusteringAtZoom: 16 | ||
}); | ||
|
||
for (var i = 0; i < stations.length; i++) { | ||
var station = stations[i]; | ||
var marker = L.marker([station[0], station[1]],{icon: smallIcon}); | ||
var marker = L.marker([station[0], station[1]], { icon: smallIcon }); | ||
marker.bindTooltip(station[2]); | ||
console.log(station[2]); | ||
markers.addLayer(marker); | ||
}; | ||
|
||
map.addLayer(markers); | ||
|
||
|
||
// Add routes layer | ||
|
||
L.geoJSON(routes, { | ||
style: function (feature) { | ||
return { | ||
color: '#' + feature.properties.color, | ||
weight: 3, | ||
"opacity": .7 | ||
}; | ||
}, | ||
onEachFeature: function (feature, layer) { | ||
layer.bindPopup(feature.properties.route_name); | ||
} | ||
}).addTo(map); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great note, do you notice slowness from loading all of these routes? If so maybe this is a candidate for caching since this data will generally not be changing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this out and it took about a minute to load the chicago page the first time, we may need to look into ways to cache, or auto-load on initialization, or only load some layers at once to reduce how much is being pulled in at a time (but this can be a ticket for later).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This took a minute or two for me to load too. I'm also wondering if splitting this into two functions may be better the pins need to be dynamically loaded and the routes don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it's taking maybe 30-45 seconds to load and this is probably why. Agree that refactoring to speed it up should be its own ticket