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

Added USA Territories to map. #17

Merged
merged 1 commit into from
Oct 13, 2022
Merged
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
46 changes: 38 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"@fortawesome/fontawesome-svg-core": "^1.2.18",
"@fortawesome/free-solid-svg-icons": "^5.8.2",
"axios": "^0.21.1",
"d3-geo": "^1.11.3",
"d3-geo-projection": "^2.6.0",
"d3-geo": "^3.0.1",
"d3-geo-projection": "^2.9.0",
"geo-albers-usa-territories": "^0.1.0",
"mapbox-gl": "^0.54.0",
"react": "^16.8.6",
"react-dom": "^16.8.6",
Expand Down
16 changes: 14 additions & 2 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import fontawesome from "./fontawesome";
const d3 = require("d3-geo");
const axios = require("axios");

//https://github.com/stamen/geo-albers-usa-territories
const geoAlbersUsaTerritories = require("geo-albers-usa-territories");

mapboxgl.accessToken =
"pk.eyJ1IjoidXJiYW5pbnN0aXR1dGUiLCJhIjoiTEJUbmNDcyJ9.mbuZTy4hI_PWXw3C3UFbDQ";

Expand Down Expand Up @@ -56,8 +59,17 @@ class App extends Component {
// Setup albersUSA projection for markers.
// @see https://github.com/developmentseed/dirty-reprojectors/issues/12.
let R = 6378137.0; // radius of Earth in meters
const projection = d3.geoAlbersUsa().translate([0, 0]).scale(R);
// This line commented out and projectionTerritories added instead
// const projection = d3.geoAlbersUsa().translate([0, 0]).scale(R);

// Setup to include US territories projectd into the map
// @see https://github.com/d3/d3-geo/issues/152
const projectionTerritories = geoAlbersUsaTerritories
.geoAlbersUsaTerritories()
.translate([0, 0])
.scale(R);
const projectionMercartor = d3.geoMercator().translate([0, 0]).scale(R);

// API URL set in .env
axios
.get(process.env.REACT_APP_API_URL)
Expand Down Expand Up @@ -115,7 +127,7 @@ class App extends Component {
})
.setLngLat(
projectionMercartor.invert(
projection(marker.geometry.coordinates)
projectionTerritories(marker.geometry.coordinates)
)
)
.setPopup(mypopup) // add popups
Expand Down