S
S
Sergey Alpeev2014-09-01 16:24:22
JavaScript
Sergey Alpeev, 2014-09-01 16:24:22

How to properly organize js code?

Good afternoon, there is a task to write a script that would collect data after filtering objects from the page and show them as points on the map, + would display some brief information in the balloon on the map, I managed to collect all the addresses, geocode them and display them on the Yandex map in the form tags, here is my code

function init() {
                         var big_Map = false;
                        var myMap = new ymaps.Map('map', {
                                center: [55.666666, 37.788628],
                                zoom: 9,
                                behaviors: ['default', 'scrollZoom']
                            });
                        
                        var massive_adres = $('.coords'); // массив адресов которые в последствии геокодируются и выводятся на карту 
                        var pagetitle = $('.pagetitle'); //массив заголовков 
                       
                    

                        massive_adres.each(function(i){
                                var objects = ymaps.geoQuery(ymaps.geocode($(this).text()))
                                
                                .setOptions({
                                        iconLayout: 'default#image',
                                        iconImageHref: 'main/red_marker.png',
                                        iconImageSize: [20, 35],
                                        iconImageOffset: [-3, -42]
                                        
                                 })
                                 
                                 
                                 
                                 
                                 .setProperties({
                                    balloonContentHeader:'Тест ',
                                    balloonContentBody: 'Тест'
                                 })
                                 
                                .addToMap(myMap); 
                              
                            });


how can I display my title and content for each label instead of "Test" in setProperties , I understand how to get arrays of all titles and all content, but I can't figure out how to display my info for each label, thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-09-01
@QTnub

data-* attributes?

var objects = ymaps.geoQuery(ymaps.geocode($(this).text()))
                                .setOptions({
                                        iconLayout: 'default#image',
                                        iconImageHref: 'main/red_marker.png',
                                        iconImageSize: [20, 35],
                                        iconImageOffset: [-3, -42]     
                                 })
                                 .setProperties({
                                    balloonContentHeader:$(this).data('title'),
                                    balloonContentBody: $(this).data('description')
                                 })

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question