B
B
busidoway2019-02-15 12:05:39
css
busidoway, 2019-02-15 12:05:39

How to get json data for Yandex Maps during automatic update?

Good afternoon.
Several items (locations) are selected on the main page, and when going to the panel.php page, an array (1,2,3,5,10) of these locations is passed there. Panel.php contains the Yandex map script. Example:

var myMap,
      geoObjects,
      objectManager,
      arr_id = '".$arr_id."',
      arrp = JSON.parse('[' + arr_id + ']');
      
    ymaps.ready(init);
    function init()
    {
      myMap = new ymaps.Map('map', {
          center: [".$last_gps."],
          zoom: 14,
          type: 'yandex#satellite'
        }, {
          searchControlProvider: 'yandex#search'
          
        });
        objectManager = new ymaps.ObjectManager({
          clusterize: true,
          gridSize: 32,
          clusterDisableClickZoom: true
        });
        objectManager.objects.options.set('preset', 'islands#grayDotIcon');
        objectManager.clusters.options.set('preset', 'islands#grayClusterIcons');
        myMap.geoObjects.add(objectManager);
  
        $.ajax({
          url:'panel_json.php',
          type: 'post',
          dataType: 'json',
          data: {arrp:arrp}
        }).done(function(data) {
          objectManager.add(data);
        });
        
        myMap.geoObjects.add(objectManager);
        
    };

Through ajax, the id array is passed to panel_json.php, where a request to the database is made through this array, after which a template is generated in json format and returned to panel.php.
The bottom line is that every 5 seconds the data on the map is updated via setInterval(). If you receive data for the map from panel_json.php, then the data is returned for a long time - about 1-2 seconds. If getting data from json file
url:'json/data.json'
, then it works much faster ~5-10 ms. But the problem is how to save and get the json file? Those. let's say several users came to the site and each one chose some locations for display. It turns out that in each case some separate array with different ids will be transferred, and for each one it will be necessary to form a separate set of json and save it to some separate file. In total, a large pile of generated files on the server.
Maybe someone has experienced something similar? Perhaps there are other solutions.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Alekseev, 2016-08-17
@LoonTiG

$(window).scroll(function () {
    if ($(this).scrollTop() > высота_до_меню) {
      $('.menu').addClass('.fixed');
    } else {
      $('.menu').removeClass('.fixed');
    }
  });

G
GreatRash, 2016-08-17
@GreatRash

It is obvious that initially it is not fixed, and then fixed.

B
busidoway, 2019-02-19
@busidoway

The problem was in connecting to the database + unoptimized sql query. In the connection to the database, instead of "localhost" I specified the IP address of the server (only the connection took ~ 1 sec of time), and split the request to the database to display records into two separate requests. As a result, the page load time dropped to ~10-20 ms.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question