L
L
Lumore2016-04-08 13:35:34
JavaScript
Lumore, 2016-04-08 13:35:34

How to optimize the output of placemarks on Yandex map?

To display placemarks on the map, I wrote the following code with a loop:

<?php

$js = "
Establishments = new ymaps.GeoObjectCollection();
";

foreach($marksArray as $mark) {
        $js .= "
           Establishments.add(new ymaps.Placemark([".$mark->lat.", ".$mark->lng."], {
            EstablishmentId: ".$mark->id.",
            EstablishmentName: '".$mark->name."'
        }, {
            iconLayout: 'default#image',
            iconImageHref: '".$mark->image."',
            iconImageSize: [32, 32],
            iconImageOffset: [-20, -25]
        }));
            ";
    }

$js .= "
myMap.geoObjects.add(Establishments);
";
$this->registerJs($js);

But if there are hundreds or even thousands of placemarks in the database, then the page will take several years to load, the question is how can this be optimized? I dug into the API, I did not find anything suitable.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cyber_bober, 2016-04-08
@Lumore

https://habrahabr.ru/company/yandex/blog/243665/
There is a clusterer

A
Amir Gafurov, 2016-04-08
@amir73911

Have you looked at the documentation? :)
Sandbox

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question