Я пытаюсь добавить маркеры в leaflet.indoor. Я получаю данные из файла geoJson. Я продолжаю получать эту ошибку «Uncaught TypeError: невозможно прочитать свойство« addLayer »неопределенного« leaflet-indoor.js: 57. Я относительно новичок в javascript и программировании.Uncaught TypeError: Невозможно прочитать свойство addLayer undefined - листовка
вот мой код.
$.getJSON("gateway.json", function(geoJSON) {
var indoorLayer = new L.Indoor(gateway, {
getLevel: function(feature) {
if (feature.properties.length === 0)
return null;
return feature.properties.level;
},
markerForFeature: function(feature) {
var content = feature.properties.name;
var iconCoords = feature.properties.center;
var myIcon = L.divIcon({
className: 'ls-room-marker',
html: content,
iconSize: new L.Point(100, 14),
iconAnchor: new L.Point(50, 7)
});
var marker = L.marker(iconCoords, {
icon: myIcon
});
return marker;
},
onEachFeature: function(feature, layer) {
layer.bindPopup(JSON.stringify(feature.properties, null, 2));
},
style: function(feature) {
var fill = 'white';
if (feature.properties.buildingpart === 'base') {
fill = 'silver';
} else if (feature.properties.buildingpart === 'hallway') {
fill = 'cornsilk';
}
return {
fillColor: fill,
weight: 1,
color: '#666',
fillOpacity: 1
};
}
});
indoorLayer.setLevel("0");
indoorLayer.addTo(map);
var levelControl = new L.Control.Level({
level: "0",
levels: indoorLayer.getLevels()
});
// Connect the level control to the indoor layer
levelControl.addEventListener("levelchange", indoorLayer.setLevel, indoorLayer);
levelControl.addTo(map);
});
Я отредактировал часть кода как показано ниже, но у меня по-прежнему нет меток.
markerForFeature: function(feature) {
if (feature.properties.category === "general"){
var iconCoords = feature.properties.center;
var content;
if ("name" in feature.properties && "category" in feature.properties) {
content = feature.properties.name + "(" + feature.properties.category + ")";
}
else if
("category" in feature.properties) {
content = feature.properties.category;
} else if ("name" in feature.properties) {
content = feature.properties.name;
} else {
return;
}
Можете ли вы предоставить более подробную информацию о том, как это относится к вопросу? Я не вижу 'onMapClick' в любом месте OP, или любое указание, что щелчок по карте является проблемой или связано с решением. – GalacticCowboy