M
M
Maxim Nikitin2014-10-22 20:02:50
JavaScript
Maxim Nikitin, 2014-10-22 20:02:50

Why is it not possible to add multiple collections to ymaps.GeoObjectCollection?

There is a problem: only the last recorded collection is shown on the map.

ymaps.ready(init);
        var myMap;
        function init() {
            myMap = new ymaps.Map("map", {
                center: [53.901, 27.5601],
                zoom: 11,
                behaviors: ['default', 'scrollZoom']
            });
            myMap.controls.add('typeSelector');
            myMap.controls.add('zoomControl');
            myMap.controls.add('searchControl');
            var geoObjects = new ymaps.GeoObjectCollection();
            geoObjects.add(GetMetalPoints());
            geoObjects.add(GetLightPoints());
            myMap.geoObjects.add(geoObjects);
        }

GetMetalPoints() and GetLightPoints() return GeoObjectCollections;
Only the latest added collection is shown on the map. If you comment out geoObjects.add(GetLightPoints()), then GetMetalPoints() will be displayed.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sydorenko, 2014-10-23
@MaxSter

Hello!
just try

...
myMap.controls.add('typeSelector');
myMap.controls.add('zoomControl');
myMap.controls.add('searchControl');
myMap.geoObjects.add(GetMetalPoints());
myMap.geoObjects.add(GetLightPoints());
...

But I would also like to look at the implementation of GetMetalPoints() and GetLightPoints() .. it seems that you use the same global variable in them to store a collection of geo objects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question