【问题标题】:Is there a way to overlay a png and coordinates on a map using react-map-gl有没有办法使用 react-map-gl 在地图上覆盖 png 和坐标
【发布时间】:2020-11-13 02:05:56
【问题描述】:

我正在尝试在 react-map-gl 地图上显示 png 图像,类似于 here 的描述方式,但图像未按预期显示,并且没有错误可使用。

这里是代码

const Map = (props: Props) => {
  const [viewport, setViewPort] = useState<InteractiveMapProps>({
    width: '100%',
    height: 300,
    latitude: 4.6500,
    longitude: 97.5900,
    zoom: 6
  })

  const onViewportChange = (viewport: InteractiveMapProps) => {
    setViewPort(viewport)
  }
   return (
    <MapGL
        {...viewport}
        mapboxApiAccessToken={process.env.REACT_APP_MAPBOX_TOKEN}
        onViewportChange={onViewportChange}
        mapStyle={mapStyle}
      >
        <Source
          id="map-source"
          type="image"
          url="https://image-"
          coordinates={[
            [95.23065877832998, 5.657816030165357],
            [98.90221227671044, 5.657816030165357],
            [98.90221227671044, 3.673126719208502],
            [95.23065877832998, 3.673126719208502],
          ]}
        />
      </MapGL>
     )

任何对此的见解将不胜感激

【问题讨论】:

    标签: reactjs typescript react-map-gl


    【解决方案1】:

    你需要一个图层。

    类似的东西

    <Source
      id="map-source"
      type="image"
      url="https://image-"
      coordinates={[
        [95.23065877832998, 5.657816030165357],
        [98.90221227671044, 5.657816030165357],
        [98.90221227671044, 3.673126719208502],
        [95.23065877832998, 3.673126719208502]
      ]}
    />
    <Layer
      id="overlay"
      source="map-source"
      type="raster"
      paint={{ "raster-opacity": 0.85 }}
    />
    

    基于https://docs.mapbox.com/mapbox-gl-js/example/image-on-a-map/

    【讨论】:

    • 嗨,Anatoly,感谢您的建议。它看起来很有希望,但我仍然无法看到图像。还有什么我可能遗漏的吗?
    • 哦,有趣。如果我从该链接插入示例图像和坐标,它就可以工作。看来我的形象和坐标可能有问题。
    • 你能分享你的图片吗?
    • 在玩了更多之后,这对我来说神奇地起作用了!我认为这是因为我在几张图像之间切换时可能会出现坐标错误以及图像中的绿色非常微弱的事实。我将把你的标记为答案。非常感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 2011-02-24
    • 1970-01-01
    相关资源
    最近更新 更多