gpt4 book ai didi

mapping - Cartojs4 - 多值圆环图标记

转载 作者:行者123 更新时间:2023-12-04 16:12:41 25 4
gpt4 key购买 nike

我想创建一个我们可以在 Carto SalesQuest 产品中看到的标记。

我按照 CARTO 提供的这篇文章从我的 CARTOjs 4 制作了一个集群 map

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

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

Multivalues donut chart, cluster markers as seen in CARTO Salesquest

My own version of clusters with CARTO JS 4

我的代码看起来像这样(隐藏的 API KEY)

<!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?等等...)

最佳答案

改进样式的余地不大,圆环图需要分解的数据,而聚合可视化中没有这些数据。最重要的是,CartoCSS 无法轻松渲染“ donut 部分”,因为这很可能涉及大量三角计算来设置角度以开始/停止图表的不同部分。 SalesQuest 使用传单插件和传统标记渲染直接在浏览器中加载 GeoJSON 数据,而不是使用 CARTO Maps API。因此,要实现这种可视化,您需要使用 SQL API 呈现正确的数据,然后使用纯 Leaflet 编码将其呈现为标记。

快速谷歌搜索至少给了我 thisthis来激励自己。

关于mapping - Cartojs4 - 多值圆环图标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51070002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com