![](/img/trans.png)
[英]How can I change the style of the icons in a map with openlayer and a geoJson file
[英]How can I create map icons for partials?
我有一个记录列表,该记录被显示为屏幕一侧的部分内容,可以过滤。 在另一侧,我有一个手绘地图,它是一个带有背景图像的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>
谢谢你的帮助。
您需要以某种方式向场所对象添加某种方法或更改渲染方法...好吧,只需在每个场所输出一些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
标签;-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.