E
E
e1s2018-03-14 08:42:30
JavaScript
e1s, 2018-03-14 08:42:30

How to show all marks on Yandex map?

The following script is used to load labels

function LoadObjects(myMap) {
            myMap.geoObjects.remove(loadingObjectManager);
            loadingObjectManager = new ymaps.LoadingObjectManager(url + '?bbox=%b',
            {
                clusterize: true,
                clusterHasBalloon: true,
                geoObjectOpenBalloonOnClick: true,
                clusterOpenBalloonOnClick: true
            });
            myMap.geoObjects.add(loadingObjectManager);
        };


Map creation script

ymaps.ready(function () {
        var myMap = new ymaps.Map("map", {
            center: [@centerYandexMap],
            zoom: 12,
            controls: ['fullscreenControl', 'geolocationControl', 'typeSelector', 'zoomControl']
        }, {
            avoidFractionalZoom: false
        });
        if (параметр == 'True') {
            LoadObjects(myMap);
            myMap.setBounds(myMap.geoObjects.getBounds());
        }
        $(window).resize(function () {
            myMap.container.fitToViewport();
        });
        });


Map pins are displayed, but viewable area does not include all points. As I understand the problem in myMap.setBounds(myMap.geoObjects.getBounds()), for some reason myMap.geoObjects.getBounds() returns null, and the expression myMap.setBounds(myMap.geoObjects.getBounds()) itself returns with an error (under the debugger did not manage to get to the moment where the error occurs, but the script following this expression does not work out). What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-03-14
@freeExec

Are you sure that your code is executed sequentially, and not let's say the data is loaded a little late? And don't you have to wait for them to load before working with them.

LoadObjects(myMap);
myMap.setBounds(myMap.geoObjects.getBounds());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question