Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARTO: Fix scripting example #7148

Merged
merged 3 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions docs/api-reference/carto/fetch-map.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ fetchMap({cartoMapId}).then(map => new Deck(map));
import mapboxgl from 'mapbox-gl';

fetchMap({cartoMapId}).then(({initialViewState, mapStyle, layers}) => {
const deck = new Deck({canvas: 'deck-canvas', controller: true, initialViewState, layers});

// Add Mapbox GL for the basemap. It's not a requirement if you don't need a basemap.
const MAP_STYLE = `https://basemaps.cartocdn.com/gl/${mapStyle.styleType}-gl-style/style.json`;
const map = new mapboxgl.Map({container: 'map', style: MAP_STYLE, interactive: false});
deck.setProps({
onViewStateChange: ({viewState}) => {
const {longitude, latitude, ...rest} = viewState;
map.jumpTo({center: [longitude, latitude], ...rest});
}
const deckgl = new deck.DeckGL({
container: 'container',
controller: true,
mapStyle: MAP_STYLE,
initialViewState,
layers
});
});
```
Expand All @@ -47,9 +45,9 @@ fetchMap({cartoMapId}).then(({initialViewState, mapStyle, layers}) => {
const map = await fetchMap({cartoMapId, credentials, autoRefresh, onNewData});
```

##### `cartoMapId` (String)
##### `cartoMapId` (String)

Required. Identifier of map created in CARTO Builder.
Required. Identifier of map created in CARTO Builder.

##### `credentials` (Object, optional)

Expand Down Expand Up @@ -98,7 +96,7 @@ An identifier describing the [basemap](docs/api-reference/carto/basemap.md#suppo
##### `layers` (Array)

A collection of deck.gl [layers](docs/api-reference/layers.md).

##### `stopAutoRefresh` (Function)

A function to invoke to stop auto-refreshing. Only present if `autoRefresh` option was provided to `fetchMap`.
Expand Down
33 changes: 6 additions & 27 deletions examples/get-started/scripting/carto/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,29 @@
font-family: UberMove, Helvetica, Arial, sans-serif;
}
#container {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#container > * {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
width: 100vw;
height: 100vh;
}
</style>
</head>

<body>
<div id="container">
<div id="map"></div>
<canvas id="deck-canvas"></canvas>
</div>
<div id="container"></div>
</body>

<script type="text/javascript">
const cartoMapId = 'ff6ac53f-741a-49fb-b615-d040bc5a96b8';

// Get map info from CARTO and update deck
deck.carto.fetchMap({cartoMapId}).then(({initialViewState, mapStyle, layers}) => {
const MAP_STYLE = `https://basemaps.cartocdn.com/gl/${mapStyle.styleType}-gl-style/style.json`;
const deckgl = new deck.DeckGL({
canvas: 'deck-canvas',
container: 'container',
controller: true,
mapStyle: MAP_STYLE,
initialViewState,
layers
});

// Add Mapbox GL for the basemap. It's not a requirement if you don't need a basemap.
const MAP_STYLE = `https://basemaps.cartocdn.com/gl/${mapStyle.styleType}-gl-style/style.json`;
const map = new mapboxgl.Map({container: 'map', style: MAP_STYLE, interactive: false});
deckgl.setProps({
onViewStateChange: ({viewState}) => {
const {longitude, latitude, ...rest} = viewState;
map.jumpTo({center: [longitude, latitude], ...rest});
}
});
});
</script>
</html>