简体   繁体   English

Google Maps 3 Redraw Polyline Flickering

[英]Google Maps 3 Redraw Polyline Flickering

I am drawing a Polyline with a fairly large number of lat/lng points (~ 1000). 我正在绘制具有相当多的lat / lng点(~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. 我认为这可能与Google应用于Polyline的反别名算法有关,但是当我移动结束滑块时它不会这样做。

Anyone know what is causing this flickering? 有谁知道导致这种闪烁的原因是什么?

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. 我试图保持点数一致,因为API似乎不喜欢我在前面添加点数。

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. 假设我有一组1000点,我只想显示200 - 900.如果我绘制点200的位置200次然后将其余数据绘制到点900,它会停止闪烁。 To display 10 - 330 I would draw point 10, 10 times then draw the rest of the data to point 330. 为了显示10-330,我将绘制点10,10次然后将剩余的数据绘制到点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. 我现在不接受答案,因为有人想出更好的答案。

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

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