Теперь я назвал каждый объект name в var, но карта все еще не работает.
Я хочу отобразить пользовательские значки, которые определены в json объект данных по имени свойства. У меня есть несколько значков. Я написал этот код, но он не работает, и моя консоль говорит, что ошибка в строке 266,
"Uncaught TypeError: Невозможно прочитать свойство 'createIcon' из undefined", но я не могу понять ошибка.
var map = L.map('map').setView([50.922082,6.944733], 13);
var markerIcons = {
"REWE": L.icon({
iconUrl: 'rewe.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Kaufland": L.icon({
iconUrl: 'kaufland.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Netto Filiale": L.icon({
iconUrl: 'netto.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"REWE Rahmati": L.icon({
iconUrl: 'rewe.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Lidl": L.icon({
iconUrl: 'lidl.jpg',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"ALDI SÜD": L.icon({
iconUrl: 'aldi.jpg',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"PENNY": L.icon({
iconUrl: 'penny.jpg',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"dm-drogerie markt": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Hit": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"HIT Handelsgruppe GmbH & Co. KG": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Hit getränkemarkt": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Hit Markt": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Kaufland Köln-Niehl": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Kaufland Köln-Ehrenfeld": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Kaufland Köln-Kalk": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Kaufland Köln-Mühlheim": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"NORMA Filiale": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"NORMA": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"real": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Wodarz Getränkemarkt": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Center Engels Marsdorf GmbH": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Engels": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Peters": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Gans": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Daub KG": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Center Engels Widdersdorf": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Romano": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Wodarz": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Kausemann": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Weiden": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Hein": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Feldmann-Höner": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA - Die Kippings": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Blomeier": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Aktiv Markt Hetzenegger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA STEFFENS": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Jung": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Markt Hein": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Frischmarkt Zickuhr": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Stahl": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Klein": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Hetzenegger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA-Markt Frischecenter J. Engels GbR": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Geurtz": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Wünsch": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Hetzenegger Getränkemarkt": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Klein Hessling": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Breuer": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Höner": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Schröder": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA FrischeCenter Gusek": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Zickuhr": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Köln-Merheim": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Klein-Heßling": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Mülln": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Bonus": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"EDEKA Breidohr-Frischecenter": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
"Edeka Jünger": L.icon({
iconUrl: 'dm.png',
iconSize: [38, 95],
iconAnchor: [22, 94],
popupAnchor: [-3, -76],
}),
};
for (var i = 0; i < jsonDataObject.length; i++) {
var lat = parseFloat(jsonDataObject[i].geometry.location.lat);
var lng = parseFloat(jsonDataObject[i].geometry.location.lng);
var marker = L.marker(L.latLng(lat, lng), {
icon: markerIcons[jsonDataObject[i].name]
});
marker.bindPopup(jsonDataObject[i].name, {
autoClose: false
});
map.addLayer(marker);
marker.myJsonData = jsonDataObject[i];
};
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);