gpt4 book ai didi

javascript - 通过连接提高自定义 CartoDB 层可视化的性能

转载 作者:行者123 更新时间:2023-11-28 06:57:57 24 4
gpt4 key购买 nike

我对 CartoDB 相当陌生(顺便说一句,这很棒),并使用 CartoDB.js 构建自定义可视化,但我的解决方案在初始加载时非常慢(加载大约需要 1 分钟),它基于文档 here我相信这是在我的 SQL 中使用 CTE 的结果(我在这张 map 的 GUI 上确认了这一点:http://cdb.io/1hL3pzF,没有 CTE 会快得多);但是我还没有看到其他方法的引用 - 有人对此有好的解决方案吗?

我假设为查询分配了一个默认名称(例如,在 cartodb.com GUI 中,关联的 CartoCSS 使用您开始使用的任何表...),但尚未看到引用。

这是一个jsfiddle我的工作方法,也在这里:

HTML

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

CSS

#map { position: absolute; top: 5px; left: 3px; height: 400px; width: 600px; }

JS

    var map = new L.map('map');

/* this works but is quite slow...
what is result of query called from cartodb?
*/
var cartocss = '#summary_tbl{ polygon-fill: #F1EEF6; polygon-opacity: 0.8; line-color: #FFF; line-width: 0.5; line-opacity: 1;}';
cartocss = cartocss + '#summary_tbl [ methane <= 158.47731712611244] { polygon-fill: #91003F; }';
cartocss = cartocss + '#summary_tbl [ methane <= 135] { polygon-fill: #CE1256; }';
cartocss = cartocss + '#summary_tbl [ methane <= 120.95519348268839] { polygon-fill: #E7298A; }';
cartocss = cartocss + '#summary_tbl [ methane <= 112.3529411764706] { polygon-fill: #DF65B0; }';
cartocss = cartocss + '#summary_tbl [ methane <= 108.42857142857143] { polygon-fill: #C994C7; }';
cartocss = cartocss + '#summary_tbl [ methane <= 104.09859154929578] { polygon-fill: #D4B9DA; }';
cartocss = cartocss + '#summary_tbl [ methane <= 98.36206896551724] { polygon-fill: #F1EEF6; }';

var sql_summ = "WITH summary_tbl AS (SELECT avg(n.methane) as methane, count(n.cartodb_id) record_count, h.the_geom_webmercator ";
sql_summ = sql_summ + "FROM nurve_sample_boston_0828 n JOIN hex_base_v500m h ON ST_Within(n.the_geom, h.the_geom) ";
sql_summ = sql_summ + "GROUP BY h.the_geom_webmercator) SELECT methane, the_geom_webmercator FROM summary_tbl";

var cbd_layer = {
user_name: 'crshunter', // Required
type: 'cartodb', // Required
sublayers: [{
sql: sql_summ,
cartocss: cartocss, // Required
interactivity: "methane"
}]
};

$(document).ready(function () {
map.on('load', function(e){
// grab OSM basemap for context
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
cartodb.createLayer(map, cbd_layer).addTo(map);
});
});

var startPosition = new L.LatLng(42.3601, -71.0589); // Boston, MA
map.setView(startPosition, 12);

最佳答案

如果对任何人都有帮助,更好的方法是使用 cartodb-nodejs 将此功能移动到后端。图书馆 - 我真傻,从一开始就不这么做。

关于javascript - 通过连接提高自定义 CartoDB 层可视化的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32416327/

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