【问题标题】:React Mapbox Layer: Show different image for markerReact Mapbox Layer:为标记显示不同的图像
【发布时间】:2019-06-18 12:18:14
【问题描述】:

我正在使用图层属性显示标记。

import markerIcon from "../map-marker.png";
const image = new Image();
image.src = markerIcon;
const images = ['customImage', image];

<Mapbox
    style="mapbox://styles/mapbox/streets-v8"
    containerStyle={{
        height: "100vh"
    }}
    >
    <Layer
        type="symbol"
        id="marker"
        layout={{
        "icon-image": "customImage",
        "icon-allow-overlap": false
        }}
        images={images}
    >
        <Feature
            key="1"
            coordinates={[-0.2416815, 51.5285582]}
        />
        <Feature
            key="2"
            coordinates={[-0.3416815, 51.6285582]}
        />
    </Layer>
</Mapbox>

以上代码运行正常。但是,我的要求是我想为 2 个标记显示 2 个不同的图像。现在我已经展示了 2 个样本坐标(特征)。是否可以为不同的功能显示不同的图像?我没有得到任何帮助。任何帮助将不胜感激。提前致谢。

【问题讨论】:

    标签: reactjs mapbox react-map-gl


    【解决方案1】:

    假设您使用的是纯 MapboxGL,请按照 these directions 在标记上放置自定义图像。它为您的问题提供了一个非常清晰的示例。仅供参考,无论您使用的是纯 Mapbox 还是包装器,您都想使用标记而不是特征。

    如果您使用 Mapbox 的包装器,请告诉我,我们可以解决它。

    【讨论】:

      猜你喜欢
      • 2021-03-31
      • 2022-08-18
      • 1970-01-01
      • 2018-10-27
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 2021-11-02
      相关资源
      最近更新 更多