Google 地图 3 重绘折线闪烁

发布于 2024-12-10 09:56:20 字数 572 浏览 5 评论 0原文

我正在绘制一条具有相当多的纬度/经度点(~ 1000)的折线。我有两个滑块(开始和结束),允许用户调整时间范围,然后更新折线以显示这两个时间之间的数据。

我的更新算法是这样的:

var mvcPath = new google.maps.MVCArray();

for (var i = 0; i < gpsData.length; i++) {

    if (gpsData[i]['timestamp'] <= endDate && 
        gpsData[i]['timestamp'] >= startDate) {
        mvcPath.push(gpsData[i]['location']);
    }
}

this.path.setPath(mvcPath);

现在奇怪的是,当我拖动结束滑块时,线条会按预期重新绘制,但是当我拖动开始滑块时,它会正确地重新绘制线条,除非在高缩放级别下,线条的部分似乎稍微移动(近距离放大时不会这样做)。我认为这可能与谷歌应用于折线的抗锯齿算法有关,但当我移动末端滑块时它不会这样做。

有谁知道是什么原因导致这种闪烁?

I am drawing a Polyline with a fairly large number of lat/lng points (~ 1000). I have two sliders (start and end) that allow the user to adjust the time bounds which then updates the Polyline to show the data between those two times.

My update algorithm goes something like this:

var mvcPath = new google.maps.MVCArray();

for (var i = 0; i < gpsData.length; i++) {

    if (gpsData[i]['timestamp'] <= endDate && 
        gpsData[i]['timestamp'] >= startDate) {
        mvcPath.push(gpsData[i]['location']);
    }
}

this.path.setPath(mvcPath);

Now the weird thing is, when I drag the end slider the line redraws as expected, however when I drag the start slider, it redraws the line correctly except at high zoom levels parts of the line seem to move slightly (it doesn't do this when zoomed in close). I thought it might be something to do with the anti alias algorithm Google applies to the Polyline but it doesn't do it when I move the end slider.

Anyone know what is causing this flickering?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-12-17 09:56:20

我已经破解了一个目前看来有效的解决方案。我试图保持点数一致,因为 API 似乎不喜欢我在前面添加点数。

假设我有一组 1000 个点,我只想显示 200 - 900 个点。如果我绘制点 200 的位置,200 次,然后将其余数据绘制到点 900,它就会停止闪烁。要显示 10 - 330,我会绘制点 10、10 次,然后将其余数据绘制到点 330。

我想这与 Google 内部存储地图线条的方式有关,如果您添加到线条的前面它可能必须重新索引整个数组并从头开始重新绘制线条。

我暂时不会接受答案,以防有人提出更好的答案。

I've hacked a solution which seems to work for now. I tried to keeping the number of points consistent as the API didn't seem to like me adding points to the front.

Lets say I have a set of 1000 points and I only want to show from 200 - 900. If I draw the location of point 200, 200 times then draw the rest of the data to point 900, it stops the flickering. To display 10 - 330 I would draw point 10, 10 times then draw the rest of the data to point 330.

I guess this has something to the way Google internally stores the lines of the map, if you add to the front of the line it may have to re-index a whole array and redraw the line from scratch.

I won't accept the answer for now incase someone comes up with a better answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文