简体   繁体   English

缩放时Google地图叠加层闪烁

[英]Google maps overlay is flickering while zooming

Does somebody had the same problem with google maps api? 有人对Google Maps API有同样的问题吗? I am using the GroundOverlay instead of UsgsOverlay because the UsgsOverlay is not pixel perfect with the original google maps. 我使用GroundOverlay而不是UsgsOverlay,因为UsgsOverlay与原始的Google地图不是像素完美的。 But the GroundOverlay is flickering(rendering) while zooming. 但是,GroundOverlay在缩放时闪烁(渲染)。

Here is a Fiddle with GroundOverlay: https://jsfiddle.net/sylvanR/a8z0yyeq/17/ 这是带有GroundOverlay的小提琴: https : //jsfiddle.net/sylvanR/a8z0yyeq/17/

As you can see when you zoom in or out it is rendering each time. 如您所见,放大或缩小时每次都在渲染。

Is there a way to fix this? 有没有办法解决这个问题? Or is there a way to line out the UsgsOverlay pixel perfect, because this is not flickering? 还是有一种方法可以使UsgsOverlay像素完美,因为它不会闪烁?

Maybe there is a way to use the exact same point as GroundOverlay with 4 points instead of these two: 也许有一种方法可以使用与GroundOverlay完全相同的点,而不是使用这两个点:

var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());

the UsgsOverlay uses NE and SW but it is not lining out perfectly. UsgsOverlay使用NE和SW,但排列不完美。 Can somebody help me out doing this? 有人可以帮我吗?

Here is a fiddle with UsgsOverlay: https://jsfiddle.net/sylvanR/a8z0yyeq/18/ 这是UsgsOverlay的提琴: https ://jsfiddle.net/sylvanR/a8z0yyeq/18/

Can somebody help me out fix the flickering or placing the UsgsOverlay? 有人可以帮我解决闪烁问题或放置UsgsOverlay吗?

I found a handy tool: https://gist.github.com/pacofvf/7324239 我找到了一个方便的工具: https : //gist.github.com/pacofvf/7324239

I did not fixed the flickering while zooming, because i used the Usgs overlay and the link above is very handy to place your map pixel perfect. 我没有解决缩放时的闪烁问题,因为我使用了Usgs叠加层,并且上面的链接非常易于放置完美的地图像素。

According to this issue , maybe the cause of flickering in GroundOverlay is that the addGroundOverlay(GroundOverlayOptions) methods returns instantly and doesn't wait for the Bitmap to be loaded into memory. 根据此问题 ,也许GroundOverlay出现闪烁的原因是addGroundOverlay(GroundOverlayOptions)方法立即返回并且不等待将位图加载到内存中。

The solution here is by using the setImage() method that will replace the existing image with another image of the same directions. 解决方案是使用setImage()方法,该方法将现有图像替换为具有相同方向的另一图像。

You can change the ground overlay image after it's been added to the map with the GroundOverlay.setImage(BitmapDescriptor) method. 您可以使用GroundOverlay.setImage(BitmapDescriptor)方法将地面叠加层图像添加到地图后进行更改。

// Add an overlay, retaining a handle to the GroundOverlay object.
GroundOverlay imageOverlay = map.addGroundOverlay(newarkMap);

// Update the GroundOverlay with a new image of the same dimensions.
imageOverlay = map.setImage(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1975));

For the placing of Custom overlay , the overlay is first instantiated and ready to display, you need to attach it to the map via the browser's DOM. 为了放置自定义叠加层 ,叠加层首先实例化并准备显示,您需要通过浏览器的DOM将其附加到地图。 The API indicates that the overlay has been added to the map by invoking the overlay's onAdd() method. API通过调用叠加层的onAdd()方法来指示该叠加层已添加到地图。 To handle this method you create a <div> to hold your image, add an <img> element, attach it to the <div> , and then attach the overlay to one of the map's panes. 要处理此方法,您可以创建一个<div>来保存图像,添加一个<img>元素,将其附加到<div> ,然后将叠加层附加到地图的一个窗格中。 A pane is a node within the DOM tree. 窗格是DOM树中的一个节点。 You can resize the image that match the bounds that you specified in the overlay's constructor. 您可以调整图像的大小,使其与在叠加层的构造函数中指定的边界匹配。 You can change it using <div> . 您可以使用<div>进行更改。

For more information you can also check this . 有关更多信息,您也可以检查一下

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

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