最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Mapbox Custom Marker as a "Pillar" on the Map - Stack Overflow

programmeradmin1浏览0评论

My goal is to have my markers standing like pillars at 90 degrees to the Mapbox map.

Like this:

I got this from .gl

Currently I have this code to add a Marker but it doesn't work.

      const customMarker = document.createElement("div");
      const backGroundColor = theme == "dark" ? "bg-white/90" : "bg-black/90";
      customMarker.className = "w-2 h-20 rounded-full" + " " + backGroundColor;

      if (!device.location?.longitude || !device.location?.latitude) return;

      new mapboxgl.Marker({
        element: customMarker,
        pitchAlignment: "map",
        rotationAlignment: "map"
      })
        .setLngLat([device.location?.longitude, device.location?.latitude] as [
          number,
          number
        ])
        .setRotation(45)
        .addTo(mapRef.current!);

This renders the markers like this:

My goal is to have my markers standing like pillars at 90 degrees to the Mapbox map.

Like this:

I got this from https://github/vasturiano/globe.gl

Currently I have this code to add a Marker but it doesn't work.

      const customMarker = document.createElement("div");
      const backGroundColor = theme == "dark" ? "bg-white/90" : "bg-black/90";
      customMarker.className = "w-2 h-20 rounded-full" + " " + backGroundColor;

      if (!device.location?.longitude || !device.location?.latitude) return;

      new mapboxgl.Marker({
        element: customMarker,
        pitchAlignment: "map",
        rotationAlignment: "map"
      })
        .setLngLat([device.location?.longitude, device.location?.latitude] as [
          number,
          number
        ])
        .setRotation(45)
        .addTo(mapRef.current!);

This renders the markers like this:

Share Improve this question asked Mar 14 at 16:01 SchickliSchickli 331 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Setting the rotationAlignment property to "horizon" should give you the expected result. Orient markers toward the horizon.

发布评论

评论列表(0)

  1. 暂无评论