gmaps4rails replaceMakers闪烁效果

编程入门 行业动态 更新时间:2024-10-28 20:20:53
本文介绍了gmaps4rails replaceMakers闪烁效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当用户平移地图时,我向服务器发出ajax请求,并获得所有落入新界限的标记,这些标记几乎与此处描述的相同:使用gmaps4rails动态加载Google Maps标记

When user pans the map, I make and ajax request to the server and get all the markers that fall into the new bounds, something almost identical to what is described here: Dynamically load Google Maps Markers with gmaps4rails

我的问题是,当我使用replaceMarker时,将重新创建地图上的所有标记,因此每个标记都闪烁一次.这真的让我很烦.

My problem is that when I use replaceMarker all the markers on the map are recreated therefore each of them flickers onces. This really annoys me.

如果使用addMarkers,则不会获得闪烁效果,但侧边栏却被拧紧了,因为: 1)平移后未加在范围内的标记不会从我的标记列表中删除. 2)一些重复项添加到我的标记列表中-标记落入新旧边界的交点.

If I use addMarkers, I don't get the flicker effect, but my sidebar gets screwed because; 1) The markers which are left out of the bounds after pan, are not removed from my marker list. 2) Some duplicates are added to my marker list - markers that fall into intersection of old and new bounds.

我尝试修改addmarkers函数,但效果不佳.

I tried modifying the addmarkers function but nothing good came out of it.

推荐答案

这就是我更改addMarkers函数的方式.将new_markers与旧标记进行比较,以找出要删除的标记并将其保留下来.

This is how I changed the addMarkers function. Comparing the new_markers set to the old one to find out which ones to remove and leave the already existing ones alone.

addMarkers : (new_markers) -> #update the list of markers to take into account @resetSidebarContent() added_markers = (marker for marker in new_markers when ($.grep(@markers, (a) -> a.id == marker.id).length == 0)) removed_markers = (marker for marker in @markers when ($.grep(new_markers, (a) -> a.id == marker.id).length == 0)) for marker in removed_markers @clearMarker(marker) @markers.remove(marker) @markers = @markers.concat(added_markers) #put markers on the map @create_markers() @adjustMapToBounds()

更多推荐

gmaps4rails replaceMakers闪烁效果

本文发布于:2023-08-02 00:11:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272939.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:效果   gmaps4rails   replaceMakers

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!