基于标记属性设计 Turf 缓冲区

Styling Turf buffer based on marker attribute

如标​​题所示,我正在尝试根据标记层的属性设置标记层周围的 Turf 缓冲区的样式。

我知道如何根据 SAME 图层的属性设置图层样式,但我无法将样式连接到缓冲区。

我尝试过两种方法,这两种方法都可以设置我的缓冲区的样式,但仍然无法连接到我的标记的属性信息(原因显而易见,您将看到)。请忽略任何奇怪的格式,因为 post 重新排列了一些东西,我试图修复它们。

尝试 1:

lyrHouses = {
  type: "FeatureCollection",
  features: [],
};

// parse local CSV file

Papa.parse("src/data1/Houses.csv", {
  header: true,
  download: true,
  dynamicTyping: true,
  skipEmptyLines: true,
  complete: function (results) {
    results.data.forEach((house) => {
      feature = {
        type: "Feature",
        geometry: {
          type: "Point",
          coordinates: [house.Longitude, house.Latitude],
        },
        properties: {
          Location: house.Location,
          Type: house.Type,
        },
      };

      mrkHouses = L.geoJSON(feature).addTo(mymap);

      lyrHouses.features.push(feature);
      houseBuffer = turf.buffer(mrkHouses.toGeoJSON(), 3, {
        units: "kilometers",
      });
      lyrTest = L.geoJSON(houseBuffer, {
        style: function (feature) {
          switch (feature.properties.Type) {
            case "Duplex":
              return { color: "blue" };

            case "Quadplex":
              return { color: "yellow" };
          }
          return { color: "red" };
        },
      }).addTo(mymap);
    });
  },
});

尝试 2:

function setBuffColor(d) {
  return d = 'Duplex' ? "green" :
    d = 'Quadplex' ? "red" :
    d = 'Semidetached' ? "blue" :
    '#FFED80';
}

function BuffStyle(feature) {
  return {
    color: setBuffColor(feature.properties.Type),
  };
}

为什么不喜欢这样?

lyrTest = L.geoJSON(houseBuffer, { style: house.Type === 'Duplex' ? { color: "blue" } : (house.Type === 'Quadplex' ? { color: "yellow" } : { color: "red" }) });