Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/53.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当鼠标悬停在侧边栏中的项目上时,gmaps4rails会更改标记颜色_Javascript_Ruby On Rails_Gmaps4rails - Fatal编程技术网

Javascript 当鼠标悬停在侧边栏中的项目上时,gmaps4rails会更改标记颜色

Javascript 当鼠标悬停在侧边栏中的项目上时,gmaps4rails会更改标记颜色,javascript,ruby-on-rails,gmaps4rails,Javascript,Ruby On Rails,Gmaps4rails,我试图通过gmaps4rails实现这种行为:用户将鼠标悬停在侧边栏中的一个框上(带有标记所在建筑物的图片),地图上相应的标记会更改图像/颜色,以使所选的标记从其他标记中脱颖而出 我对rails很了解,但我对javascript很不在行 我从前面的一个类似问题中看到了这段代码: Gmaps.map.callback = function(){ for(var i = 0; i < Gmaps.map.markers.length; i++){ marker = Gmaps.map.ma

我试图通过gmaps4rails实现这种行为:用户将鼠标悬停在侧边栏中的一个框上(带有标记所在建筑物的图片),地图上相应的标记会更改图像/颜色,以使所选的标记从其他标记中脱颖而出

我对rails很了解,但我对javascript很不在行

我从前面的一个类似问题中看到了这段代码:

Gmaps.map.callback = function(){
for(var i = 0; i < Gmaps.map.markers.length; i++){
  marker = Gmaps.map.markers[i];
  google.maps.event.addListener(marker.serviceObject, 'click', 
  (function(marker){
    return function(){
     console.log($(marker.serviceObject.ne.ga).attr("src", "/assets/marker_sprite2.png"));
    }
  })(marker)
  )
  }
}
Gmaps.map.callback=function(){
对于(var i=0;i
但我不知道该把它放在我的应用程序中的什么地方,也不知道如何将它与侧边栏中的项目关联起来


很抱歉问这么一个基本的问题。请帮助?

我有完全相同的问题,以下是我的(部分)解决方案:

假设您已经设置了rails应用程序,就像youtube视频上显示的那样(链接到github页面)

将marker.json({:id=>location.id})添加到您的控制器中,使其结果如下:

@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
  marker.lat location.latitude
  marker.lng location.longitude
  marker.infowindow "$#{location.suggested_price}, #{location.address}"
  marker.json({ :id => location.id })
end
然后,在javascript下的视图中构建一个映射,添加一个.each函数,该函数遍历每个json片段,并将功能添加到视图中相应的类中(我假设您使用名为“location-”的div包装每个侧边栏项):


希望这能有所帮助!

我有一个完全相同的问题,下面是我的(部分)解决方案:

假设您已经设置了rails应用程序,就像youtube视频上显示的那样(链接到github页面)

将marker.json({:id=>location.id})添加到您的控制器中,使其结果如下:

@hash = Gmaps4rails.build_markers(@locations) do |location, marker|
  marker.lat location.latitude
  marker.lng location.longitude
  marker.infowindow "$#{location.suggested_price}, #{location.address}"
  marker.json({ :id => location.id })
end
然后,在javascript下的视图中构建一个映射,添加一个.each函数,该函数遍历每个json片段,并将功能添加到视图中相应的类中(我假设您使用名为“location-”的div包装每个侧边栏项):


希望能有所帮助!

您使用哪个版本?哇!感谢您快速响应(我喜欢您的gem)。我在2.x中使用的是2.1.1Ok si版本,
Gmaps.map.callback
已被弃用,还有
Gmaps.map.markers.length
。请查看您使用哪个版本的示例?哇!感谢您快速响应(我喜欢您的gem).我在2.x中使用的是2.1.1Ok si版本,
Gmaps.map.callback
已被弃用,还有
Gmaps.map.markers.length
。有关这方面的检查示例非常有用,可能应该添加到wiki中,谢谢这非常有用,可能应该添加到wiki中,谢谢
      handler.getMap().setZoom(14);
      json.marker.setMap(handler.getMap()); //because clusterer removes map property from marker
      json.marker.panTo();
      google.maps.event.trigger(json.marker.getServiceObject(), 'click');