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 module @deck.gl/carto #4925

Merged
merged 1 commit into from
Sep 24, 2020
Merged

CARTO module @deck.gl/carto #4925

merged 1 commit into from
Sep 24, 2020

Conversation

alasarr
Copy link
Contributor

@alasarr alasarr commented Sep 8, 2020

Background

Deck.gl is today the preferred/official library for CARTO to build Location Intelligence apps. We consider that the best option for the future is to be part of Deck.gl family and we've created @deck.gl/carto for this 😄 .

Why a module inside deck.gl repo? It's a more collaborative approach. The closer to Deck.gl, the better. We want our engineers in this ecosystem rather than working on a wrapper or an external module.

We've included some examples at examples/carto but was not clear for us to find the right place. Feel free to suggest another location even if you consider it shouldn't be part of this repo.

This module provides two layers:

  • CartoSQLLayer: is a layer to visualize data hosted in your CARTO account and apply custom SQL.
  • CartoBQTilerLayer: is a layer to visualize large datasets (millions or billions rows) directly from Google BigQuery without having to move data outside BigQuery. You need first to generate a tileset of your dataset in your BigQuery account using CARTO BigQuery Tiler. More info here.

Change List

  • A new module at modules/carto
  • Examples doc at examples/carto
  • Tests at test/modules/carto
  • Doc at docs/api-reference/carto
  • It includes doc at website

@coveralls
Copy link

coveralls commented Sep 8, 2020

Coverage Status

Coverage decreased (-2.9%) to 80.678% when pulling ce74dcf on CartoDB:carto-module into e0cd727 on visgl:master.

@alasarr
Copy link
Contributor Author

alasarr commented Sep 15, 2020

Examples moved to examples/get-started

@@ -0,0 +1,8 @@
Pure js demo for CARTO layers

### Usage
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This demo requires a Mapbox token. Either add instructions for acquiring and providing a token (see README of other mapbox examples), or remove the mapbox dependency (preferred for a "minimal" example)

Copy link
Contributor Author

@alasarr alasarr Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really since we're using CARTO's basemaps and they are free

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the mapbox code in this example then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still use Mapbox GL but tiles are provided by CARTO, so I think we can use Mapbox GL without a token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you prefer to have the example without the basemap to make it simpler? I just did because it looks better with the basemap

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it's fine then

<html>
<head>
<!-- deck.gl standalone bundle -->
<script src="https://unpkg.com/deck.gl@^8.1.0/dist.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to include the carto module from CDN here.

As the number of submodules grow, we have paused adding new modules into the main bundle to prevent bloating its size with unnecessary functionalities, unless it can be justified for most common use cases. For example, the arcgis module is not part of the main bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I've kept it linked against ^8.1.0 just to allow an easy replace 😄

"prepublishOnly": "npm run build-bundle && npm run build-bundle -- --env.dev"
},
"dependencies": {
"@deck.gl/geo-layers": "^8.2.7",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a peerDependency

```bash
npm install deck.gl
# or
npm install @deck.gl/core @deck.gl/layers @deck.gl/carto
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

geo-layers

## Install package

```bash
npm install deck.gl
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this to work the new module must be added to modules/main's package.json

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're not going to include in the bundle I think it's clearer to keep it outside the main module. Let me know otherwise.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deck.gl can include all submodules as dependency. This makes installation easier and has no direct impact on bundle size unless the user references a specific API.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

To use pre-bundled scripts:

```html
<script src="https://unpkg.com/deck.gl@^8.2.0/dist.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add carto bundle

To use pre-bundled scripts:

```html
<script src="https://unpkg.com/deck.gl@^8.2.0/dist.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add carto bundle

Optional. A string pointing to a unique attribute at the result of the query. A unique attribute is needed for highlighting a feature split across two or more tiles.


##### `credentials` (Object)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the equivalent of using setDefaultCredentials?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same but for each layer. It's there to support layers from different CARTO users, so you can merge in the same map datasets of two users. It's quite common when you use a public dataset with a private one.

const BQ_TILEJSON_ENDPOINT = 'https://us-central1-cartobq.cloudfunctions.net/tilejson';

const defaultProps = {
...CartoLayer.defaultProps
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unnecessary. defaultProps is automatically merged with that of the parent class.

}

renderLayers() {
if (!this.state.tilejson) return [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return null is fine

data: this.state.tilejson.tiles
};

return new MVTLayer(props);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more efficient:

new MVTLayer(this.props, this.getSubLayerProps({
  id: 'mvt',
 data: this.state.tilejson.tiles
}));


const defaultProps = {
...mapsApiProps,
...CartoLayer.defaultProps,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@alasarr
Copy link
Contributor Author

alasarr commented Sep 22, 2020

Changes applied 😄


<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^8.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/layers@^8.2.0/dist.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing geo-layers


<!-- or -->
<script src="https://unpkg.com/@deck.gl/core@^8.0.0/dist.min.js"></script>
<script src="https://unpkg.com/@deck.gl/layers@^8.2.0/dist.min.js"></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing geo-layers

@alasarr alasarr closed this Sep 24, 2020
Co-authored-by: Víctor Velarde <victor.velarde@gmail.com>
Co-authored-by: Javier Aragón <jaragon@cartodb.com>
@alasarr
Copy link
Contributor Author

alasarr commented Sep 24, 2020

I closed by mistake sorry

@alasarr alasarr reopened this Sep 24, 2020
@Pessimistress Pessimistress merged commit f1a9167 into visgl:master Sep 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants