E
E
exxagw2015-04-20 16:21:27
JavaScript
exxagw, 2015-04-20 16:21:27

How to get the id of the visible points of Yandex maps?

how to get the id of the points that fell into the scope when dragging/zooming the map?

var placemark = [];

$.getJSON(document.location.pathname+"results.json", function(data) {
for (var i in data) {
var company = data[i];
placemark[company.id] = new ymaps.Placemark(company['tv.coords'].split(','), {
preset: 'islands#redIcon'
}
);
clusterer.add(placemark[company.id]);
}
});
map.geoObjects.add(clusterer);

this is how the points are generated. placemark[company.id] for example the 55th point.

and at the same time I wonder if it is possible to get the points that have disappeared?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hOtRush, 2015-04-30
@hOtRush

As far as I know, it's not possible. you need to explicitly iterate over the points and compare the coordinates with the boundaries of the map. although, as for me, the method is very in demand and it is strange that it is not in the api

this.checkVisibleOrCenter = function(placemark) {

        var placeMarkCoordinates = placemark.geometry.getCoordinates(),
            mapBounds = this.mapObject.getBounds(),
            mapBotLeft = mapBounds[0],
            mapTopRight = mapBounds[1];

        if (
            placeMarkCoordinates[0] < mapBotLeft[0]
            ||
            placeMarkCoordinates[0] > mapTopRight[0]
            ||
            placeMarkCoordinates[1] < mapBotLeft[1]
            ||
            placeMarkCoordinates[1] > mapTopRight[1]
        ) {

            // placemark not visible, set map center to it

            this.mapObject.setCenter(placeMarkCoordinates);

        }

    };

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question