-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(examples): Remove framework-specific examples
- Loading branch information
1 parent
efebb5c
commit 86e9c9f
Showing
20 changed files
with
187 additions
and
1,045 deletions.
There are no files selected for viewing
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,106 @@ | ||
import maplibregl from 'maplibre-gl'; | ||
import {Deck} from '@deck.gl/core'; | ||
import {H3TileLayer} from '@deck.gl/carto'; | ||
import {Filter, h3TableSource, H3TableSourceResponse} from '@carto/api-client'; | ||
import '../components/index.js'; | ||
import type {Widget, FilterEvent} from '../components/index.js'; | ||
|
||
/************************************************************************** | ||
* REACTIVE STATE | ||
*/ | ||
|
||
let data: Promise<H3TableSourceResponse>; | ||
let viewState = {latitude: 37.375, longitude: -5.996, zoom: 6}; | ||
let filters: Record<string, Filter> = {}; | ||
|
||
/************************************************************************** | ||
* DECK.GL | ||
*/ | ||
|
||
const deck = new Deck({ | ||
canvas: 'deck-canvas', | ||
initialViewState: viewState, | ||
controller: true, | ||
layers: [], | ||
}); | ||
|
||
const map = new maplibregl.Map({ | ||
container: 'map', | ||
style: | ||
'https://basemaps.cartocdn.com/gl/positron-nolabels-gl-style/style.json', | ||
interactive: false, | ||
}); | ||
|
||
deck.setProps({ | ||
onViewStateChange: (params) => { | ||
viewState = params.viewState; | ||
const {longitude, latitude, ...rest} = viewState; | ||
map.jumpTo({center: [longitude, latitude], ...rest}); | ||
updateWidgets(); | ||
}, | ||
}); | ||
|
||
const widgets: Widget[] = [ | ||
bindWidget('#formula'), | ||
bindWidget('#category'), | ||
bindWidget('#pie'), | ||
bindWidget('#table'), | ||
bindWidget('#scatter'), | ||
bindWidget('#histogram'), | ||
]; | ||
|
||
updateSources(); | ||
|
||
/************************************************************************** | ||
* UPDATES | ||
*/ | ||
|
||
function updateSources() { | ||
data = h3TableSource({ | ||
accessToken: import.meta.env.VITE_CARTO_ACCESS_TOKEN, | ||
connectionName: 'carto_dw', | ||
tableName: | ||
'carto-demo-data.demo_tables.derived_spatialfeatures_esp_h3res8_v1_yearly_v2', | ||
filters, | ||
aggregationExp: 'sum(population) as population', | ||
}); | ||
|
||
updateLayers(); | ||
updateWidgets(); | ||
} | ||
|
||
function updateLayers() { | ||
const layer = new H3TileLayer({ | ||
id: 'retail_stores', | ||
data, | ||
pointRadiusMinPixels: 4, | ||
getFillColor: [200, 0, 80], | ||
}); | ||
|
||
deck.setProps({layers: [layer]}); | ||
data.then(({attribution}) => { | ||
document.querySelector('#footer')!.innerHTML = attribution; | ||
}); | ||
} | ||
|
||
function updateWidgets() { | ||
for (const widget of widgets) { | ||
widget.data = data; | ||
widget.viewState = viewState; | ||
} | ||
} | ||
|
||
/************************************************************************** | ||
* INITIALIZATION | ||
*/ | ||
|
||
function bindWidget(selector: string): Widget { | ||
const widget = document.querySelector<Widget>(selector)!; | ||
|
||
widget.addEventListener('filter', (event) => { | ||
filters = (event as FilterEvent).detail.filters; | ||
updateSources(); | ||
}); | ||
|
||
return widget; | ||
} |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-US"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Examples / Spatial Index</title> | ||
<link rel="stylesheet" href="../style.css" /> | ||
</head> | ||
<body> | ||
<main id="app"> | ||
<header> | ||
<h1>Spatial Index</h1> | ||
<a href="../">← Back</a> | ||
</header> | ||
<section id="view"> | ||
<div id="map"></div> | ||
<canvas id="deck-canvas"></canvas> | ||
</section> | ||
<section id="rail"> | ||
<formula-widget | ||
id="formula" | ||
header="Total population" | ||
operation="count" | ||
></formula-widget> | ||
<category-widget | ||
id="category" | ||
header="Urbanity" | ||
operation="count" | ||
column="urbanity" | ||
></category-widget> | ||
<pie-widget | ||
id="pie" | ||
header="Urbanity" | ||
operation="count" | ||
column="urbanity" | ||
></pie-widget> | ||
<table-widget | ||
id="table" | ||
header="Pop. Distribution" | ||
columns='["population", "male", "female"]' | ||
sortBy="population" | ||
></table-widget> | ||
<scatter-widget | ||
id="scatter" | ||
header="Education vs. Healthcare" | ||
xAxisColumn="education" | ||
yAxisColumn="healthcare" | ||
></scatter-widget> | ||
<histogram-widget | ||
id="histogram" | ||
header="Population distribution" | ||
column="population" | ||
ticks="[100, 500, 1000, 5000]" | ||
></histogram-widget> | ||
</section> | ||
<footer id="footer"></footer> | ||
</main> | ||
<script type="module" src="./app.ts"></script> | ||
</body> | ||
</html> |
Oops, something went wrong.