【发布时间】:2020-04-24 22:40:11
【问题描述】:
我觉得这段代码不错。数据返回正确,正在创建标记对象,但仅显示第一个标记。实际上有两组标记,所讨论的一组都是红色标记。我已经注释掉了其他人,但留下了代码。 下面是 MySQL/PHP 创建的代码:
var W0KCN3 = new L.Marker(new L.LatLng(39.2859182,-94.667236),{
contextmenu: true, contextmenuWidth: 140,
contextmenuItems: [{ text: 'Click here to add mileage circles',
callback: circleKoords}],
icon: new L.NumberedRedIcon({number: 'E1' }),
title: "marker_E1"}).addTo(fg).bindPopup("W0KCN-3 Platte Co. Resource Center<br>Kansas City, MO<br>39.2859182, -94.667236<br>EM29PG").openPopup();
$(EOC._icon).addClass("redmrkr");
markers.push(W0KCN3);
var W0KCN4 = new L.Marker(new L.LatLng(39.3721733,-94.780929),{
contextmenu: true, contextmenuWidth: 140,
contextmenuItems: [{ text: 'Click here to add mileage circles',
callback: circleKoords}],
icon: new L.NumberedRedIcon({number: 'E2' }),
title: "marker_E2"}).addTo(fg).bindPopup("W0KCN-4 Platte Co. EOC<br>Platte City, MO<br>39.3721733, -94.780929<br>EM29OI").openPopup();
$(EOC._icon).addClass("redmrkr");
markers.push(W0KCN4);
var STJOMC = new L.Marker(new L.LatLng(38.93620,-094.60370),{
contextmenu: true, contextmenuWidth: 140,
contextmenuItems: [{ text: 'Click here to add mileage circles',
callback: circleKoords}],
icon: new L.NumberedRedIcon({number: 'H1' }),
title: "marker_H1"}).addTo(fg).bindPopup(" Saint Joseph Medical Center<br>Kansas City, MO 64114-4865<br>38.93620, -094.60370<br>EM28QW").openPopup();
$(Hospital._icon).addClass("redmrkr");
markers.push(STJOMC);
在这个简单的例子中,标记 W0KCN3 出现在地图上,但没有显示后续标记。在我看来,服务器正确地返回了所有信息,还有大约 70 个标记。如果我注释掉对 W0KCN3 的 MySQL 调用,则标记 W0KCN4 会显示,而没有其他标记。这至少适用于我尝试过的前 10 个。
这个测试程序可以在https://net-control.us/map1Rose.php看到
【问题讨论】:
-
听起来你的 JS 中的一些错误正在引发异常并停止执行任何进一步的 JS。您的浏览器控制台是否有任何错误?
-
我在开发者工具中遇到一个错误。 Uncaught ReferenceError: EOC is not defined,但我无法在代码中找到对 EOC 的引用。但这确实给了我一个我会探索的想法。
-
已解决:问题在于构建标记 addClass。我必须附上 $row[class] 以包含引号。我不知道为什么我的代码以前版本不需要它们,但现在它们是。
标签: javascript leaflet