简体   繁体   English

如何为局部零件创建地图图标?

[英]How can I create map icons for partials?

I have a list of records being displayed as partials down one side of the screen which can be filtered. 我有一个记录列表,该记录被显示为屏幕一侧的部分内容,可以过滤。 And on the other side I have a hand drawn map which is a div with a background image. 在另一侧,我有一个手绘地图,它是一个带有背景图像的div。 How can I have an icon for each record on the map which is only displayed when the records partial is shown? 如何为地图上的每条记录设置一个图标,该图标仅在显示部分记录时才显示?

Index page looks like this: 索引页面如下所示:

<div class="map_container">
</div>

<div class="filter_options_container">
  filter form stuff is here
</div>

<div class="venue_partials_container">
  <%= render :partial => 'venue', :collection => @venues %>
  <div class="clearall"></div>

  <%= will_paginate @venues %>

  <div class="venue_partial_button">
    <%= link_to 'add a new venue', new_venue_path %>
  </div>
</div>

<div class="clearall"></div>

Thanks for any help. 谢谢你的帮助。

You need to add some method to venue object or change render method, in some way... well, just output some javascript data with each venue like next: 您需要以某种方式向场所对象添加某种方法或更改渲染方法...好吧,只需在每个场所输出一些javascript数据,如下所示:

<script type="text/javascript"><!--
data.push({
  x: <%= this.x %>,
  y: <%= this.y %>,
  someOtherStuff: <%= this.stuff %>
});
--></script>

and after that add a function, which will iterate through that data array: 然后添加一个函数,该函数将遍历该数据数组:

function insertIconOnMap(mapItem){
  var img = $("<img>", {
    'class': "mapIcon",
    'src': mapItem.someOtherStuff
  }).css({
    'left': mapItem.x,
    'top': mapItem.y
  });
  $("#map").append(img);
}
data.each(insertIconOnMap);

and some css like 和一些CSS像

#map { position: relative; }
#map .mapIcon { position: absolute; }

If you want it in more elegant way... I forget everything I knew about Ruby :-D And it was you, who put javascript tag for your question ;-) 如果您想要更优雅的方式...我忘了我对Ruby的所有了解:-D正是您,为您的问题添加了javascript标签;-)

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

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