How to display Loading Icon while rendering Markers on the MAP

前端 未结 1 813
情歌与酒
情歌与酒 2021-01-15 19:40

Rightnow i\'m developing an application where i have to display huge number of markers on the map roughly (30K to 50K).right now while rendering the map it is taking time to

相关标签:
1条回答
  • 2021-01-15 20:36

    Checking if clustering is complete

    You probably want to add an observer to the state property of the cluster provider instead:

    function clusterDataPoints(data) {
      clusterProvider = new nokia.maps.clustering.ClusterProvider(map, {
        eps: 16,
        minPts: 1,
        dataPoints: data
      });
    
      clusterProvider.addObserver("state", 
        function (obj, key, newValue, oldValue) { 
          console.log(newValue);
        }
      );
      clusterProvider.cluster();
    }
    

    The ClusterProvider will change state to STATE_READY whenever clustering is complete.

    Adding a loading icon

    To add a "Loading" icon, you should add a custom map control like this:

    function extend(B, A) {
      function I() {}
      I.prototype = A.prototype;
      B.prototype = new I();
      B.prototype.constructor = B;
    }
    
    function HtmlControl (html, id) {
      nokia.maps.map.component.Component.call(this);
      this.init(html, id);
    }
    
    extend(HtmlControl,
        nokia.maps.map.component.Component);
    
    
    HtmlControl.prototype.init = function (html, id) {
      that = this;
      that.id = id
      that.set('node',  document.createElement('div'));  
      that.node.innerHTML = html;
    };
    
    HtmlControl.prototype.getId = function () { 
      return 'HtmlControl.' + this.id;
    };
    
    HtmlControl.prototype.attach = function (map) {
      map.getUIContainer().appendChild(this.node);
    };
    
    HtmlControl.prototype.detach = function (display) {
      map.getUIContainer().removeChild(this.node);
    };
    

    It can be added to the map like this:

    htmlControl = new HtmlControl(
         '<div class=\'loader\' style=\'width:540px; height:334px; display:block\'></div>', 'Loader');
      map.components.add(htmlControl);
    

    and styled using CSS:

    <style>
      .loader {
        position: relative;
        top:0;
        left:0;
        bottom:0;
        right:0;
        background-color:black;
        background-color: rgba(0,0,0,0.5);
        background-image: url(img/loading.gif);
        background-position: 50% 50%;
        background-repeat: no-repeat;
      }
      </style>
    

    You would then just need to add() or remove() the html control to display the loading gif.

    0 讨论(0)
提交回复
热议问题