【发布时间】:2015-10-21 20:53:28
【问题描述】:
我想创建一个应用程序,帮助用户搜索城市中的美食场所,以便他们将来可以再次访问。这个应用程序是我第一个使用传单的有趣项目。我想做的是制作简单的地图并从数据库中加载标记,其中标记仅在用户从类别中查询地点或在搜索栏中搜索时出现。我确实在 JSFiddle 中测试了 index page 和 marker.js,但它只出现在搜索按钮、栏和类别旁边的 map-wrap。
Marker.js
//now map reference the global map declared in the first line
map=L.map('map').setView(true)
//marker development
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data ©<a href="http://openstreetmap.org">OpenStreetMap</a>
contributors,<a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
maxZoom:18
}).addTo(map);
newMarkerGroup = new L.LayerGroup();
map.on('click',addMarker);
});
//add group layer to map
map.addLayer(search_group);
//start to initiate adding marker
function addMarker(e){
// Add marker to map at click location; add popup window
var newMarker = new L.marker(e.latlng).addTo(map);
}
//create array
var marker= new Array();
function onMapClick(e){
marker = new L.Marker(e.latlng,
{draggable: false});
//pushing items into array each by each and then add markers
function itemWrap(){
for(i=0; i<items.length; i++){
var LamMarker = new
L.marker([items[i].lat,items[i].lon]);
marker.push(LamMarker);
map.addLayer(marker[i]);
}
}
//create popup
marker.bindPopup().openPopup();
};
//add to map function with a popup that contains a link, which when clicked will have a popup of details and booking options
//this link will have as its id the latlng of the point
//this id will then be compared to when you click on one of your created markers
map.on('click',function(e){
var clickPositionMarker = L.marker([e.latlng.lat,e.latlng.lng],{icon:idMarker});
clickArr.push(clickPositionMarker);
mapLat = e.latlng.lat;
mapLon = e.latlng.lng;
clickPositionMarker.addTo(search_group).bindPopup().openPopup();
L.marker(e.latlng).addTo(map)
.bindPopup("You're within " + radius + " meters from this point").openPopup();
L.circle(e.latlng, radius).addTo(map);
}
map.on('locationfound' , onLocationFound);
//access it using markers[i]["id"]
我之前确实测试过 index.html,当然我取消了 L.marker 的注释 功能,它工作正常。确实出现了弹出窗口。但是当我测试标记时,将评论放在 L.marker 上,只出现 map-wrap 和其他 css。请帮助我,我确实查看了文档,测试了很多但没有出现。有人请帮助我,因为我对传单真的很陌生
【问题讨论】: