简体   繁体   English

Performance GL Triangles Mapbox GL JS

[英]Performant GL Triangles Mapbox GL JS

I am working on trying to create a basic, grid-based, but performant weather-arrow visualization system. 我正在尝试创建一个基本的,基于网格的高性能天气箭头可视化系统。

EDIT 2: Up-to-date version here: ( Mapbox Tracker ) of the system using the workflow which is described below 编辑2:此处为最新版本:( Mapbox Tracker )使用下面描述的工作流的系统

Usage Instructions: - Click on Wind icon (on the left) - Wait for triangles to occupy screen - Pan time-slider (at the bottom) 使用说明:-单击“风”图标(在左侧)-等待三角形占据屏幕-平移时间滑块(在底部)

As you will observe (especially on larger resolutions or when panning time slider quickly) there is quite a performance hit when drawing the triangles. 正如您将看到的(尤其是在较大的分辨率下或快速平移时间滑块时),绘制三角形时会大大降低性能。

I would greatly appreciate any advice on where to start with either using something in the current API which would help, or any ideas on how to tap into the current graphics pipeline with some type of custom buffer where I would only need to rotate, scale, change color of triangles already populated in screen space. 对于在哪里开始使用当前API会有所帮助的任何建议,或者关于如何使用某种类型的自定义缓冲区进入当前图形管道的想法,我将不胜感激,而我只需要旋转,缩放,更改屏幕空间中已经填充的三角形的颜色。

I feel as though my specific use-case would greatly benefit from something like this, I really just don't know how to approach it. 我觉得我的特定用例可能会从这样的事情中受益匪浅,但我真的不知道该如何处理。

I have a naive implementation running using this workflow: 我使用此工作流程运行了一个幼稚的实现:

  • Create a geojson FeatureCollection source 创建geojson FeatureCollection源
  • Create a fill layer 创建一个填充层
  • Using Data Driven property: fill-color 使用数据驱动属性:fill-color

Data function: 数据功能:

  1. Get map bounds 获取地图范围
  2. Project sw & ne into screen points (map.project(LatLng)) 将sw&ne投影到屏幕点(map.project(LatLng))
  3. Divide height and width into portions 将高度和宽度分成几部分
  4. Loop through width and height portions 遍历宽度和高度部分
  5. Lookup data 查找数据
  6. Access data rotation property 访问数据轮换属性
  7. Create vertices based on center point + size 根据中心点+大小创建顶点
  8. Rotate vertices 旋转顶点
  9. Create Point objects for vertices 为顶点创建点对象
  10. Unproject Point Object and wrap map.unproject(Point).wrap() 取消投影Point Object并包装map.unproject(Point).wrap()
  11. Create Feature Object, assign Data driven Color 创建要素对象,分配数据驱动的颜色
  12. Assign unprojected LatLng as Coordinates to Polygon geometry 将未投影的LatLng分配为“多边形”几何的坐标
  13. Add to Feature Array for Collection 添加到要素阵列以进行收集
  14. Call setData on layer 在图层上调用setData

So while this works, I'm looking for advice for a more performance friendly approach. 因此,尽管这可行,但我正在寻求有关更性能友好的方法的建议。

What I'm thinking here is whether I can somehow create a custom layer, one where I only need to draw to screen co-ordinates to represent the data relative to its LatLng point. 我在这里想的是,是否可以以某种方式创建一个自定义图层,在该图层中我只需要绘制屏幕坐标即可表示相对于其LatLng点的数据。 So that I can draw colored, scaled, rotated triangles in screen space, and then have them update to relevant data from the new relative LatLng position. 这样我就可以在屏幕空间中绘制彩色,缩放,旋转的三角形,然后让它们从新的相对LatLng位置更新为相关数据。

Eg Update some type of Mesh on screen instead of having to: unproject, then update feature collection source using map.getSource('arrows').setData(d), requestAnimationFrame(function) etc. 例如,更新屏幕上的某种类型的网格,而不必:取消投影,然后使用map.getSource('arrows')。setData(d),requestAnimationFrame(function)等更新要素收集源。

I've done similar in three.js in other projects but I would much rather use something that is more mapbox native. 在其他项目中,我在Three.js中也做过类似的事情,但我宁愿使用更贴图的原生Mapbox。 Does this sound feasible? 这听起来可行吗? Am I going to see a decent performance boost if so? 如果可以,我是否会看到不错的性能提升? I've not dealt with raw gl calls before etc so I might need a pointer or two in the right direction if its going to need to get as low level as that. 我没有在etc之前处理过原始的gl调用,因此如果它需要达到这样的低水平,则可能需要在正确方向上指向一个或两个指针。

EDIT: 编辑:

Previous Implementation using gmaps / three.js : volvooceanrace (wait for button on left to go from grey to black) click on top button which shows a 'wind' label when hovered over, slide red time bar underneath to change data. 使用gmaps / three.js的先前实现: volvooceanrace (等待左侧按钮从灰色变为黑色)单击上方的按钮,该按钮悬停时显示“ wind”标签,在下方滑动红色时间栏以更改数据。

Added screenshot of current working implementation Mapbox GL Arrows 添加了当前有效的实现Mapbox GL Arrows的屏幕截图

不确定2016年有什么可用,但是如今,一种合理的方法可能是使用symbol层,并使用icon-rotate数据驱动的属性根据其数据点的属性来旋转每个图标。

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

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