Skip to content

Commit

Permalink
Lab 07 - Step 03
Browse files Browse the repository at this point in the history
added bike station data
  • Loading branch information
ikrvb1 committed Feb 26, 2025
1 parent f6654e7 commit 35257c8
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
11 changes: 10 additions & 1 deletion global.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ html, body {
height: 100%; /* Adjust height to your desired size */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Optional: subtle shadow for effect */
border-radius: 8px; /* Optional: rounded corners */
}
}

#map svg {
position: absolute;
z-index: 1; /* Ensure it's above the map */
width: 100%;
height: 100%;
pointer-events: none; /* Allows interaction with the map below */
opacity: 100%; /* Makes the overlay semi-transparent */
}
4 changes: 3 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
</head>
<body>
<h1>🚴🏼‍♀️Geospatial Study of Cycling Patterns</h1>
<div id="map"></div>
<div id="map">
<svg></svg>
</div>
</body>
</html>
48 changes: 44 additions & 4 deletions map.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as d3 from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';
import mapboxgl from 'https://cdn.jsdelivr.net/npm/[email protected]/+esm';

console.log("Mapbox GL JS Loaded:", mapboxgl);
Expand All @@ -15,12 +16,12 @@ const map = new mapboxgl.Map({
maxZoom: 18 // Maximum allowed zoom
});

map.on('load', async () => {
map.on('load', async () => {
map.addSource('boston_route', {
type: 'geojson',
data: 'https://bostonopendata-boston.opendata.arcgis.com/datasets/boston::existing-bike-network-2022.geojson'
});

map.addLayer({
id: 'bike-lanes',
type: 'line',
Expand All @@ -42,9 +43,48 @@ map.on('load', async () => {
type: 'line',
source: 'cambridge_route',
paint: {
'line-color': '#CC5500', // Corrected color code
'line-color': '#CC5500',
'line-width': 2.5,
'line-opacity': 0.6
}
});
});

const jsonurl = 'https://dsc106.com/labs/lab07/data/bluebikes-stations.json';
const jsonData = await d3.json(jsonurl);

let stations = jsonData.data.stations;
console.log('Stations Array:', stations);

const svg = d3.select('#map').select('svg');

function getCoords(station) {
const point = new mapboxgl.LngLat(+station.lon, +station.lat);
const { x, y } = map.project(point);
return { cx: x, cy: y };
}

const circles = svg.selectAll('circle')
.data(stations)
.enter()
.append('circle')
.attr('r', 5)
.attr('fill', 'steelblue')
.attr('stroke', 'white')
.attr('stroke-width', 1)
.attr('opacity', 0.8);

function updatePositions() {
circles
.attr('cx', d => getCoords(d).cx)
.attr('cy', d => getCoords(d).cy);
}

updatePositions();

map.on('move', updatePositions);
map.on('zoom', updatePositions);
map.on('resize', updatePositions);
map.on('moveend', updatePositions);
});


0 comments on commit 35257c8

Please sign in to comment.