Здравствуйте, запутался на отображении объектов, в json передаю 10 объектов среди них json[0] - это основной объект, как мне реализовать отображение оставшихся 9 объектов относительно основного объекта json[0] в радиусе к примеру 1 км, чтобы отобразились те точки которые расположены в радиусе 1 км от основного объекта json[0] а какие не входят в этот критерий отсекаем.
Пример кода моего, при клике обрабатываю и достаю из бд данные преобразую в json и затем передаю в $.setMarks
var map, circle, clusterer, myGeoObjects = [], myGeoQuery = [];
$.setMarks = function setMark(json, isfirst, priceInDay, cash) {
debugger;
myMap.destroy();
if (isfirst) {
map = new ymaps.Map("map", {
center: [parseFloat(json[0].Lattitude), parseFloat(json[0].Longitude)],
zoom: 9,
type: 'yandex#map',
});
clusterer = new ymaps.Clusterer({
clusterOpenBalloonOnClick: true,
clusterDisableClickZoom: true,
clusterBalloonContentLayoutWidth: 430,
gridSize: 128,
preset: 'islands#invertedGreenClusterIcons' //clusterBalloonContentLayout: 'cluster#balloonCarousel',
});
} else {
clusterer.removeAll();
myGeoObjects = [];
map.geoObjects.removeAll();
}
for (var i = 0; i < json.length; i++) {
myGeoObjects[i] = new ymaps.GeoObject({
geometry: { type: "Point", coordinates: [json[i].Lattitude, json[i].Longitude] },
options: {
iconMaxWidth: 1000,
},
properties: {
clusterCaption: json[i].Title,
balloonContentBody:
"<div class='item bft-object_md'>\
<div class='row'>\
<div class='col-xs-12 col-sm-5'>\
<div class='tail tail_height m-b-10 maw-250'>\
<a href='#' target='_blank'>11\
</a>\
</div>\
</div>\
<div class='omega col-xs-12 col-sm-7'>\
<div class='bft-object__caption bft-object__caption_static p-l-0 p-b-5 p-t-0'>\
<b><a href='#' target='_blank'>"+json[i].Street+"</a></b>\
</div>\
<div class='p-b-5 p-t-0'> " + json[i].House + " </div>\
<div title=\"{7}\">\
<a class='price btn-success btn-sm btn p-r-15 maw-100p' href='#' target='_blank'>\
<span class='item d-i-b'>"+i+"</span>\
<span class='item d-i-b'>\
<span>{5}</span> <br>\
<span class='cashless'> "+json[i].Street+" </span>\
</span>\
</a>\
</div>\
</div>\
</div>\
</div>"
}
}, {
preset: 'islands#greenIcon'
});
}
как произвести сортировку и отобросить точки не входящие в радиус 1 км
var sortedByMapBounds = myGeoObjects.sortByDistance(map);
clusterer.add(sortedByMapBounds);
map.geoObjects.add(clusterer);
map.geoObjects.add(circle);
if (sortedByMapBounds.length > 1) {
map.setBounds(clusterer.getBounds(), {
checkZoomRange: true
});
} else {
map.setZoom(10);
}
}