문제

I have an Openlayers3 map with a lot of markers and I would like to handle it more efficiently.

I saw there was a cluster method on the last version of Openlayers and I would like to use the same thing on the third version : http://openlayers.org/dev/examples/strategy-cluster.html

Do I have to use vectors ?

Here is my current code :

$.getJSON( "http://localhost/folder/address.json", function(data){

     for(var k in data) {

      var companyCity = data[k].city;
      var companyName = data[k].company;
      var companyLocation = data[k].address;
      var companyLat = data[k].lat;
      var companyLng = data[k].lng;
      var companyPosition = transform([companyLng,companyLat]);

       var elt = $('<p title="'+ companyName +': '+ companyLocation +', '+ companyCity +'"></p>').css({

        "width": '5px',
        "height": '5px',
        "border-radius": '50%',
        "background-color": '#E64411',
        "opacity" : '.5'

       });



       var marker = new ol.Overlay({
        map: map,
        position: companyPosition,
        element: elt
       });


    }
  });

Someone has already done it ?

도움이 되었습니까?

해결책

I know this post is old but there is a Clustering example now.

다른 팁

The cluster strategy does rely on having the markers added to a layer. Is there a strong reason not to do this? If you were able to have the address.json stored as geoJSON, it is far more "automatic" to use a layer.

If there are strong reasons to not use a layer, you could grab the filter strategy code and customize it to work without a layer. Looking at OpenLayers.Strategy.Cluster on GitHub, it looks like you would simply need to manually set features to the array of features you have created and then call cluster() at appropriate times.

As of of 14.11.2013 clustering was not yet available in OpenLayers 3. https://groups.google.com/forum/#!topic/ol3-dev/UDjoZSX3Wx4

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top