首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cartojs4 -多值甜甜圈图标记

Cartojs4 -多值甜甜圈图标记
EN

Stack Overflow用户
提问于 2018-06-27 19:19:50
回答 1查看 312关注 0票数 0

我想创建一个标记,就像我们在Carto SalesQuest产品中看到的那样。

按照CARTO提供的这篇文章,我用我的CARTOjs 4绘制了一个集群地图

https://carto.com/blog/inside/tile-aggregation/

我可以使用CARTOCSS来设计我的图层,但我想知道实现这样一个示例的最佳实践/方法是什么:

多值甜甜圈图,CARTO Salesquest中的聚类标记

我自己版本的CARTO JS 4集群

我的代码看起来如下(隐藏的API密钥)

代码语言:javascript
复制
<!DOCTYPE html>
<html>

<head>
    <meta name="viewport" content="initial-scale=1.0" />
    <meta charset="utf-8" />
    <!-- Include Carto.js -->
    <script src="https://cartodb-libs.global.ssl.fastly.net/carto.js/v4.0.2/carto.min.js"></script>
    <!-- Include Leaflet -->
    <script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"></script>
    <link href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css" rel="stylesheet" />
    <style>
        body {
            margin: 0;
            padding: 0;
        }
        #map {
            position: absolute;
            height: 100%;
            width: 100%;
        }
    </style>
</head>

<body>
<div id="map"></div>

<script>
    const map = L.map('map').setView([30, 0], 3);
    L.tileLayer('http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png', {
        maxZoom: 18
    }).addTo(map);
    // define client
    const client = new carto.Client({
        apiKey: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        username: 'anagraph-clement'
    });
    // define source of data using a SQL query
    const source = new carto.source.SQL(`
            select *, 1 as count from pochesfils_carto
        `);
    // Aggregation option
    const aggregation = new carto.layer.Aggregation({
        threshold: 5,
        resolution: 32,
        placement: carto.layer.Aggregation.placement.SAMPLE,
        columns: {
            total_agg: {
                aggregateFunction: carto.layer.Aggregation.operation.SUM,
                aggregatedColumn: "count"
            }
        }
    });
    // define CartoCSS code to style data on map
    const style = new carto.style.CartoCSS(`
            #layer {
                marker-fill:  ramp([total_agg], (#3288bd, #99d594, #e6f598, #ffffbf, #fee08b, #fc8d59, #d53e4f), quantiles);
                marker-width: ramp([total_agg],  8 ,40 , quantiles);
                marker-line-color: ramp([total_agg], (#5F4690, #1D6996, #38A6A5, #0F8554, #73AF48, #EDAD08, #E17C05, #CC503E, #94346E, #6F4070, #666666), (5,10,20,30,50,66,75,100,150), "=", category);
                marker-line-width: 5;
                marker-line-opacity: 0.75;
            }
            #layer::labels {
                text-name: [total_agg];
                text-face-name: 'DejaVu Sans Book';
                text-size: 8;
                text-fill: #FFFFFF;
                text-label-position-tolerance: 0;
                text-halo-radius: 1;
                text-halo-fill: black;
                text-allow-overlap: true;
                text-placement: point;
                text-placement-type: dummy;
            }
        `);
    // create CARTO layer from source and style variables
    // and defining the interactivity of columns
    // when featureOver and featureClick events are executed
    const cartolayer = new carto.layer.Layer(source, style, { aggregation });
    // add CARTO layer to the client
    client.addLayer(cartolayer);
    // get tile from client and add them to the map object
    client.getLeafletLayer().addTo(map);
</script>
</body>

</html>

感谢您让我知道您是否对这种类型的标记创建有任何提示。(svg?d3.js?chart.js?CARTOCSS + TurboCARTO?等等.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-02 14:08:04

没有太多的空间来改进你的风格,甜甜圈图需要的是非聚合数据,而你在聚合可视化中没有这些数据。最重要的是,CartoCSS不能够轻松地绘制“甜甜圈部分”,因为这很可能需要大量的三角计算来设定角度来开始/停止图表的不同部分。SalesQuest使用传单插件和传统的标记渲染直接在浏览器中加载GeoJSON数据,而不是使用CARTO。因此,要实现这种可视化,您需要使用SQL呈现适当的数据,然后使用纯传单编码将其作为标记来呈现。

一个快速的谷歌搜索给了我至少启发你自己。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51070002

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档