Answer the question
In order to leave comments, you need to log in
Yandex maps Uncaught TypeError: Cannot read property '1' of null - how to fix?
The map uses a clusterer. When incrementing, this error "Uncaught TypeError: Cannot read property '1' of null" occurs. The fact is that everything worked, and no changes were made to the code, and recently this has begun to occur.
here is the code that does it.
ymaps.ready(function () {
var objects = {$arr|json_encode:true};
var coords = [], icons = [], img = [], name = [], address = [], url = [];
for (var x = 0; x < objects.length; x++) {
coords[x] = objects[x]['point'];
icons[x] = objects[x]['placemark'];
img[x] = objects[x]['img'];
name[x] = objects[x]['name'];
address[x] = objects[x]['address'];
url[x] = objects[x]['url'];
}
var myMap = new ymaps.Map('map', {
center: [55.751574, 37.573856],
zoom: 9,
controls: ['fullscreenControl', 'zoomControl']
}),
MyIconContentLayout = ymaps.templateLayoutFactory.createClass('<span style="color: #ffffff; font-weight: bold; font-size: 38px;">$[properties.geoObjects.length]</span>'),
clusterer = new ymaps.Clusterer({
gridSize: 80,
clusterDisableClickZoom: false,
clusterIcons: [{
href: '/media/files/cluster.png',
size: [69, 75],
offset: [-34, -37]
}],
clusterNumbers: [100],
clusterIconContentLayout: MyIconContentLayout
}),
points = coords,
geoObjects = [];
function getPointData(index) {
return {
balloonContentBody: '<img class="dealer-map-img" src="'+img[index]+'" />' +
'<div class="dealer-map-content"><h6 class="dealer-map-name">' + name[index] + '</h6>' +
'<address class="dealer-map-address">' + address[index] + '</address>' +
'<a class="dealer-map-site" href="' + url[index] + '" target="_blank">Перейти на сайт</a></div>'
};
}
function getPointOptions(index) {
return {
iconLayout: 'default#image',
iconImageHref: icons[index],
iconImageSize: [69, 75],
offset: [-34, -37]
};
}
for(var i = 0, len = points.length; i < len; i++) {
geoObjects[i] = new ymaps.Placemark(points[i], getPointData(i), getPointOptions(i));
}
clusterer.add(geoObjects);
myMap.geoObjects.add(clusterer);
myMap.behaviors.disable('scrollZoom');
myMap.setBounds(clusterer.getBounds(), {
checkZoomRange: true
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question