Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.
[Bug] fix 3d building layer missing mapbox token, fix image export (#360)
Shan Hec244f6eb179d
diff --git a/src/components/map-container.js b/src/components/map-container.jsindex 8096b1c48..8f8084777 100644--- a/src/components/map-container.js+++ b/src/components/map-container.js@@ -328,7 +328,8 @@ export default function MapContainerFactory(MapPopover, MapControl) {mapStyle,layerData,layerOrder,- visStateActions+ visStateActions,+ mapboxApiAccessToken} = this.props;let deckGlLayers = [];@@ -341,9 +342,13 @@ export default function MapContainerFactory(MapPopover, MapControl) {.reverse().reduce(this._renderLayer, []);}- const threeDBuildingLayerId = '_keplergl_3d-building';+if (mapStyle.visibleLayerGroups['3d building']) {- deckGlLayers.push(new ThreeDBuildingLayer({id: threeDBuildingLayerId, threeDBuildingColor: mapStyle.threeDBuildingColor}));+ deckGlLayers.push(new ThreeDBuildingLayer({+ id: '_keplergl_3d-building',+ mapboxApiAccessToken,+ threeDBuildingColor: mapStyle.threeDBuildingColor+ }));}return (diff --git a/src/components/plot-container.js b/src/components/plot-container.jsindex 8d83c5395..b1bdb850f 100644--- a/src/components/plot-container.js+++ b/src/components/plot-container.js@@ -80,7 +80,8 @@ export default function PlotContainerFactory(MapContainer) {mapStyle.bottomMapStyle,resolution),- topMapStyle: scaleMapStyleByResolution(mapStyle.topMapStyle, resolution)+ topMapStyle: scaleMapStyleByResolution(mapStyle.topMapStyle, resolution),+ visibleLayerGroups: mapStyle.visibleLayerGroups}));diff --git a/src/deckgl-layers/3d-building-layer/3d-building-layer.js b/src/deckgl-layers/3d-building-layer/3d-building-layer.jsindex c98efe110..d065fad82 100644--- a/src/deckgl-layers/3d-building-layer/3d-building-layer.js+++ b/src/deckgl-layers/3d-building-layer/3d-building-layer.js@@ -25,7 +25,7 @@ import {_SolidPolygonLayer as SolidPolygonLayer} from '@deck.gl/layers';export default class ThreeDBuildingLayer extends CompositeLayer {// this layer add its subLayers to the redux store, and push sample data-+renderSubLayers(props) {return new SolidPolygonLayer({...props,@@ -51,9 +51,10 @@ export default class ThreeDBuildingLayer extends CompositeLayer {}renderLayers() {+return [new DeckGLTileLayer({- getTileData,+ getTileData: (args) => getTileData(this.props.mapboxApiAccessToken, args),minZoom: 13,renderSubLayers: this.renderSubLayers.bind(this)})diff --git a/src/deckgl-layers/3d-building-layer/3d-building-utils.js b/src/deckgl-layers/3d-building-layer/3d-building-utils.jsindex 095c9cfb8..16afb852b 100644--- a/src/deckgl-layers/3d-building-layer/3d-building-utils.js+++ b/src/deckgl-layers/3d-building-layer/3d-building-utils.js@@ -22,20 +22,16 @@ import Protobuf from 'pbf';import {VectorTile, VectorTileFeature} from '@mapbox/vector-tile';import {worldToLngLat} from 'viewport-mercator-project';-/* global fetch process */+/* global fetch */const TILE_SIZE = 512;-const MAPBOX_TOKEN = process.env.MapboxAccessToken;+const MAP_SOURCE = 'https://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7';++export function getTileData(token, {x, y, z}) {+ const mapSource = `${MAP_SOURCE}/${z}/${x}/${y}.vector.pbf?access_token=${token}`;-export function getTileData({x, y, z}) {- const mapSource = `https://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/${z}/${x}/${y}.vector.pbf?access_token=${MAPBOX_TOKEN}`;return fetch(mapSource)- .then(response => {- return response.arrayBuffer();- })- .then(buffer => {- const data = decodeTile(x, y, z, buffer);- return data;- });+ .then(response => response.arrayBuffer())+ .then(buffer => decodeTile(x, y, z, buffer));}export function decodeTile(x, y, z, arrayBuffer) {@@ -85,7 +81,7 @@ export function vectorTileFeatureToProp(vectorTileFeature, project) {const extent = vectorTileFeature.extent;let i;let j;-+coords = classifyRings(coords);for (i = 0; i < coords.length; i++) {for (j = 0; j < coords[i].length; j++) {diff --git a/src/utils/dom-to-image.js b/src/utils/dom-to-image.jsindex 711954be7..ae37f87ca 100644--- a/src/utils/dom-to-image.js+++ b/src/utils/dom-to-image.js@@ -24,30 +24,18 @@*/import window, {- Blob,- Image,XMLHttpRequest,FileReader,setTimeout,- HTMLInputElement,- HTMLTextAreaElement,- HTMLCanvasElement,- SVGElement,- Element,- HTMLImageElement,- SVGRectElement,- document,- XMLSerializer,- console,- CSSRule,fetch} from 'global/window';+import document from 'global/document';+import console from 'global/console';const util = newUtil();const inliner = newInliner();const fontFaces = newFontFaces();const images = newImages();-// Default impl optionsconst defaultOptions = {// Default is to fail on error, no placeholder@@ -210,7 +198,7 @@ function cloneNode(node, filter, root) {.then(clone => processClone(node, clone));function makeNodeCopy(nd) {- if (nd instanceof HTMLCanvasElement) {+ if (nd instanceof window.HTMLCanvasElement) {return util.makeImage(nd.toDataURL());}return nd.cloneNode(false);@@ -239,7 +227,7 @@ function cloneNode(node, filter, root) {}function processClone(original, clone) {- if (!(clone instanceof Element)) {+ if (!(clone instanceof window.Element)) {return clone};@@ -321,17 +309,17 @@ function cloneNode(node, filter, root) {}function copyUserInput() {- if (original instanceof HTMLTextAreaElement)+ if (original instanceof window.HTMLTextAreaElement)clone.innerHTML = original.value;- if (original instanceof HTMLInputElement)+ if (original instanceof window.HTMLInputElement)clone.setAttribute('value', original.value);}function fixSvg() {- if (!(clone instanceof SVGElement)) return;+ if (!(clone instanceof window.SVGElement)) return;clone.setAttribute('xmlns', 'http://www.w3.org/2000/svg');- if (!(clone instanceof SVGRectElement)) return;+ if (!(clone instanceof window.SVGRectElement)) return;['width', 'height'].forEach(attribute => {const value = clone.getAttribute(attribute);if (!value) return;@@ -359,7 +347,7 @@ function makeSvgDataUri(node, width, height) {return Promise.resolve(node).then(nd => {nd.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');- return new XMLSerializer().serializeToString(nd);+ return new window.XMLSerializer().serializeToString(nd);}).then(util.escapeXhtml).then(xhtml =>@@ -445,7 +433,7 @@ function newUtil() {binaryArray[i] = binaryString.charCodeAt(i);resolve(- new Blob([binaryArray], {type: 'image/png'})+ new window.Blob([binaryArray], {type: 'image/png'}));});}@@ -483,7 +471,7 @@ function newUtil() {function makeImage(uri) {return new Promise((resolve, reject) => {- const image = new Image();+ const image = new window.Image();image.onload = () => {resolve(image);};@@ -690,7 +678,7 @@ function newFontFaces() {function selectWebFontRules(cssRules) {return cssRules- .filter(rule => rule.type === CSSRule.FONT_FACE_RULE)+ .filter(rule => rule.type === window.CSSRule.FONT_FACE_RULE).filter(rule => inliner.shouldProcess(rule.style.getPropertyValue('src')));}@@ -770,21 +758,30 @@ function newFontFaces() {function getCssRules(styleSheets) {const cssRules = [];styleSheets.forEach((sheet) => {- if (sheet.cssRules && typeof sheet.cssRules === 'object') {+ // try...catch because browser may not able to enumerate rules for cross-domain sheets+ let rules;+ try {+ rules = sheet.rules || sheet.cssRules;+ } catch (e) {+ console.error(`'Can't read the css rules of: ${sheet.href}`, e);+ return;+ }++ if (rules && typeof rules === 'object') {try {util- .asArray(sheet.cssRules || [])+ .asArray(rules || []).forEach(cssRules.push.bind(cssRules));} catch (e) {- console.log(- `Error while reading CSS rules from ${sheet.href}`,- e.toString()- );+ console.error(`Error while reading CSS rules from ${sheet.href}`, e);+ return;}} else {- console.log('getCssRules can not fint cssRules')+ console.error('getCssRules can not find cssRules');+ return;}});+return cssRules;}