3

Leaflet マップで 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'」エラーが発生します。

何かご意見は?ありがとう!

4

1 に答える 1

2

ここで複雑さを軽減し、迅速に使いこなすための優れた方法は、すでに CartoDB サポートが組み込まれている、Vector Layers などのビルド済みの Leaflet プラグインを使用することです。こちらのデモをご覧ください。http://jasonsanford.github.io/leaflet-vector-layers/demos/cartodb/

于 2015-05-16T17:48:21.463 に答える