简体   繁体   English

显示精确大小的图标

[英]Displaying icons with exact size

I'd like to have exact-sized icons on my map, where each icon takes up a predefined size in meters on the map.我想在我的 map 上有精确大小的图标,其中每个图标在 map 上占据以米为单位的预定义大小。 Additionally, these need to be changed at runtime, so generating an image ahead of time that covers the whole map is a no-go.此外,这些需要在运行时进行更改,因此无法提前生成覆盖整个 map 的图像。 My use case is displaying to-be-painted pavement markings, so a 3 meter square is probably the largest thing displayed.我的用例是显示要涂漆的路面标记,所以 3 平方米可能是显示的最大的东西。 Matching the rotation and pitch is easily done with setting icon-rotation-alignment to map , leaving the issue of size.通过将icon-rotation-alignment设置为map可以轻松匹配旋转和俯仰,留下大小问题。 I could scale the icon-size by interpolate -ing the zoom factor ( ['interpolate', ['exponential', 2], ['zoom'], 15, 1 / 72, 22, 1 / 0.56] ), but I would then run into problems with the difference in latitudes with the Mercator projection .我可以通过interpolate缩放icon-size['interpolate', ['exponential', 2], ['zoom'], 15, 1 / 72, 22, 1 / 0.56] ),但我然后会遇到墨卡托投影的纬度差异问题。 It would probably be possible, though, to interpolate based on both the zoom and current latitude.但是,可能可以根据缩放和当前纬度进行插值。

Alternatively, some demos that look to be doing similar tasks of aligning real-world sizes are Add a 3D model , Add a canvas source , Add a custom style layer (although I don't think I need that), and Add an image .或者,一些看起来正在执行对齐真实世界大小的类似任务的演示是Add a 3D model添加 canvas 源代码,添加一个自定义样式 My understanding of how I would use each:我对如何使用每个的理解:

  • Add a 3D model: I would use three.js (or another renderer) and set it up with the location and image of each symbol, then use it to draw.添加一个 3D model:我会使用 three.js(或其他渲染器)并将其设置为每个符号的位置和图像,然后使用它来绘制。
  • Add a canvas source: Either create a very large canvas (probably would use too much RAM) or one canvas per symbol (overhead?), then draw the symbol添加一个 canvas 源:要么创建一个非常大的 canvas(可能会使用太多 RAM),要么为每个符号创建一个 canvas(开销?),然后绘制符号
  • Add an image: Same decision, but with URLs instead of canvases添加图像:相同的决定,但使用 URL 而不是画布

Which of these would be the best option?其中哪一个是最好的选择?

You can do that easily with a raster layer in mapbox but you'll need to do on your side the calculations of the length in meters for the 4 corners of the image using a conversion that considers latitude.您可以使用 mapbox 中的栅格图层轻松完成此操作,但您需要使用考虑纬度的转换来计算图像 4 个角的长度(以米为单位)。

Other option if you want to add an image in exact meters size (considering the latitude), just check this out made with the latest version of threebox如果您想添加精确米大小的图像(考虑纬度)的其他选项,只需使用最新版本的threebox进行检查

You'll be able to load any image (and any 3D model) and define its size in meters (millimeters indeed) with only a few lines of code, but using a threejs plug-in for a pure 2D task is probably like shooting fish in a barrel.您将能够加载任何图像(以及任何 3D 模型)并以米为单位(实际上是毫米)定义其大小,只需几行代码,但使用 threejs 插件执行纯 2D 任务可能就像打鱼一样在一个桶里。

图片

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM