M
M
maxsmart2014-07-28 18:03:24
PHP
maxsmart, 2014-07-28 18:03:24

How to display a list of placemarks on the map?

There is a map with labels. The labels contain the name of the balloon and a description. I want to have a list of these labels with names next to the map. And so that when you click on a label from the list, the balloon of the label itself on the map opens. How can this be implemented?
Here is the code:

<script type="text/javascript">
function init() {
    var myMap = new ymaps.Map('map', {
            center: [55.734046, 37.588628],
            zoom: 9,
            controls: ['zoomControl', 'typeSelector',  'fullscreenControl']
        });
    
    var objects = ymaps.geoQuery()

<?php  

    while (($result = mysql_fetch_array($address))) 
    
    { 
    
      print_r (".add(ymaps.geocode('$result[0]',{results:1}))\n"); 
    
    } 
      
    ?>
    
        .addToMap(myMap);
    
    var balloons = [<?php $myrow = mysql_query("SELECT cartime FROM data WHERE fio='$fio' AND carmodel='$carmodel' AND cardate='$cardate'"); while (($myrowresult = mysql_fetch_array($myrow))) { print_r ("'$myrowresult[0]', "); } ?>], i = 0;
    var balloonsfooter = [<?php $myrow2 = mysql_query("SELECT address FROM data WHERE fio='$fio' AND carmodel='$carmodel' AND cardate='$cardate'"); while (($myrowresult2 = mysql_fetch_array($myrow2))) { print_r ("'$myrowresult2[0]', "); } ?>], i = 0;
    objects.then(function () {
        objects.get(0).balloon.open();
        for(var i = 0, len = objects.getLength(); i < len; i++) {
             objects.get(i).properties.set('iconContent', i + 1, 'results', '1');
             objects.get(i).properties.set('balloonContentBody', balloons[i]);
             objects.get(i).properties.set('balloonContentFooter', balloonsfooter[i]);
             
        }
    });
}

ymaps.ready(init);
</script>

<div id="map"/>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gasoid, 2014-07-29
@Gasoid

you need to use javascript,
and in PHP generate an array for javascript with label parameters
to get the type:
point_array = [{address:"Address1"}, {address:"Address2"}, etc.]
then use either a cluster if there are many labels or add loop through javascript

H
H2Otik, 2014-08-14
@H2Otik

Here is your answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question