我想创建一个应用程序,帮助用户搜索城市中的美食场所,以便他们将来可以重新访问。这个应用程序是我第一个使用传单的有趣项目。我想做的是从数据库中制作简单的地图和加载标记,当用户从类别查询地点或在搜索栏中搜索时,只显示标记。我确实测试了JSFiddle中的索引pageand 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。 PLease帮助我,我确实审查了文档,测试了很多但没有出现。有人请帮助我,因为我真的很喜欢传单
答案 0 :(得分:0)
您在new
之前抛出L.marker
,这不是此构造函数的格式。请注意m
上的大小写差异。它必须是L.marker(options)
}或new L.Marker(options)
。您只需要new
样式标记初始化L.Marker
。
见http://leafletjs.com/reference.html#marker