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

发布于 2024-10-17 12:09:48 字数 665 浏览 1 评论 0原文

我有一个记录列表,显示为屏幕一侧的部分内容,可以进行过滤。在另一边,我有一张手绘地图,它是一个带有背景图像的 div。如何为地图上的每条记录添加一个图标,该图标仅在显示部分记录时显示?

索引页面如下所示:

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

感谢您的帮助。

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. 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵性 2024-10-24 12:09:48

您需要向场地对象添加一些方法或以某种方式更改渲染方法...好吧,只需在每个场地输出一些 javascript 数据,如下所示:

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

然后添加一个函数,它将迭代该数据数组:

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

以及一些css之类的

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

如果你想要以更优雅的方式...我忘记了我所知道的关于Ruby的一切:-D 是你为你的问题添加了 javascript 标签;-)

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:

<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

#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 ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文