【问题标题】:Editable geoJSON layer on map with leaflet.draw使用 Leaflet.draw 在地图上可编辑的 geoJSON 图层
【发布时间】:2015-07-25 09:39:47
【问题描述】:

我尝试在 Mapbox 中加载 geoJson 数据并使用插件 Leaflet.Draw 对其进行编辑 当我点击编辑按钮时,我有一个错误: 无法设置未定义的属性“原始”

图层在地图上,但我无法编辑它。

代码如下:

    var map = L.map('map').setView( [40, 40], 2);    

  L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
      attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
      maxZoom: 18,
      id: 'mapbox.streets',
      accessToken: '*******'
  }).addTo(map);

  // Initialise the FeatureGroup to store editable layers
  var drawnItems = new L.FeatureGroup();
  map.addLayer(drawnItems);

  L.geoJson(<%=RGeo::GeoJSON.encode(@field.shape).to_json.html_safe%>, 
      {
      onEachFeature: function (feature, layer) {
          drawnItems.addLayer(layer);
      }
  }).addTo(map);

  // Initialise the draw control and pass it the FeatureGroup of editable layers
  var drawControl = new L.Control.Draw({
      draw : {
        position : 'topleft',
        polygon : true,
        polyline : false,
        rectangle : false,
        circle : false,
        marker: false
      },
      edit: {
          featureGroup: drawnItems
      },
  }).addTo(map);

【问题讨论】:

    标签: ruby-on-rails leaflet mapbox geojson


    【解决方案1】:

    所以,我找到了答案。 我正在尝试编辑多面体,但 leaflet.draw 不支持它们。

    我切换到leaflet.editable

    【讨论】:

      猜你喜欢
      • 2016-10-20
      • 2020-05-12
      • 1970-01-01
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多