P
P
Pavel Busel2014-09-22 20:44:04
JavaScript
Pavel Busel, 2014-09-22 20:44:04

How to properly form a collection of geo objects in ymap?

Task: to form a json array so that it creates collections of geo objects i.e.

var myCollection = new ymaps.GeoObjectCollection(collection, {preset: 'twirl#shopIcon'});

where collection is a geocollection object.
All examples describe that you need to make an empty collection and then push objects, but this option is not to my liking. It would be desirable to push at once in the designer all objects.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Busel, 2014-09-22
@pro100Coder

Found a solution using geoQuery
example:

var result = ymaps.geoQuery({
        type: 'FeatureCollection',
            features: [
                {
                    type: 'Feature',
                    geometry: {
                        type: 'Circle',
                        coordinates: [15, 15],
                        radius: 100
                    }
                },
                {
                    type: 'Feature',
                    geometry: {
                        type: 'LineString',
                        coordinates: 
                    }
                },
                {
                    type: 'FeatureCollection',
                    features: [
                        {
                            type: 'Feature',
                            geometry: {
                                type: 'Point',
                                coordinates: [12, 41]
                            },
                            properties: {
                              name: 'point'
                            },
                            options: {
                                preset: 'islands#yellowIcon'
                            }
                        }
                    ]
                }
            ]
      });

Y
yttrium, 2014-09-22
@yttrium

The first argument is not an array, but a feature. This object has an array children which describes GeoObjects

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question