Draggable Marker
@@ -17,7 +18,8 @@ function ControlPanel(props) {
const lngLat = events[eventName];
return (
- {eventName}: {lngLat ? lngLat.map(round5).join(', ') : null}
+ {eventName}:{' '}
+ {lngLat ? `${round5(lngLat.lng)}, ${round5(lngLat.lat)}` : null}
);
})}
diff --git a/examples/draggable-markers/src/pin.js b/examples/draggable-markers/src/pin.tsx
similarity index 100%
rename from examples/draggable-markers/src/pin.js
rename to examples/draggable-markers/src/pin.tsx
diff --git a/examples/draggable-markers/tsconfig.json b/examples/draggable-markers/tsconfig.json
new file mode 100644
index 00000000..ff49de04
--- /dev/null
+++ b/examples/draggable-markers/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "jsx": "react",
+ "allowSyntheticDefaultImports": true,
+ "resolveJsonModule": true,
+ "moduleResolution": "node",
+ "sourceMap": true
+ }
+}
\ No newline at end of file
diff --git a/examples/draggable-markers/webpack.config.js b/examples/draggable-markers/webpack.config.js
index 78fe2a6a..ed4df0d5 100644
--- a/examples/draggable-markers/webpack.config.js
+++ b/examples/draggable-markers/webpack.config.js
@@ -5,33 +5,40 @@
const resolve = require('path').resolve;
const webpack = require('webpack');
-const BABEL_CONFIG = {
- presets: ['@babel/env', '@babel/react'],
- plugins: ['@babel/proposal-class-properties']
-};
-
const config = {
mode: 'development',
+ devServer: {
+ static: '.'
+ },
+
entry: {
- app: resolve('./src/app.js')
+ app: resolve('./src/app')
},
output: {
library: 'App'
},
+ resolve: {
+ extensions: ['.ts', '.tsx', '.js', '.json']
+ },
+
module: {
rules: [
{
- // Compile ES2015 using babel
- test: /\.js$/,
+ test: /\.(ts|js)x?$/,
include: [resolve('.')],
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
- options: BABEL_CONFIG
+ options: {
+ presets: ['@babel/env', '@babel/react']
+ }
+ },
+ {
+ loader: 'ts-loader'
}
]
}
@@ -39,7 +46,7 @@ const config = {
},
// Optional: Enables reading mapbox token from environment variable
- plugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken'])]
+ plugins: [new webpack.EnvironmentPlugin({MapboxAccessToken: ''})]
};
// Enables bundling against src in this repo rather than the installed version
diff --git a/examples/filter/app.css b/examples/filter/app.css
deleted file mode 100644
index 27e3367c..00000000
--- a/examples/filter/app.css
+++ /dev/null
@@ -1,29 +0,0 @@
-body {
- margin: 0;
- font-family: Helvetica, Arial, sans-serif;
-}
-#map {
- width: 100vw;
- height: 100vh;
-}
-
-.county-info {
- font-size: 12px;
- font-weight: 700;
-}
-
-.control-panel {
- position: absolute;
- top: 0;
- right: 0;
- max-width: 320px;
- background: #fff;
- box-shadow: 0 2px 4px rgba(0,0,0,0.3);
- padding: 12px 24px;
- margin: 20px;
- font-size: 13px;
- line-height: 2;
- color: #6b6b76;
- text-transform: uppercase;
- outline: none;
-}
diff --git a/examples/filter/index.html b/examples/filter/index.html
index 7ccf392a..0455c88d 100644
--- a/examples/filter/index.html
+++ b/examples/filter/index.html
@@ -3,7 +3,38 @@
react-map-gl Example
-
+
+
diff --git a/examples/filter/package.json b/examples/filter/package.json
index 0ae73b96..ca74eb45 100644
--- a/examples/filter/package.json
+++ b/examples/filter/package.json
@@ -1,21 +1,23 @@
{
"scripts": {
"start": "webpack-dev-server --progress --hot --open",
- "start-local": "webpack-dev-server --env.local --progress --hot --open"
+ "start-local": "webpack-dev-server --env local --progress --hot --open"
},
"dependencies": {
- "react": "^16.3.0",
- "react-dom": "^16.3.0",
- "react-map-gl": "^6.0.0"
+ "mapbox-gl": "^2.0.0",
+ "react": "^17.0.0",
+ "react-dom": "^17.0.0",
+ "react-map-gl": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
- "@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.0",
- "webpack": "^4.20.0",
- "webpack-cli": "^3.1.2",
- "webpack-dev-server": "^3.1.0"
+ "ts-loader": "^9.0.0",
+ "typescript": "^4.0.0",
+ "webpack": "^5.65.0",
+ "webpack-cli": "^4.9.0",
+ "webpack-dev-server": "^4.7.0"
}
}
diff --git a/examples/filter/src/app.js b/examples/filter/src/app.tsx
similarity index 71%
rename from examples/filter/src/app.js
rename to examples/filter/src/app.tsx
index f353e31f..1cc13510 100644
--- a/examples/filter/src/app.js
+++ b/examples/filter/src/app.tsx
@@ -1,29 +1,21 @@
import * as React from 'react';
import {useState, useMemo, useCallback} from 'react';
import {render} from 'react-dom';
-import MapGL, {Popup, Source, Layer} from 'react-map-gl';
+import Map, {Popup, Source, Layer} from 'react-map-gl';
import ControlPanel from './control-panel';
-import {countiesLayer, highlightLayer} from './map-style.js';
+import {countiesLayer, highlightLayer} from './map-style';
const MAPBOX_TOKEN = ''; // Set your mapbox token here
export default function App() {
- const [viewport, setViewport] = useState({
- latitude: 38.88,
- longitude: -98,
- zoom: 3,
- minZoom: 2,
- bearing: 0,
- pitch: 0
- });
const [hoverInfo, setHoverInfo] = useState(null);
const onHover = useCallback(event => {
const county = event.features && event.features[0];
setHoverInfo({
- longitude: event.lngLat[0],
- latitude: event.lngLat[1],
+ longitude: event.lngLat.lng,
+ latitude: event.lngLat.lat,
countyName: county && county.properties.COUNTY
});
}, []);
@@ -33,14 +25,16 @@ export default function App() {
return (
<>
-
@@ -51,13 +45,14 @@ export default function App() {
{selectedCounty}
)}
-
+
>
);
diff --git a/examples/filter/src/control-panel.js b/examples/filter/src/control-panel.tsx
similarity index 100%
rename from examples/filter/src/control-panel.js
rename to examples/filter/src/control-panel.tsx
diff --git a/examples/filter/src/map-style.js b/examples/filter/src/map-style.ts
similarity index 75%
rename from examples/filter/src/map-style.js
rename to examples/filter/src/map-style.ts
index 4749f9fa..4a13db46 100644
--- a/examples/filter/src/map-style.js
+++ b/examples/filter/src/map-style.ts
@@ -1,4 +1,6 @@
-export const countiesLayer = {
+import type {FillLayer} from 'react-map-gl';
+
+export const countiesLayer: FillLayer = {
id: 'counties',
type: 'fill',
'source-layer': 'original',
@@ -8,7 +10,7 @@ export const countiesLayer = {
}
};
// Highlighted county polygons
-export const highlightLayer = {
+export const highlightLayer: FillLayer = {
id: 'counties-highlighted',
type: 'fill',
source: 'counties',
diff --git a/examples/filter/tsconfig.json b/examples/filter/tsconfig.json
new file mode 100644
index 00000000..ff49de04
--- /dev/null
+++ b/examples/filter/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "jsx": "react",
+ "allowSyntheticDefaultImports": true,
+ "resolveJsonModule": true,
+ "moduleResolution": "node",
+ "sourceMap": true
+ }
+}
\ No newline at end of file
diff --git a/examples/filter/webpack.config.js b/examples/filter/webpack.config.js
index 78fe2a6a..ed4df0d5 100644
--- a/examples/filter/webpack.config.js
+++ b/examples/filter/webpack.config.js
@@ -5,33 +5,40 @@
const resolve = require('path').resolve;
const webpack = require('webpack');
-const BABEL_CONFIG = {
- presets: ['@babel/env', '@babel/react'],
- plugins: ['@babel/proposal-class-properties']
-};
-
const config = {
mode: 'development',
+ devServer: {
+ static: '.'
+ },
+
entry: {
- app: resolve('./src/app.js')
+ app: resolve('./src/app')
},
output: {
library: 'App'
},
+ resolve: {
+ extensions: ['.ts', '.tsx', '.js', '.json']
+ },
+
module: {
rules: [
{
- // Compile ES2015 using babel
- test: /\.js$/,
+ test: /\.(ts|js)x?$/,
include: [resolve('.')],
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
- options: BABEL_CONFIG
+ options: {
+ presets: ['@babel/env', '@babel/react']
+ }
+ },
+ {
+ loader: 'ts-loader'
}
]
}
@@ -39,7 +46,7 @@ const config = {
},
// Optional: Enables reading mapbox token from environment variable
- plugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken'])]
+ plugins: [new webpack.EnvironmentPlugin({MapboxAccessToken: ''})]
};
// Enables bundling against src in this repo rather than the installed version
diff --git a/examples/geojson-animation/app.css b/examples/geojson-animation/app.css
deleted file mode 100644
index 72db167a..00000000
--- a/examples/geojson-animation/app.css
+++ /dev/null
@@ -1,24 +0,0 @@
-body {
- margin: 0;
- background: #000;
-}
-#map {
- width: 100vw;
- height: 100vh;
-}
-
-.control-panel {
- position: absolute;
- top: 0;
- right: 0;
- max-width: 320px;
- background: #fff;
- box-shadow: 0 2px 4px rgba(0,0,0,0.3);
- padding: 12px 24px;
- margin: 20px;
- font-size: 13px;
- line-height: 2;
- color: #6b6b76;
- text-transform: uppercase;
- outline: none;
-}
diff --git a/examples/geojson-animation/index.html b/examples/geojson-animation/index.html
index 7ccf392a..89f2a3b8 100644
--- a/examples/geojson-animation/index.html
+++ b/examples/geojson-animation/index.html
@@ -3,7 +3,32 @@
react-map-gl Example
-
+
+
diff --git a/examples/geojson-animation/package.json b/examples/geojson-animation/package.json
index 0ae73b96..59cbf0c5 100644
--- a/examples/geojson-animation/package.json
+++ b/examples/geojson-animation/package.json
@@ -1,21 +1,23 @@
{
"scripts": {
"start": "webpack-dev-server --progress --hot --open",
- "start-local": "webpack-dev-server --env.local --progress --hot --open"
+ "start-local": "webpack-dev-server --env local --progress --hot --open"
},
"dependencies": {
- "react": "^16.3.0",
- "react-dom": "^16.3.0",
- "react-map-gl": "^6.0.0"
+ "react": "^17.0.0",
+ "react-dom": "^17.0.0",
+ "react-map-gl": "^7.0.0",
+ "mapbox-gl": "^2.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
- "@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.0",
- "webpack": "^4.20.0",
- "webpack-cli": "^3.1.2",
- "webpack-dev-server": "^3.1.0"
+ "ts-loader": "^9.0.0",
+ "typescript": "^4.0.0",
+ "webpack": "^5.65.0",
+ "webpack-cli": "^4.9.0",
+ "webpack-dev-server": "^4.7.0"
}
}
diff --git a/examples/geojson-animation/src/app.js b/examples/geojson-animation/src/app.tsx
similarity index 75%
rename from examples/geojson-animation/src/app.js
rename to examples/geojson-animation/src/app.tsx
index d24e06e4..c3cbdc27 100644
--- a/examples/geojson-animation/src/app.js
+++ b/examples/geojson-animation/src/app.tsx
@@ -2,13 +2,14 @@
import * as React from 'react';
import {useState, useEffect} from 'react';
import {render} from 'react-dom';
-import MapGL, {Source, Layer} from 'react-map-gl';
+import {Map, Source, Layer} from 'react-map-gl';
+import type {LayerProps} from 'react-map-gl';
import ControlPanel from './control-panel';
const MAPBOX_TOKEN = ''; // Set your mapbox token here
-const pointLayer = {
+const pointLayer: LayerProps = {
type: 'circle',
paint: {
'circle-radius': 10,
@@ -24,13 +25,6 @@ function pointOnCircle({center, angle, radius}) {
}
export default function App() {
- const [viewport, setViewport] = useState({
- latitude: 0,
- longitude: -100,
- zoom: 3,
- bearing: 0,
- pitch: 0
- });
const [pointData, setPointData] = useState(null);
useEffect(() => {
@@ -42,20 +36,21 @@ export default function App() {
return (
<>
-
{pointData && (
)}
-
+
>
);
diff --git a/examples/geojson-animation/src/control-panel.js b/examples/geojson-animation/src/control-panel.tsx
similarity index 100%
rename from examples/geojson-animation/src/control-panel.js
rename to examples/geojson-animation/src/control-panel.tsx
diff --git a/examples/geojson-animation/tsconfig.json b/examples/geojson-animation/tsconfig.json
new file mode 100644
index 00000000..ff49de04
--- /dev/null
+++ b/examples/geojson-animation/tsconfig.json
@@ -0,0 +1,10 @@
+{
+ "compilerOptions": {
+ "target": "es2020",
+ "jsx": "react",
+ "allowSyntheticDefaultImports": true,
+ "resolveJsonModule": true,
+ "moduleResolution": "node",
+ "sourceMap": true
+ }
+}
\ No newline at end of file
diff --git a/examples/geojson-animation/webpack.config.js b/examples/geojson-animation/webpack.config.js
index 78fe2a6a..ed4df0d5 100644
--- a/examples/geojson-animation/webpack.config.js
+++ b/examples/geojson-animation/webpack.config.js
@@ -5,33 +5,40 @@
const resolve = require('path').resolve;
const webpack = require('webpack');
-const BABEL_CONFIG = {
- presets: ['@babel/env', '@babel/react'],
- plugins: ['@babel/proposal-class-properties']
-};
-
const config = {
mode: 'development',
+ devServer: {
+ static: '.'
+ },
+
entry: {
- app: resolve('./src/app.js')
+ app: resolve('./src/app')
},
output: {
library: 'App'
},
+ resolve: {
+ extensions: ['.ts', '.tsx', '.js', '.json']
+ },
+
module: {
rules: [
{
- // Compile ES2015 using babel
- test: /\.js$/,
+ test: /\.(ts|js)x?$/,
include: [resolve('.')],
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
- options: BABEL_CONFIG
+ options: {
+ presets: ['@babel/env', '@babel/react']
+ }
+ },
+ {
+ loader: 'ts-loader'
}
]
}
@@ -39,7 +46,7 @@ const config = {
},
// Optional: Enables reading mapbox token from environment variable
- plugins: [new webpack.EnvironmentPlugin(['MapboxAccessToken'])]
+ plugins: [new webpack.EnvironmentPlugin({MapboxAccessToken: ''})]
};
// Enables bundling against src in this repo rather than the installed version
diff --git a/examples/geojson/app.css b/examples/geojson/app.css
deleted file mode 100644
index 86e21888..00000000
--- a/examples/geojson/app.css
+++ /dev/null
@@ -1,46 +0,0 @@
-body {
- margin: 0;
- font-family: Helvetica, Arial, sans-serif;
-}
-#map {
- width: 100vw;
- height: 100vh;
-}
-
-.control-panel {
- position: absolute;
- top: 0;
- right: 0;
- max-width: 320px;
- background: #fff;
- box-shadow: 0 2px 4px rgba(0,0,0,0.3);
- padding: 12px 24px;
- margin: 20px;
- font-size: 13px;
- line-height: 2;
- color: #6b6b76;
- outline: none;
- text-transform: uppercase;
-}
-
-label {
- display: inline-block;
- width: 100px;
-}
-
-input {
- margin-left: 20px;
- width: 160px;
-}
-
-.tooltip {
- position: absolute;
- margin: 8px;
- padding: 4px;
- background: rgba(0, 0, 0, 0.8);
- color: #fff;
- max-width: 300px;
- font-size: 10px;
- z-index: 9;
- pointer-events: none;
-}
diff --git a/examples/geojson/index.html b/examples/geojson/index.html
index 7ccf392a..0b75dc1a 100644
--- a/examples/geojson/index.html
+++ b/examples/geojson/index.html
@@ -3,7 +3,55 @@
react-map-gl Example
-
+
+
diff --git a/examples/geojson/package.json b/examples/geojson/package.json
index e1cafa41..e11ee9c5 100644
--- a/examples/geojson/package.json
+++ b/examples/geojson/package.json
@@ -1,22 +1,25 @@
{
"scripts": {
"start": "webpack-dev-server --progress --hot --open",
- "start-local": "webpack-dev-server --env.local --progress --hot --open"
+ "start-local": "webpack-dev-server --env local --progress --hot --open"
},
"dependencies": {
- "d3-scale": "^1.0.6",
- "react": "^16.3.0",
- "react-dom": "^16.3.0",
- "react-map-gl": "^6.0.0"
+ "d3-array": "^3.1.1",
+ "d3-scale": "^4.0.2",
+ "mapbox-gl": "^2.0.0",
+ "react": "^17.0.0",
+ "react-dom": "^17.0.0",
+ "react-map-gl": "^7.0.0"
},
"devDependencies": {
"@babel/core": "^7.0.0",
- "@babel/plugin-proposal-class-properties": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.0",
- "webpack": "^4.20.0",
- "webpack-cli": "^3.1.2",
- "webpack-dev-server": "^3.1.0"
+ "ts-loader": "^9.0.0",
+ "typescript": "^4.0.0",
+ "webpack": "^5.65.0",
+ "webpack-cli": "^4.9.0",
+ "webpack-dev-server": "^4.7.0"
}
}
diff --git a/examples/geojson/src/app.js b/examples/geojson/src/app.tsx
similarity index 78%
rename from examples/geojson/src/app.js
rename to examples/geojson/src/app.tsx
index 4e97e242..dfceeb29 100644
--- a/examples/geojson/src/app.js
+++ b/examples/geojson/src/app.tsx
@@ -1,22 +1,15 @@
import * as React from 'react';
import {useState, useEffect, useMemo, useCallback} from 'react';
import {render} from 'react-dom';
-import MapGL, {Source, Layer} from 'react-map-gl';
+import Map, {Source, Layer} from 'react-map-gl';
import ControlPanel from './control-panel';
-import {dataLayer} from './map-style.js';
+import {dataLayer} from './map-style';
import {updatePercentiles} from './utils';
const MAPBOX_TOKEN = ''; // Set your mapbox token here
export default function App() {
- const [viewport, setViewport] = useState({
- latitude: 40,
- longitude: -100,
- zoom: 3,
- bearing: 0,
- pitch: 0
- });
const [year, setYear] = useState(2015);
const [allData, setAllData] = useState(null);
const [hoverInfo, setHoverInfo] = useState(null);
@@ -33,7 +26,7 @@ export default function App() {
const onHover = useCallback(event => {
const {
features,
- srcEvent: {offsetX, offsetY}
+ point: {x, y}
} = event;
const hoveredFeature = features && features[0];
@@ -41,8 +34,8 @@ export default function App() {
hoveredFeature
? {
feature: hoveredFeature,
- x: offsetX,
- y: offsetY
+ x,
+ y
}
: null
);
@@ -54,15 +47,16 @@ export default function App() {
return (
<>
-
@@ -74,7 +68,7 @@ export default function App() {
Percentile: {(hoverInfo.feature.properties.percentile / 8) * 100}
)}
-
+