如何获取L.geojson的函数数据

时间:2019-06-24 04:30:53

标签: javascript json leaflet geojson

为什么不能在l.geojson上调用数据函数,我怎么称呼它?

我尝试过在l.geojson数据中调用一个乡村变量来创建多边形,但是找不到该数据,因为它具有闭合的花括号

$(document).ready(function() {
  var map = L.map("map", {
    zoomControl: true,
    maxZoom: 28,
    minZoom: 1
  }).fitBounds([ [-5.89182819599, 102.924994823],
                 [-3.71646322182, 107.177564198] ]);
  var hash = new L.Hash(map);
  map.attributionControl.addAttribution(
    '<a href="https://github.com/tomchadwin/qgis2web" target="_blank">qgis2web</a>'
  );
  var bounds_group = new L.featureGroup([]);
  var basemap0 = L.tileLayer(
    "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    {
      attribution:
        '&copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
      maxZoom: 28
    }
  );
  basemap0.addTo(map);

  function style(d) {
    return {
      fillColor: d,
      weight: 2,
      opacity: 1,
      color: "white",
      dashArray: "3",
      fillOpacity: 0.7
    };
  }
  var desa = "{!! $des !!}";
  $.each(JSON.parse(desa), function desa(des_baru, i) {
    var id = i.gid;
    var nama = i.desa;
    var index = i.index;
    var geom = i.geo;
  });

  var des = new L.geoJson(geom, {
    attribution: '<a href=""></a>',
    style: style("black"),
    onEachFeature: des
  });
  bounds_group.addLayer(des);
  map.addLayer(des);

  function des(feature, layer) {
    layer.on({
      mouseout: function(e) {
        for (i in e.target._eventParents) {
          e.target._eventParents[i].resetStyle(e.target);
        }
      }
    });
    var popupContent =
      '<table> <id="table_wil" <tbody><tr><th scope="row">No:</th><td>' +
      [id] +
      '</td></tr><tr><th scope="row">KABUPATEN:</th><td>' +
      [nama] +
      '</td></tr><tr><th scope="row">Detail:</th><td><button  class="btnclick" data_wil="' +
      [nama] +
      '">Detail</button></td></tr></tbody></table>';
    layer.bindPopup(popupContent, { maxHeight: 400 });
  }

  var baseMaps = {};
  L.control.layers(baseMaps, { " DesaIndonesia": des }).addTo(map);
});

如何在该函数之外获取l.geojson数据的desa数据函数?

0 个答案:

没有答案