单张侧边栏未加载时打开

时间:2015-04-08 15:49:02

标签: plugins leaflet cartodb

我正在使用leaflet-sidebarv2插件为cartodb / leaflet地图创建侧边栏。我遇到的问题是我无法获得工作选项 - 关闭按钮,autoPan等)和b。)不能使用setContent来动态设置数据。

侧边栏按预期运行。问题是修改它似乎没有效果。我还在setTimeoutsetContent行上收到错误“Uncaught TypeError:undefined is not function”。

      cartodb.createLayer(map, {
      user_name: {{user_name}},
      type: 'cartodb',
      sublayers: [{
         sql: 'select * from {{table_name}}',
         cartocss: '#layer',
         interactivity: 'cartodb_id, name',
         auto_bound: true
      }]
    })
    .addTo(map)
    .done(function(layer) {
      var barData;

      barData = layer.createSubLayer({
        sql: 'select * from {{table_name}}',
        cartocss: '#layer {marker-fill: #bababa; marker-opacity: 0.3; marker-width: 4px; }',
        interactivity: 'name, location'
      });

      //on click
      barData.on('featureClick', function(e, pos, pixel, data) {
        //log active data
      console.log("Name: " + data.name + " @ " + data.location);
        $('#map').css('cursor', 'pointer');
      });

      barData.setInteraction(true);

      //hover pop-up
      var infobox = new cdb.geo.ui.InfoBox({
        width: 100,
        layer: layer,
        template: '<p class="cartodb-infobox">{{name}}</p></br><p>{{location}}</p>',
        position: 'top|right' // top, bottom, left and right are available
      });

      $("body").append(infobox.render().el);

      // leaflet-sidebar> closeButton not engaging
      var sidebar = L.control.sidebar('sidebar', {closeButton: true});
      map.addControl(sidebar);

      //content not showing up anywhere
      sidebar.setContent('test <b>test</b> test');

     // sidebar still collapsed at reload
     setTimeout(function () {
         sidebar.show();
    }, 500);

      });
  }      
  window.onload = main; 

有关我可能做错的任何建议吗?我已经装好了所有正确的部件。                     

1 个答案:

答案 0 :(得分:0)

您似乎使用了错误的API。 setContent()方法和options哈希是leaflet-sidebar库API的一部分,但不是sidebar-v2的一部分。