gpt4 book ai didi

leaflet - 将 CartoDb 层添加到 Leaflet 层控件

转载 作者:行者123 更新时间:2023-12-02 02:00:46 26 4
gpt4 key购买 nike

我正在尝试切换 Leaflet map 上 CartoDb 图层的显示。我已经能够使用此代码加载图层:

       var layerUrl = 'http://ronh-aagis.cartodb.com/api/v1/viz/rotaryclubs_geo2/viz.json';

var clubPts = cartodb.createLayer(map, layerUrl, {
// The ST_AsGeoJSON(ST_Simplify(the_geom,.01)) as geometry will store a simplified GeoJSON representation of each polygon as an attribute we can pick up on hover

query: 'select *, ST_AsGeoJSON(the_geom) as geometry from {{table_name}}',

interactivity: 'cartodb_id, geometry'
})

.on('done', function(layer) {
map.addLayer(layer);

layer.on('featureOver', function(e, pos, latlng, data) {
$('.leaflet-container').css('cursor','pointer');

if (data.cartodb_id != point.cartodb_id) {
drawHoverPoint(data);
}
cartodb.log.log(pos, data);
});

layer.on('featureOut', function(e, pos, latlng, data) {
$('.leaflet-container').css('cursor','default')
removePoint();
});

layer.on('error', function(err) {
cartodb.log.log('error: ' + err);
});

}).on('error', function() {
cartodb.log.log("some error occurred");
});

然而,当我尝试将此图层添加到图层控件时:

       var clubs = new L.LayerGroup();
clubs.addLayer(clubPts);

我收到“Uncaught TypeError: Object # has no method 'onAdd'”错误。

有什么想法吗?谢谢!

最佳答案

降低复杂性和快速上手的一个好方法是使用已经内置的 Leaflet 插件,比如 Vector Layers,它已经内置了 CartoDB 支持。看看这里的演示。 http://jasonsanford.github.io/leaflet-vector-layers/demos/cartodb/

关于leaflet - 将 CartoDb 层添加到 Leaflet 层控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17344454/

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