-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
100 additions
and
179 deletions.
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,42 +1,5 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
padding: 0; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
transition: filter 300ms; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} | ||
} |
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,5 +1,5 @@ | ||
import React from 'react'; | ||
import Map from './components/Map'; | ||
import './App.css' | ||
|
||
function App() { | ||
return ( | ||
|
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,97 +1,101 @@ | ||
/** @jsxImportSource @emotion/react */ | ||
import React, { useRef, useEffect, useState } from 'react' | ||
import maplibregl from 'maplibre-gl' | ||
import 'maplibre-gl/dist/maplibre-gl.css' | ||
import { useRef, useEffect, useState } from "react"; | ||
import maplibregl from "maplibre-gl"; | ||
import "maplibre-gl/dist/maplibre-gl.css"; | ||
|
||
const Map = () => { | ||
const mapContainer = useRef<HTMLDivElement | null>(null); | ||
const map = useRef<maplibregl.Map | null>(null); | ||
const [lat] = useState(45.92); | ||
const [lng] = useState(6.87); | ||
const [zoom] = useState(14); | ||
const mapContainer = useRef<HTMLDivElement | null>(null); | ||
const map = useRef<maplibregl.Map | null>(null); | ||
const [lat] = useState(45.92); | ||
const [lng] = useState(6.87); | ||
const [zoom] = useState(14); | ||
|
||
useEffect(() => { | ||
if (map.current) return; | ||
map.current = new maplibregl.Map({ | ||
container: mapContainer.current as HTMLElement, | ||
style: `http://localhost:3000/style.json`, | ||
center: [lng, lat], | ||
zoom: zoom, | ||
antialias: true, | ||
maxPitch: 80, | ||
maplibreLogo: true, | ||
maxBounds: [6.540000, 45.770000, 7.160000, 46.040000] | ||
}); | ||
useEffect(() => { | ||
if (map.current) return; | ||
map.current = new maplibregl.Map({ | ||
container: mapContainer.current as HTMLElement, | ||
style: `/style.json`, | ||
center: [lng, lat], | ||
zoom: zoom, | ||
antialias: true, | ||
maxPitch: 80, | ||
maplibreLogo: true, | ||
maxBounds: [6.54, 45.77, 7.16, 46.04], | ||
}); | ||
|
||
// 'building' layer in the streets vector source contains building-height | ||
// data from OpenStreetMap. | ||
map.current.on('load', function () { | ||
var layers = map.current!.getStyle().layers; | ||
map.current!.addLayer( | ||
{ | ||
id: 'building-3d', | ||
source: 'openmaptiles', | ||
'source-layer': "building", | ||
filter: ["all", ["!has", "hide_3d"]], | ||
type: 'fill-extrusion', | ||
minzoom: 13, | ||
layout: { visibility: "visible" }, | ||
paint: { | ||
'fill-extrusion-color': '#aaa', | ||
// use an 'interpolate' expression to add a smooth transition effect to the | ||
// buildings as the user zooms in | ||
"fill-extrusion-height": { | ||
"property": "render_height", | ||
"type": "identity" | ||
}, | ||
'fill-extrusion-base': { | ||
"property": "min_height", | ||
"type": "identity" | ||
}, | ||
'fill-extrusion-opacity': 0.6 | ||
} | ||
}, | ||
'waterway-name' | ||
); | ||
}); | ||
|
||
map.current.addControl( | ||
new maplibregl.NavigationControl({ | ||
visualizePitch: true, | ||
showZoom: true, | ||
showCompass: true | ||
}), | ||
'top-right') | ||
map.current.addControl( | ||
new maplibregl.TerrainControl({ | ||
source: 'terrain_source', | ||
exaggeration: 1 | ||
}) | ||
); | ||
map.current.addControl( | ||
new maplibregl.ScaleControl({ | ||
maxWidth: 300, | ||
unit: 'metric' | ||
})) | ||
// 'building' layer in the streets vector source contains building-height | ||
// data from OpenStreetMap. | ||
map.current.on("load", function () { | ||
var layers = map.current!.getStyle().layers; | ||
map.current!.addLayer( | ||
{ | ||
id: "building-3d", | ||
source: "openmaptiles", | ||
"source-layer": "building", | ||
filter: ["all", ["!has", "hide_3d"]], | ||
type: "fill-extrusion", | ||
minzoom: 13, | ||
layout: { visibility: "visible" }, | ||
paint: { | ||
"fill-extrusion-color": "#aaa", | ||
// use an 'interpolate' expression to add a smooth transition effect to the | ||
// buildings as the user zooms in | ||
"fill-extrusion-height": { | ||
property: "render_height", | ||
type: "identity", | ||
}, | ||
"fill-extrusion-base": { | ||
property: "min_height", | ||
type: "identity", | ||
}, | ||
"fill-extrusion-opacity": 0.6, | ||
}, | ||
}, | ||
"waterway-name" | ||
); | ||
}); | ||
|
||
return ( | ||
<div css={{ | ||
position: 'relative', | ||
width: '100%', | ||
height: '100vh' | ||
}}> | ||
<div | ||
ref={mapContainer} | ||
css={{ | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100vh', | ||
backgroundColor: '#c0ddfd' | ||
}} | ||
/> | ||
</div> | ||
map.current.addControl( | ||
new maplibregl.NavigationControl({ | ||
visualizePitch: true, | ||
showZoom: true, | ||
showCompass: true, | ||
}), | ||
"top-right" | ||
); | ||
map.current.addControl( | ||
new maplibregl.TerrainControl({ | ||
source: "terrain_source", | ||
exaggeration: 1, | ||
}) | ||
); | ||
} | ||
map.current.addControl( | ||
new maplibregl.ScaleControl({ | ||
maxWidth: 300, | ||
unit: "metric", | ||
}) | ||
); | ||
}); | ||
|
||
return ( | ||
<div | ||
css={{ | ||
position: "relative", | ||
width: "100%", | ||
height: "100vh", | ||
}} | ||
> | ||
<div | ||
ref={mapContainer} | ||
css={{ | ||
position: "absolute", | ||
width: "100%", | ||
height: "100vh", | ||
backgroundColor: "#c0ddfd", | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Map; | ||
export default 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