Skip to content

Commit

Permalink
Merge pull request #3 from cneben/m/#2-maintenance-vitejs
Browse files Browse the repository at this point in the history
M/#2 maintenance update from CR to vitejs, update to latest maplibre
  • Loading branch information
cneben authored Jul 14, 2024
2 parents 74dda90 + 2718039 commit da5db49
Show file tree
Hide file tree
Showing 19 changed files with 252 additions and 12,789 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/node_modules
/.pnp
.pnp.js
package-lock.json

# testing
/coverage
Expand Down
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
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<!-- <link rel="icon" type="image/svg+xml" href="/vite.svg" /> -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Maplibre standalone sampl</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
12,486 changes: 0 additions & 12,486 deletions package-lock.json

This file was deleted.

61 changes: 22 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,47 +1,30 @@
{
"name": "react-maplibre-standalone",
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.10.5",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"maplibre-gl": "^3.0.0-pre.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"devDependencies": {
"typescript": "^4.9.4",
"@types/react": "^18.0.26",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.17",
"@types/react-dom": "^18.0.10"
},
"version": "0.3.0",
"type": "module",
"scripts": {
"start": "react-scripts start",
"build": "tsc",
"test": "react-scripts test",
"eject": "react-scripts eject"
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
"dependencies": {
"react": "^18.3.1",
"react-dom": "^18.3.1",
"maplibre-gl": "^4.5.0",
"@emotion/react": "^11.11.4"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
"devDependencies": {
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@typescript-eslint/eslint-plugin": "^7.13.1",
"@typescript-eslint/parser": "^7.13.1",
"@vitejs/plugin-react": "^4.3.1",
"eslint": "^8.57.0",
"eslint-plugin-react-hooks": "^4.6.2",
"eslint-plugin-react-refresh": "^0.4.7",
"typescript": "^5.2.2",
"vite": "^5.3.1"
}
}
41 changes: 0 additions & 41 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.

5 changes: 5 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#root {
margin: 0 auto;
padding: 0;
text-align: center;
}
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);

React.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;
Loading

0 comments on commit da5db49

Please sign in to comment.