1

私はこれをオンラインで見つけようとしましたが、あまり運がありませんでした。Stackoverflowにも同様の質問ソリューションはないようです。これは私が見つけた最も近い比較です:

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ファイルの「ポリラインの作成」関数を変更する方法に関する提案はありますか? 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関数で、2行目を追加しました。

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:配列要素が別の配列と一致します

これで、リンクにマウスオーバーするたびに、Chrome javascriptコンソールで不透明度に変化がなく、このエラーが発生します。

Uncaught TypeError:Object javascript:void(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とは何の関係もないので、混乱しています!また、リソース解釈エラーはもっと一般的であるように思われるので、今は無視しています...

あなたのヒント、前向きなことをありがとう、そして私は私の新しいエラーにいくつかの光を当てることができる他の誰かに感謝します...

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

さて、これを理解しました-あなたのヒントをapneadivingしてくれてありがとう!将来の参考のために(これが実際に誰かに役立つ場合)、基本的にこれらの2行(onmouseoverとonmouseout)をgmaps4rails.base.js.coffeeのcreateSidebarに追加しました。

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}
4

1 に答える 1

0

さて、これを理解しました-あなたのヒントをapneadivingしてくれてありがとう!将来の参考のために(これが実際に誰かに役立つ場合)、基本的にこれらの2行(onmouseoverとonmouseout)をgmaps4rails.base.js.coffeeのcreateSidebarに追加しました。

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}
于 2012-05-23T21:32:15.043 に答える