2
リーフレット。 geoJsonファイルからデータを取得しています。 57:リーフレット-indoor.js:私はこのエラー「未定義のプロパティ 『addLayer』を読み取ることができませんキャッチされない例外TypeError」を得続けます。私は比較的新しいjavascriptとプログラミングです。キャッチされない例外TypeError:未定義の「addLayer」プロパティを読み取ることができません - 私はleaflet.indoorするマーカーを追加しようとしている
ここは私のコードです。
$.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);
});
私は下記のコードの部分を編集しましたが、まだラベルは表示されません。私は(、this.onMapClickを 'クリック')
this.map.onを使用しようとした
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;
}
これがどのように質問に関係しているかについて詳しく説明できますか?私は 'OP、またはマップをクリックすると、問題や解決策に関連していること兆候のどこにonMapClick'表示されません。 – GalacticCowboy