1

我试图在网上找到它,但没有多少运气。 Stackoverflow似乎也没有类似的问题解决方案。这是最接近的比较,我发现:鼠标悬停地标链接时突出​​显示Google地图折线

http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/2121de2422cf5053?pli=1

但是这个人的活页看起来并不像他们说的很远(他们只有2010年1月对他们的地图工作)...但相同的思路我想做的事。我不知道如何实现给定的解决方案,因为我将有数百个折线,并且不想为它们中的每一个创建全局变量...

我想要做的是“集群“以某种方式具有从该标记开始/结束的一组多段线的地标。然后,我会在该地标的侧边栏/菜单外链接中提供一个链接,我希望当用户将鼠标悬停/悬停到地标的链接时,与地标关联的多段线会更改其不透明度(即高光)。我认为我的问题是:

  1. 如何引用已创建的折线?我如何弄清楚它的手柄?
  2. 我能以某种方式使用“穿过”我的标记的事实来更改多段线的属性吗? (即aSel.onmouseover(“接触这个物体的所有多段线都具有不透明度= 1”))
  3. 有关如何修改gmaps4rails.base.js文件的“create polyline”函数来执行此操作的任何建议? https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee 我有这种感觉,那么我的问题就会变成“我在创建多段线时如何知道链接/地标的处理程序?”如果我尝试这种方法...

我目前使用Rails和gmaps4rails插件来尝试这个,但我打开其他优雅的建议/解决方案。

感谢您的帮助!

==========================================

这是我迄今为止尝试过的代码,下面是apneadiving的建议(我不是Rails,javascript,Coffeescript或Maps专家...):

在gmaps4rails.base.js中的createSidebar功能,添加的第二行:

aSel.onclick = @sidebar_element_handler(currentMap, marker_container.serviceObject, 'click') 
aSel.onmouseover = @sidebar_highlight_paths(currentMap, marker_container.serviceObject) 

然后定义:

sidebar_highlight_paths : (currentMap, marker) -> 
    return() -> 
    for polyline in Gmaps.map.polylines 
     points = polyline.serviceObject.latLngs.getArray()[0].getArray() 
     if (@sidebar_intersect(points, marker.position)) 
     @polyline.setOptions({strokeOpacity: 1.0}) 

sidebar_intersect : (a, b) -> 
    [a, b] = [b, a] if a.length > b.length 
    value for value in a when value in b 

相交功能是基于在这里下车的响应: Coffeescript: Array element matches another array

现在我得到的不透明性和不改变这个错误在我的Chrome的JavaScript控制台,每当我将鼠标悬停在链接:

遗漏的类型错误:对象中的JavaScript :无效(0);没有方法 'sidebar_intersect' Gmaps4Rails.Gmaps4Rails.sidebar_highlight_pathsgmaps4rails.base.js:434

资源解释为图像但具有MIME类型text/html移送: “http://maps.googleapis.com/maps/gen_204?ev=api_viewport&cad=src:apiv3,ts:1336420051554”。

434线(上面无方法错误)是:

if @map_options.auto_adjust 
    #from markers 
    @extendBoundsWithMarkers() 
->line 432<- 
    #from polylines: 
    for polyline in @polylines ->line 434<- 
    polyline_points = polyline.serviceObject.latLngs.getArray()[0].getArray() 
    for point in polyline_points 
     @boundsObject.extend point 

这无关我的新功能,sidebar_intersect,所以我很困惑!此外,我现在忽略资源解释错误,因为它似乎更普遍...

感谢您的提示,aneadiving,我欣赏其他人谁可以阐明我的新错误...

=============================

好的,想通了 - 谢谢你的提示apneadiving!对于未来的参考(这实际上可以帮助任何人),我基本上都添加了这两条线(的onmouseover和onmouseout)以createSidebar在gmaps4rails.base.js.coffee:

aSel.onclick = @sidebar_element_handler(currentMap, marker_container.serviceObject, 'click') 
aSel.onmouseover = @sidebar_highlight_paths(currentMap, marker_container.serviceObject) 
aSel.onmouseout = @sidebar_reset_paths(currentMap, marker_container.serviceObject) 
li.appendChild(aSel) 
ul.appendChild(li) 

然后:

sidebar_highlight_paths : (currentMap, marker) -> 
return() -> 
    for polyline in Gmaps.map.polylines 
    b = polyline.serviceObject.latLngs.getArray()[0].getArray() 
    for latlng in b 
     if (marker.position.equals(latlng)) 
     polyline.serviceObject.setOptions({strokeOpacity: 1}) 

sidebar_reset_paths : (currentMap, marker) -> 
return() -> 
    for polyline in Gmaps.map.polylines 
    polyline.serviceObject.setOptions({strokeOpacity: 0.1} 
+1

这需要很多工作。我会给你一些轨道:1)循环'Gmaps.map.polylines'并标记你想要的多义线,例如:'Gmaps.map.polylines [0] .foo =“bar”'2)不知道你怎么知道它通过一个标记,但如果你知道它,只需处理谷歌多段线对象例如:'Gmaps.map.polylines [0] .serviceObject' – apneadiving

回答

0

好,想通了 - 谢谢你的提示apneadiving!对于未来的参考(这实际上可以帮助任何人),我基本上都添加了这两条线(的onmouseover和onmouseout)以createSidebar在gmaps4rails.base.js.coffee:

aSel.onclick = @sidebar_element_handler(currentMap,marker_container.serviceObject, 'click') 
aSel.onmouseover = @sidebar_highlight_paths(currentMap,marker_container.serviceObject) 
aSel.onmouseout = @sidebar_reset_paths(currentMap,marker_container.serviceObject) 
li.appendChild(aSel) 
ul.appendChild(li) 

然后:

sidebar_highlight_paths : (currentMap, marker) -> 
return() -> 
    for polyline in Gmaps.map.polylines 
    b = polyline.serviceObject.latLngs.getArray()[0].getArray() 
    for latlng in b 
     if (marker.position.equals(latlng)) 
     polyline.serviceObject.setOptions({strokeOpacity: 1}) 

sidebar_reset_paths : (currentMap, marker) -> 
return() -> 
    for polyline in Gmaps.map.polylines 
    polyline.serviceObject.setOptions({strokeOpacity: 0.1} 
相关问题