Google Maps Platform 㨠deck.gl ã使ç¨ã、CARTO ãã©ãããã©ã¼ã ã§é«åº¦ãªãã¼ã¿ã®å¯è¦åãå®ç¾ããæ¹æ³
æ¨å¹´ 10 æã«éå¬ããã Google Cloud Next ã§、Google ãã¼ã ã¯å°ç空éæ
å ±ä¼æ¥ã§ãã CARTO 㨠vis.gl Technical Steering Committee(TSC)ã¨ã®é£æºã«ãã、deck.gl å¯è¦åã©ã¤ãã©ãªã®ææ°ãªãªã¼ã¹ãçºè¡¨ãã¾ãã。deck.gl ã®ãªãªã¼ã¹ã«ã¯、Maps JavaScript API ã® WebGL ã«ããæ°æ©è½ã¨ã®ç·å¯ãªã¤ã³ãã°ã¬ã¼ã·ã§ã³ãå«ã¾ãã¦ãã、ãã¼ã¹ãããä¸ã§ç´æ¥ 2D ・ 3D ã®ããããå¯è¦åã§ããããã«ãªãã¾ãã。
CARTO ã®ãã¼ã ã¯、ãããµã¹å·ã®ãã©ãã¯ãé»åã§ããå¯è½æ§ã示ãå種ãã¼ã¿ã½ã¼ã¹ãå¯è¦åãããµã³ãã«ã¢ããªãä½æãã¾ãã。ãã®ã¢ããªã¯、Google Maps Platform 㨠deck.gl ã§ä½æã§ãã、ãã¾ãã¾ãªã¿ã¤ãã®é«åº¦ãªãã¼ã¿ã®å¯è¦åãç´¹ä»ãã¦ãã¾ã。ããã§、çæ§ã«、å¯è¦åã®ããã®ãã¼ã¿ã½ã¼ã¹ã¨、CARTO ãã©ãããã©ã¼ã ãã©ã®ããã«å¯è¦åãå®ç¾ãã¦ããã®ãã«ã¤ãã¦ãç´¹ä»ãã¾ã。
Google Cloud ã¯、å°ç空éã¯ã¨ãªããµãã¼ããããµã¼ãã¼ã¬ã¹ ãã¼ã¿ ã¦ã§ã¢ãã¦ã¹ ã½ãªã¥ã¼ã·ã§ã³ã§ãã BigQuery ãæä¾ãã¾ã。空éãã¼ã¿ãæ±ãå ´å、ãã¼ã¿ã»ãããæ¢ç´¢ãå¯è¦åããå°å³ãä½æãããã¨ã¯、éè¦ãã¤ä¸è¬çã«å¿ è¦ã¨ããã¦ãããã¨ã§ã。CARTO Spatial Extension for BigQuery ã¯、ãã¼ã¿ ã¦ã§ã¢ãã¦ã¹ã¸ã®æ¥ç¶ãä½æã、BigQuery ãã¼ãã«ããã®ãã¼ã¿ã§å°å³ãè¨è¨ã、deck.gl ã使ç¨ãã¦ã¦ã§ãã¢ããªã§å¯è¦åããç°¡åãªæ¹æ³ãæä¾ãã¾ã。
CARTO Builder ãã Map ID ãåå¾ããä¾ |
CARTO Builder ã§ç´æ¥、å°å³ã«å種ã«ã¹ã¿ã ã¹ã¿ã¤ã«ãé©ç¨å¯è½ |
ã·ã³ãã«ãªå°å³ã®ä½æ
CARTO ãã©ãããã©ã¼ã ã使ç¨ãã¦ã·ã³ãã«ãªå°å³ãä½æããã«ã¯、ä½é¨çã¢ã«ã¦ã³ãã«ç»é²ãã¾ã。ãã°ã¤ã³ããã¨、ãµã¼ãã¹ ã¢ã«ã¦ã³ãã使ç¨ã㦠BigQuery ã¤ã³ã¹ã¿ã³ã¹ã¨æ¥ç¶ããããã«è¨å®ã§ãã¾ã。è¨å®ããã Data Explorer ã«ç§»åãã¦、å©ç¨å¯è½ãªãã¼ã¿ã»ããã確èªã、å°å³ã§ãã¼ã¿ã½ã¼ã¹ã¨ãã¦ä½¿ç¨ããããã¼ãã«ãè¦ã¤ãã¾ã。詳細ã«ã¤ãã¦ã¯、CARTO ããã¥ã¡ã³ããã確èªãã ãã。
CARTO Builder ã® Data Explorer ã§、ãã¾ãã¾ãªå°ç空éãã¼ã¿ã»ããããã¬ãã¥ã¼ã§ãã¾ã |
ãããµã¹å·ã®éé»ç·ãå¯è¦åããããã«、ã¾ããããµã¹å·ã®è¡æ¿çæ å ±ãå¼ãåºãæããå§ããã¨、æ¦æ³ãã¤ããã¾ã。Data Explorer ã§ãã¼ãã«ããã¬ãã¥ã¼ã、å³ä¸ã® [Create map] ãã¿ã³ãã¯ãªãã¯ã、å¯è¦åã®è¨å®ä½æ¥ãéå§ãã¾ã。
å°å³ä½æãã¼ã«ã§ãã CARTO Builder ã使ç¨ãã¦、èæ¯å°å³ã¨ãã¦å©ç¨å¯è½ãª Google ã®ãã¯ã¿ã¼ãã¼ã¹ãããã®ã¹ã¿ã¤ã«ã®ä¸ãã 1 ã¤ãé¸ã³、ã¬ã¤ã¤ã¹ã¿ã¤ã«ãã«ã¹ã¿ãã¤ãºãã¾ã。
CARTO Builder ã§è¡¨ç¤ºãããå®è¡æ¸ã¿ã®å°ç空éã¯ã¨ãªã®çµæ |
SELECT *
FROM cartobq.nexus_demo.transmission_lines
WHERE ST_INTERSECTS(
geometry,
(SELECT geom FROM cartobq.nexus_demo.texas_boundary_simplified)
);
CARTO Builder ã§å®è¡ãããå°ç空éã¯ã¨ãªã®ä¾ |
[Run] ãã¿ã³ãã¯ãªãã¯ããã¨、Google Cloud ã® BigQuery å´ã§ã¯ã¨ãªãå®è¡ããã¾ã。çµæ㯠Builder ãã¼ã«ã«è¿éããå¯è¦åããã¾ã。æ°ããã¬ã¤ã¤ã§ã¹ã¿ã¤ã«ã®ã«ã¹ã¿ãã¤ãºãããã°、å°å³è¡¨ç¾ã®æºåã¯å®äºã§ã。
çµæã¯、BigQuery ããè¿ãã、èªåçã«å¯è¦åããã¾ã |
Google Maps Platform ã¢ããªã±ã¼ã·ã§ã³ã«å°å³ã追å ããåã«å°å³ãå ¬éããå¿ è¦ãããã¾ã。[Share] ãã¿ã³ãã¯ãªãã¯ãã¦、[Developers] ã¿ããé¸ã³、å°å³ ID ãã³ãã¼ãã¾ã。
Google Maps Platform ã¦ã§ã SDK ã¨ã¢ãã¤ã« SDK ã§ä½¿ç¨ããããã®å°å³ ID ã CARTO Building ã®å ±æã¡ãã¥ã¼ããçæãã¾ã。 |
ãã¨ã¯、以ä¸ã® 4 è¡ã®ã³ã¼ãã追å ããã ãã§、Google Maps Platform ã¢ããªã±ã¼ã·ã§ã³ã§ CARTO ã§è¨å®ãã主é¡å³ãå¯è¦åã§ãã¾ã。
const cartoMapId = 'b502bf53-877d-4e89-b5ad-71982cac431d';
deck.carto.fetchMap({cartoMapId}).then(({layers}) => {
const overlay = new deck.GoogleMapsOverlay({layers});
overlay.setMap(map);
});
fetchMap é¢æ°ãå¼ã³åºãã«ã¯、CARTO Builder ããã³ãã¼ããå°å³ ID ãå©ç¨ã§ãã¾ã。ãã®é¢æ°ã¯ãã©ãããã©ã¼ã ã«æ¥ç¶ã、æå®ãããã¹ã¦ã®ã¹ã¿ã¤ãªã³ã° ããããã£ãæ㤠deck.gl ã¬ã¤ã¤ã®ã³ã¬ã¯ã·ã§ã³ãå«ã、å¯è¦åã«å¿ è¦ãªãã¹ã¦ã®æ å ±ãåå¾ãã¾ã。ãã®ã¬ã¤ã¤ã®ã³ã¬ã¯ã·ã§ã³ã使ã£ã¦、deck.gl GoogleMapsOverlay ã®ã¤ã³ã¹ã¿ã³ã¹ãä½æã、å°å³ã«è¿½å ãã¾ã。
å®å ¨ãªãµã³ãã«ã¯ãã¡ãã®ãã¡ãããã覧ãã ãã。
JSFiddle ã§å©ç¨å¯è½ãªå®å ¨ãªãµã³ãã« |
é常ã«å¤§è¦æ¨¡ãªãã¼ã¿ã»ããã®å¯è¦å
BigQuery ã®å¤§ããªç¹å¾´ã® 1 ã¤ã¯、巨大ãªãã¼ã¿ã»ããã«å¯¾ãã¦ãå¦çãã¹ã±ã¼ã«ã¢ã¦ãã§ãããã¨ã§ã。CARTO ãã©ãããã©ã¼ã ã§ã¯、ã¿ã¤ã«ã»ããã¨ãã、ãããããçæããããã¯ãã«ã¿ã¤ã«ãå«ã空éçã«æé©åããããã¼ã¿æ§é ã使ã£ã¦、é常ã«å¤§ããªãã¼ã¿ã»ãããé«éã§å¯è¦åã§ãã¾ã。ã¿ã¤ã«ã»ãã㯠BigQuery å 㧠Analytics Toolbox é¢æ°ã使ç¨ãã¦æ°ååç¹ãå¦çã§ãã並åå¦çã§çæããã¾ã。
ä¾ãã°、åè¿°ã®ç±³å½ã®éé»ç·ã®å ¨ãã¼ã¿ã»ãã、100 MB 以ä¸ã®ã¸ãªã¡ããªã§ã¿ã¤ã«ã»ããæ©è½ã使ç¨ãã¦å¯è¦åã§ãã¾ã。
ãã®ãããªå¤§è¦æ¨¡ãªãã¼ã¿ã»ããã®åé¡ç¹ã¯、ä¸åº¦ã«ã¡ã¢ãªã«åã¾ããªããã¨ã§ã。ãã®ãã、ã¿ã¤ã«ã«åå²ãã¦é ã«ã¬ã³ããªã³ã°ããå¿ è¦ããã訳ã§ãã、CARTO ã¯ãã®ç¹ããããããèæ ®ã、BigQuery ã§ç´æ¥ã¿ã¤ã«ã»ãããä½æããã、ãªã³ã¶ãã©ã¤ã§åçã«çæãããã¨ãã§ãã¾ã。
BigQuery ã§çæãã、CARTO Builder ã§è¡¨ç¤ºãããã¿ã¤ã«ã»ãã |
ãã®æ¹æ³ã§å°å³ã«ãã¼ã¿ãèªã¿è¾¼ãã¨、å¿ è¦ãªç¯å²ã ããã¬ã³ããªã³ã°ãããã¨ãå¯è½ã§ã。ä¾ãã°、170 åç¹ã®è¹è¶ãã¼ã¿ãå¯è¦åãã以ä¸ã®ãµã³ãã«ãè¦ã¦ã¿ã¾ããã。
ã«ã¹ã¿ã ã¿ã¤ã«ã»ããã§ã¬ã³ããªã³ã°ãã 170 åç¹ã®ãã¼ã¿ã»ãã |
ã©ã¤ããã¼ã¿ã«ã¤ãã¦
BigQuery ã¯ç¶ç¶çã«æ´æ°ãããã¹ããªã¼ãã³ã° ãã¼ã¿ããµãã¼ããã¦ãã¾ã。ãã®ã·ããªãªã§ã¯、ãã¼ã¿ã®å¤åã«å¿ãã¦、ä¸å®ééã§å¯è¦åãæ´æ°ã§ããããã«è¨å®ãã¦ãã¾ã。deck.gl ã使ç¨ããã°å¯è¦åæ å ±ãæ´æ°ãããã¨ã¯ç°¡åã§ã。å°å³ã®åå¾æã« autoRefresh ãã©ã¡ã¼ã¿ã true ã«è¨å®ã、æ°ãããã¼ã¿ããã¦ã³ãã¼ããããã¨ãã«å®è¡ãããé¢æ°ãæå®ããã ãã§ã。
const {layers} = await deck.carto.fetchMap({
cartoMapId,
autoRefresh: true,
onNewData: (parsedMap) => { … }
});
BigQuery ã®ã³ã³ã½ã¼ã«ã§ INSERT é¢æ°ã使ã£ã¦ãã¼ãã«ã«ãã¤ã³ãã追å ã、å°å³ä¸ã§ãªã¢ã«ã¿ã¤ã ã«ãã¼ã¿ãæ´æ°ãããã®ãè¦ããã¨ãã§ãã¾ã。
BigQuery ã®ãã¼ã¿ã»ããããªã³ã¶ãã©ã¤ã§æ´æ°ã、CARTO ã§å¯è¦åãããã¨ãå¯è½ã§ã |
ããã«è©³ããè¦ã¦ã¿ã¾ããã
ä¸ã«ç¤ºãããããªã·ã³ãã«ãªå¯è¦åã®æ¹æ³ã«å ã、deck.gl ã¯、åºç¯å²ã«å¯è¦åããæè»æ§ãåãã¦ãã¾ã。CARTO ãã©ãããã©ã¼ã ã¯ãã¼ã¿ ã¦ã§ã¢ãã¦ã¹ãããã¼ã¿ã«ã¢ã¯ã»ã¹ã、é«åº¦ãªå°å³ä½ææ©è½ã§ãã¼ã¿ãå¯è¦åããæ©è½ãæä¾ãã¾ã。ããã«、deck.gl ã¬ã¤ã¤ã«ã¿ãã°ã§å©ç¨ã§ããé«åº¦ãªå¯è¦åã«ãã£ã¦、æ©è½ãæ¡å¼µã§ãã¾ã。
deck.gl ã®ã³ã¼ããããã«ã³ã³ããã¼ã«ããããã®è¿½å ãªãã·ã§ã³ã 2 ã¤ããã¾ã。1 ã¤ç®ã¯、fetchMap ã使ç¨ããã«、ç´æ¥ CartoLayer ã使ç¨ããæ¹æ³ã§ã。ãã®å ´å、CARTO ãã©ãããã©ã¼ã å´ã§æ¥ç¶å¯¾è±¡ã®å°å³ãã¼ã¿ã®è¨å®ã¨、ãã¼ã¿ã½ã¼ã¹ã®ã¿ã¤ã・åå、ã¯ã¨ãªãã¹ã¿ã¤ã« ããããã£ãªã©ãæå®ããå¿ è¦ãããã¾ããæ¯è¼ç容æã«å¯è¦åã¬ã¤ã¤ãçæå¯è½ã§ã。
const overlay = new deck.GoogleMapsOverlay({
layers: [
new deck.carto.CartoLayer({
connection: 'bqconn',
type: deck.carto.MAP_TYPES.TABLE,
data: `cartobq.public_account.retail_stores`,
getFillColor: [238, 77, 90],
pointRadiusMinPixels: 6,
}),
],
});
2 ã¤ç®ã¯、fetchLayerData é¢æ°ã使ç¨ããæ¹æ³ã§ã。ãã®é¢æ°ã¯、BigQuery ã¨ã¢ããªã±ã¼ã·ã§ã³éã®ãã¼ã¿è»¢éã«ä½¿ç¨ããããã©ã¼ããããããã«ã³ã³ããã¼ã«ãããã¨ãå¯è½ã§、ArcLayer、H3HexagonLayer、TripsLayer ãªã©ã®ç¹å®ã®ãã¼ã¿å½¢å¼ãå¿ è¦ã¨ããé«åº¦ãªå¯è¦åã«ããã¦ä½¿ç¨ã§ãã¾ã。
deck.carto.fetchLayerData({
type: deck.carto.MAP_TYPES.TABLE,
source: `cartobq.geo_for_good_meetup.texas_pop_h3`,
connection: 'bqconn',
format: deck.carto.FORMATS.JSON,
credentials: {
accessToken: 'eyJhbGciOiJIUzI1NiJ9.eyJhIjoiYWNfbHFlM3p3Z3UiLCJqdGkiOiI1YjI0OWE2ZCJ9.Y7zB30NJFzq5fPv8W5nkoH5lPXFWQP0uywDtqUg8y8c'
}
}).then(({data}) => {
const layers= [
new deck.H3HexagonLayer({
id: 'h3-hexagon-layer',
data,
extruded: true,
getHexagon: d => d.h3,
getFillColor: [182, 0, 119, 150],
getElevation: d => d.pop,
elevationScale: 2.5,
parameters: {
blendFunc: [luma.GL.SRC_ALPHA, luma.GL.DST_ALPHA],
blendEquation: luma.GL.FUNC_ADD
}
})
];
const overlay = new deck.GoogleMapsOverlay({layers});
overlay.setMap(map);
});
両æ¹ã®ãªãã·ã§ã³ã使ç¨ããå®å ¨ãªã³ã¼ãã¯、ãã¡ãã®ãµã³ãã«ãã覧ãã ãã。
Google Maps Platform 㨠CARTO ã«ãã deck.gl Hexagon Layer ã®å¯è¦åã®ä½¿ç¨ä¾ |
詳ããæ å ±ã¯
deck.gl ã®ããã¥ã¡ã³ã ã¦ã§ããµã¤ã㨠CARTO ã®ããã¥ã¡ã³ã ã»ã³ã¿ã¼ã§、ãã¢ãããã¥ã¡ã³ãã«ã¢ã¯ã»ã¹ã§ãã¾ã。ãä¸æãªç¹ãããå ´åã¯、CARTO Users Slack ã¯ã¼ã¯ã¹ãã¼ã¹ã«ã¦、CARTO ãã¼ã ã«ãåãåãããã ãã。
Google Maps Platform ã«é¢ãã詳ããæ å ±ã¯ãã¡ããã覧ãã ãã。ã質åããã£ã¼ãããã¯ã¯ãã¼ã¸å³ä¸ã®「ãåãåãã」ããæ¿ã£ã¦ããã¾ã。
Posted by 丸山 æºåº· (Tomoyasu Maruyama) - Developer Relations Engineer