簡體   English   中英

如何使用 mapbox-gl 為特征點設置單獨的布局屬性?

[英]How to set individual layout properties for feature points with mapbox-gl?

我有一組特征點,並且不想單獨更新每個特征點上的一些布局屬性。 我該怎么做?

這是我到目前為止。

const features = getVisibleFeatures();
// This updates all. Not what I wan't. Each feature should have different offset.
map.setLayoutProperty("ports", "text-offset", [5, 5]);

每個功能都應該有它自己的text-offset ,基於單獨的值。 我如何實現這一目標?

更新

@steve-bennett 在下面的評論中提供了一些很好的建議,但不幸的是,它們不適用於布局屬性和文本偏移值。

解決方案可以解決這個問題很重要。

經過大量的搜索、試驗和錯誤,我發現我可以這樣做:

map.setLayoutProperty("ports", "text-offset", {
    property: "id",
    type: "categorical",
    stops: [
      ["0", [2, 1]],
      ["1", [2, 0]],
      ["2", [0, 2]],
    ],
    default: [0, 0],
});

"0""1""2"properties.id字段匹配。 所以我可以做這樣的事情:

  map.setLayoutProperty("layout-id", "text-offset", {
    property: "id",
    type: "categorical",
    stops: nodes.map((node) => {
      const x = node.vx;
      const y = node.vy;
      return [node.id, [x, y]];
    }),
    default: [0, 0],
  });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM