这段代码以前有用,但是我不确定我改变了什么,或者Leaflet中有什么改变来打破它,但没有显示任何标记。数据正确返回,正在创建标记对象,但不显示任何标记。我在这里不知所措。使用0.7.2。让我告诉你代码......
function getGameMarkers(){
var center = map.getCenter();
var zoo = map.getZoom();
var bounds = map.getBounds();
var min = bounds.getSouthWest().wrap();
var max = bounds.getNorthEast().wrap();
//console.log(bounds);
//console.log(min);
//console.log(max);
$.ajax({type: "GET", url: "./ajax/markers.php", dataType: "json", data: "clat="+center.lat+"&clng="+center.lng+"&zoom="+zoo+"&minlat="+min.lat+"&minlng="+min.lng+"&maxlat="+max.lat+"&maxlng="+max.lng+cookiestr,
success: function(data){
if (data.showmap == 1) {
plotlist = data.map_data;
removeMarkers();
//console.log(plotlist.length);
for (i=0;i<plotlist.length;i++) {
var iconic = String(plotlist[i].icon);
var plotmark = new L.marker([plotlist[i].lat,plotlist[i].lng], {icon: L.icon({iconUrl: iconic, iconSize: [32, 32]}) }).bindPopup(plotlist[i].html);
map.addLayer(plotmark);
console.log(plotmark);
console.log(plotlist[i]);
plotlayers.push(plotmark);
}
$("#content").html(data.html);
}else {
$("#map_content").show();
$("#map_content").html(data.main_content);
$("#content").html(data.side_content);
}
}
});
}
一切都应该工作得很好。服务器正确返回信息。列表中总共有13个项目(预期行为),我将plostlist [i]的内容打印到控制台以及plotmarker对象。
这是plotlist [i]的输出:
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "41.564087", lng: "-73.023376", icon: "./img/avicon3.png", html: "<a href='#' onclick='getcon(8,107184863);'>viktor</a><br/><br/>Level: 2 / Energy: 3 "} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.944637", lng: "-73.671570", icon: "./img/avicon3.png", html: "<a href='#' onclick='getcon(8,116518883);'>gambatedhan</a><br/><br/>Level: 3 / Energy: 8 "} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "41.288128", lng: "-74.135742", icon: "./img/avicon2.png", html: "<a href='#' onclick='getcon(8,118454338);'>halil</a><br/><br/>Level: 1 / Energy: 8 "} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.857449", lng: "-74.039612", icon: "./img/avicon3.png", html: "<a href='#' onclick='getcon(8,120599464);'>KIM15</a><br/><br/>Level: 2 / Energy: 1 "} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.6687012", lng: "-73.9646988", icon: "./img/bicon2.png", html: "<a href='#' onclick='getcon(2, 157764); return false;' >Brooklyn Botanic Garden</a>"} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.7062111", lng: "-73.3062286", icon: "./img/ricon.png", html: "<a href='#' onclick='getcon(1, 114779); return false;' >West Islip</a>"} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.7625999", lng: "-73.4531784", icon: "./img/ricon.png", html: "<a href='#' onclick='getcon(1, 114526); return false;' >Old Bethpage</a>"} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
Object {lat: "40.9381485", lng: "-73.8320770", icon: "./img/ricon.png", html: "<a href='#' onclick='getcon(1, 114063); return false;' >Bronxville</a>"} (index):100
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
一切看起来都很好......现在用于标记输出:
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
(index):99
e {options: Object, _latlng: o.LatLng, _initHooksCalled: true, _leaflet_events: Object, _popupHandlersAdded: true…}
再次,看起来很好。
因此...
以下是我对可能发生的事情的看法...要么返回的那些lat / lng坐标被弃用,要么被解释得不同而且它们不在地图上,或者由于某种原因没有显示图层。有什么想法吗?
答案 0 :(得分:2)
事实证明,世界重新开始,并且自我包裹。要解决此问题,需要在地图选项中将worldCopyJump设置为true。
答案 1 :(得分:2)
添加你自己的CSS ...它对我有用..在你的css文件中包含以下代码。
.leaflet-map-pane {
z-index: 2 !important;
}
.leaflet-google-layer {
z-index: 1 !important;
}