我是一个真正的javascript新手,我需要帮助才能在koken (摄影师的CMS )内实现mapbox地图的适当集成。
这个想法是做一些像https://www.flickr.com/map这样的事情,在地图上呈现图片。
现在我的代码如下所示:
<div id='map' style="height: 800px;"></div>
<script>
var map = L.mapbox.map('map', 'mymap')
.setView([48.895513333333, 2.39237], 6);
//loop to create markers
<koken:load limit="30" source="contents">
<koken:loop>
L.mapbox.featureLayer({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [
{{ geolocation.longitude }},
{{ geolocation.latitude }}
]
},
properties: {
'title' : '{{ content.title }} <br/> <a href="{{ content.url }}">Voir la photo</a>',
'marker-size': 'large',
'marker-color': '#CC0001',
'marker-symbol': 'camera'
}
}).addTo(map);
</koken:loop>
</koken:load>
</script>我的问题是:
{{ geolocation.longitude }}或{{ geolocation.latitude }},当这个字段为空时,地图就不会显示下一个标记。我试着通过做一个if( ) { }来过滤,但是失败了。就像一个人说我是新手..。有人能告诉我怎么弄清楚这个吗?非常感谢那些愿意帮助我的人!
发布于 2014-06-19 10:08:03
我本可以这样做的:
<div id='map' style="height: 800px;"></div>
<script>
var map = L.mapbox.map('map', 'mymap')
.setView([48.895513333333, 2.39237], 6);
// Array containing markers datas
var points = new Array();
//koken loop to populate markers datas
<koken:load limit="30" source="contents">
<koken:loop>
points.push({
cLng: {{ geolocation.longitude }} +0, // hack to add empty coordinate
cLat: {{ geolocation.latitude }} +0,
title: "{{ content.title }}",
url: "{{ content.url }}"
});
</koken:loop>
</koken:load>
// JS Loop thru markers datas to create markers on map
for(var idx in points) {
// Only for non empty coordinates
if((points[idx].cLng != 0) && (points[idx].cLat != 0)) {
L.mapbox.featureLayer({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [
points[idx].cLng,
points[idx].cLat
]
},
properties: {
'title' : points[idx].title +' <br/> <a href="'+points[idx].url+'">Voir la photo</a>',
'marker-size': 'large',
'marker-color': '#CC0001',
'marker-symbol': 'camera'
}
}).addTo(map);
}
}
</script>记者:我不认识科肯,所以不知道你的最后一个问题。
https://stackoverflow.com/questions/24303035
复制相似问题