Skip to content

Commit

Permalink
#2 Vite.js configuration working.
Browse files Browse the repository at this point in the history
  • Loading branch information
cneben committed Jul 14, 2024
1 parent c3389c0 commit 2718039
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 179 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ Our objective is to build a Maplibre web application with the following features
git clone https://github.com/cneben/react-maplibre-standalone
cd react-maplibre-standalone
npm install
npm start
npm run dev
```

Web application should then be available at: http://localhost:3000
Web application should then be available at: http://localhost:3000 (Note: port 3000 is hardcoded in `style.json` it must be free)

This README.md describe the process for generating your own GIS data:

Expand Down
18 changes: 0 additions & 18 deletions public/index.html

This file was deleted.

8 changes: 0 additions & 8 deletions public/manifest.json

This file was deleted.

3 changes: 0 additions & 3 deletions public/robots.txt

This file was deleted.

41 changes: 2 additions & 39 deletions src/App.css
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;
}
}
2 changes: 1 addition & 1 deletion src/App.tsx
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 (
Expand Down
180 changes: 92 additions & 88 deletions src/components/Map.tsx
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;
23 changes: 3 additions & 20 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,19 @@ a:hover {

body {
margin: 0;
display: flex;
/* display: flex; */
place-items: center;
min-width: 320px;
min-height: 100vh;
margin: 0;
padding: 0;
}

h1 {
font-size: 3.2em;
line-height: 1.1;
}

button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}

@media (prefers-color-scheme: light) {
:root {
color: #213547;
Expand Down

0 comments on commit 2718039

Please sign in to comment.