Skip to content

Commit 9d05b34

Browse files
Ihor DykhtaIhor Dykhta
authored andcommitted
custom style example
Signed-off-by: Ihor Dykhta <ihordykhta@Ihors-MacBook-Pro.local>
1 parent 67630a6 commit 9d05b34

11 files changed

Lines changed: 120 additions & 99 deletions

File tree

examples/custom-map-style/.babelrc

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# https://yarnpkg.com/configuration/yarnrc
2+
nodeLinker: node-modules
3+
# Define the registry to use when fetching packages.
4+
npmRegistryServer: 'https://registry.yarnpkg.com'

examples/custom-map-style/README.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,41 @@
22

33
![map layers](https://studio-public-data.foursquare.com/statics/keplergl/documentation/f-map-styles-8.jpg 'custom map style')
44

5-
Demo how to use kepler.gl with other basemap services other than Mapbox.
5+
Demo showing how to use kepler.gl with basemap services other than Mapbox.
66

7-
Read more about [Custom Map Style][custom-map-styles]
7+
Read more about [Custom Map Style][custom-map-styles].
88

9-
### Run Example
9+
## Pre-requirements
1010

11-
#### 1. Install
11+
- [Node.js ^20.x](http://nodejs.org)
12+
- [Yarn 4.4.0](https://yarnpkg.com): See the [installation instructions][yarn-install].
13+
14+
## 1. Install Dependencies
15+
16+
Go to the `examples/custom-map-style` directory and run:
1217

1318
```sh
14-
yarn
19+
touch yarn.lock && yarn
1520
```
1621

17-
#### 2. Start the app
22+
> `touch yarn.lock` is required once to mark this directory as a standalone Yarn project,
23+
> independent of the monorepo root.
24+
25+
## 2. Start the App
1826

1927
```sh
2028
yarn start
2129
```
2230

23-
[custom-map-styles]: ./docs/api-reference/advanced-usages/custom-map-styles.md
31+
The app will be available at [http://localhost:8080](http://localhost:8080).
32+
33+
## Production Build
34+
35+
```sh
36+
yarn build
37+
```
38+
39+
The output will be in the `dist/` directory.
40+
41+
[custom-map-styles]: https://docs.kepler.gl/docs/api-reference/advanced-usages/custom-map-styles
42+
[yarn-install]: https://yarnpkg.com/getting-started/install

examples/custom-map-style/esbuild.config.mjs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,28 @@
22
// Copyright contributors to the kepler.gl project
33

44
import esbuild from 'esbuild';
5-
import {replace} from 'esbuild-plugin-replace';
65
import {dotenvRun} from '@dotenv-run/esbuild';
76
import copyPlugin from 'esbuild-plugin-copy';
87

98
import process from 'node:process';
109
import fs from 'node:fs';
10+
import path from 'node:path';
11+
import {fileURLToPath} from 'node:url';
1112
import {spawn} from 'node:child_process';
12-
import {join} from 'node:path';
1313

1414
const args = process.argv;
1515

16+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
17+
1618
const port = 8080;
1719

1820
const NODE_ENV = JSON.stringify(process.env.NODE_ENV || 'production');
1921

20-
// Ensure a single instance of React and friends to avoid invalid hook calls
21-
const ROOT_NODE_MODULES = join('..', '..', 'node_modules');
22-
const thirdPartyAliases = {
23-
react: join(ROOT_NODE_MODULES, 'react'),
24-
'react-dom': join(ROOT_NODE_MODULES, 'react-dom'),
25-
'react-redux': join(ROOT_NODE_MODULES, 'react-redux', 'lib'),
26-
'styled-components': join(ROOT_NODE_MODULES, 'styled-components'),
27-
'apache-arrow': join(ROOT_NODE_MODULES, 'apache-arrow')
28-
};
29-
3022
const config = {
3123
platform: 'browser',
3224
format: 'iife',
3325
logLevel: 'info',
34-
loader: {
35-
'.js': 'jsx',
36-
'.ts': 'ts',
37-
'.tsx': 'tsx',
38-
'.css': 'css',
39-
'.ttf': 'file',
40-
'.woff': 'file',
41-
'.woff2': 'file'
42-
},
26+
loader: {'.js': 'jsx', '.ts': 'ts', '.tsx': 'tsx', '.css': 'css'},
4327
entryPoints: ['src/main.tsx'],
4428
outfile: 'dist/bundle.js',
4529
bundle: true,
@@ -53,10 +37,23 @@ const config = {
5337
environment: NODE_ENV,
5438
root: '../../.env'
5539
}),
56-
replace({
57-
__PACKAGE_VERSION__: '3.1.10',
58-
include: /constants\/src\/default-settings\.ts/
59-
}),
40+
// styled-components: @hubble.gl/react nests its own copy.
41+
// react-palm: several @kepler.gl/* packages nest their own copy.
42+
// Both are singletons that break when loaded more than once.
43+
{
44+
name: 'dedupe-singletons',
45+
setup(build) {
46+
build.onResolve({filter: /^(styled-components|react-palm(\/|$)|react$|react-dom$)/}, async args => {
47+
if (args.pluginData?.deduped) return;
48+
const result = await build.resolve(args.path, {
49+
resolveDir: __dirname,
50+
kind: args.kind,
51+
pluginData: {deduped: true}
52+
});
53+
return result;
54+
});
55+
}
56+
},
6057
copyPlugin({
6158
resolveFrom: 'cwd',
6259
assets: {
@@ -84,16 +81,13 @@ function openURL(url) {
8481
const result = await esbuild
8582
.build({
8683
...config,
87-
alias: thirdPartyAliases,
8884
minify: true,
8985
sourcemap: false,
9086
metafile: true,
9187
define: {
9288
...config.define,
9389
'process.env.NODE_ENV': '"production"'
94-
},
95-
drop: ['console', 'debugger'],
96-
treeShaking: true
90+
}
9791
})
9892
.catch(e => {
9993
console.error(e);
@@ -106,7 +100,6 @@ function openURL(url) {
106100
await esbuild
107101
.context({
108102
...config,
109-
alias: thirdPartyAliases,
110103
minify: false,
111104
sourcemap: true,
112105
banner: {
@@ -123,7 +116,7 @@ function openURL(url) {
123116
console.info(remoteAddress, status, `"${method} ${path}" [${timeInMS}ms]`);
124117
}
125118
});
126-
console.info(`kepler.gl custom-map-style example running at ${`http://localhost:${port}`}`);
119+
console.info(`kepler.gl custom-map-style example running at http://localhost:${port}`);
127120
openURL(`http://localhost:${port}`);
128121
})
129122
.catch(e => {
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,27 @@
11
{
2+
"name": "kepler-custom-map-style",
3+
"version": "0.0.1",
4+
"license": "MIT",
25
"scripts": {
36
"start": "node esbuild.config.mjs --start",
47
"build": "node esbuild.config.mjs --build",
58
"start-local": "NODE_ENV=local node esbuild.config.mjs --start"
69
},
710
"dependencies": {
8-
"@kepler.gl/components": "^3.1.10",
9-
"@kepler.gl/reducers": "^3.1.10",
10-
"global": "^4.3.0",
11-
"react": "^18.2.0",
12-
"react-dom": "^18.2.0",
13-
"react-palm": "^3.3.6",
14-
"react-redux": "^8.0.5",
15-
"react-virtualized": "^9.21.0",
16-
"redux-actions": "^2.2.1",
17-
"styled-components": "6.4.3"
11+
"@kepler.gl/components": "^3.3.0-alpha.6",
12+
"@kepler.gl/reducers": "^3.3.0-alpha.6",
13+
"react": "^19.0.0",
14+
"react-dom": "^19.0.0",
15+
"react-redux": "^9.1.0",
16+
"redux": "^5.0.1"
1817
},
1918
"devDependencies": {
2019
"@dotenv-run/esbuild": "^1.5.0",
20+
"@types/node": "^20",
21+
"@types/react": "^19.0.0",
22+
"@types/react-dom": "^19.0.0",
2123
"esbuild": "^0.25.0",
2224
"esbuild-plugin-copy": "^2.1.1",
23-
"esbuild-plugin-replace": "^1.4.0"
25+
"typescript": "^5.5.0"
2426
}
2527
}
Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4-
import React from 'react';
5-
import {connect} from 'react-redux';
4+
import * as React from 'react';
5+
import {useState, useEffect} from 'react';
66
import KeplerGl from '@kepler.gl/components';
7-
import AutoSizer from 'react-virtualized/dist/commonjs/AutoSizer';
87

98
const localeMessages = {
109
en: {
@@ -14,23 +13,27 @@ const localeMessages = {
1413
}
1514
};
1615

17-
const App = () => (
18-
<div style={{position: 'absolute', width: '100%', height: '100%'}}>
19-
<AutoSizer>
20-
{({height, width}) => (
21-
<KeplerGl
22-
mapboxApiAccessToken=""
23-
id="map"
24-
width={width}
25-
height={height}
26-
localeMessages={localeMessages}
27-
/>
28-
)}
29-
</AutoSizer>
30-
</div>
31-
);
16+
function useWindowSize() {
17+
const [size, setSize] = useState({width: window.innerWidth, height: window.innerHeight});
18+
useEffect(() => {
19+
const onResize = () => setSize({width: window.innerWidth, height: window.innerHeight});
20+
window.addEventListener('resize', onResize);
21+
return () => window.removeEventListener('resize', onResize);
22+
}, []);
23+
return size;
24+
}
3225

33-
const mapStateToProps = state => state;
34-
const dispatchToProps = dispatch => ({dispatch});
26+
const App = () => {
27+
const {width, height} = useWindowSize();
28+
return (
29+
<KeplerGl
30+
mapboxApiAccessToken=""
31+
id="map"
32+
width={width}
33+
height={height}
34+
localeMessages={localeMessages}
35+
/>
36+
);
37+
};
3538

36-
export default connect(mapStateToProps, dispatchToProps)(App);
39+
export default App;
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright contributors to the kepler.gl project
33

4-
import React from 'react';
4+
import * as React from 'react';
55
import ReactDOM from 'react-dom/client';
6-
import document from 'global/document';
76
import {Provider} from 'react-redux';
87
import store from './store.ts';
98
import App from './app.tsx';
@@ -14,6 +13,6 @@ const Root = () => (
1413
</Provider>
1514
);
1615

17-
const root = ReactDOM.createRoot(document.getElementById('root'));
18-
16+
const container = document.getElementById('root');
17+
const root = ReactDOM.createRoot(container!);
1918
root.render(<Root />);

examples/custom-map-style/src/store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ const reducers = combineReducers({
5252
});
5353

5454
const middlewares = enhanceReduxMiddleware([]);
55-
const enhancers = [applyMiddleware(...middlewares)];
55+
const enhancers = applyMiddleware(...middlewares);
5656

57-
export default createStore(reducers, {}, compose(...enhancers));
57+
export default createStore(reducers, {}, compose(enhancers));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
5+
"module": "ESNext",
6+
"moduleResolution": "bundler",
7+
"jsx": "react-jsx",
8+
"strict": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"skipLibCheck": true
12+
},
13+
"include": ["src"]
14+
}

examples/get-started-vite/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@ A minimal example showing how to integrate [Kepler.gl](https://kepler.gl/) into
99

1010
## 1. Install Dependencies
1111

12+
Go to the `examples/get-started-vite` directory and run:
13+
1214
```sh
13-
yarn install
15+
touch yarn.lock && yarn
1416
```
1517

18+
> `touch yarn.lock` is required once to mark this directory as a standalone Yarn project,
19+
> independent of the monorepo root.
20+
1621
## 2. Start the App
1722

1823
```sh

0 commit comments

Comments
 (0)