none
Bing map v7 clustering question RRS feed

  • Question

  • Hi,

    We have developed one application using clustering module of v7. It is working fine but we have one issue with it.

    Here is our scenario previously we used the EntityCollection to plot map and hide/show pushpin based on entitycollection name. For example we have 3 entitycollection plotted on map 1 for Redmond ,2 for New York and  3 for Kansas and based on this we hide/show pushpin. Now we have using clustering module so we are difficult to handle this situation.

    Below is the code line we used to hide the pushpin layer without clustering. 

     mapLayerCollection["maplayer" + selectedLegend.Label].setOptions({ visible: false });

    Is there any way in clustering module to plot based on EntityCollection and find particular collection based on name within cluster similar to shown in above code.

    Any one have suggestion on this.

    Thanks!

    Balasaheb 

     

    Balasaheb

    Friday, April 29, 2016 3:47 PM

Answers

  • No. The Clustering layer only supports pushpins, not layers of pushpins. Note that you can have multiple clustering layers. Take a look at the FeaturesExample.html file that came with the clustering module for V7. It shows multiple clustering layers on the map.

    [Blog] [twitter] [LinkedIn]

    Friday, April 29, 2016 4:49 PM
  • If using the V7 clustering module, you can then customize the code anyway you want since it is open source.

    For your first requirement you can update the SetData function to do a check to see if the amount of data being passed in meets your requirement, if not, then disable clustering. Here is a simple if statement that you can add to that function:

    if(data.length <= 5){
    	_options.clusteringEnabled = false;
    } else {
    	_options.clusteringEnabled = true;
    }

    For your second requirement, you can do this already without changing the module. Simply add a click event to the cluster using the optional callback function. This callback function receives two values, an array of the data in the cluster, and a coordinate for the cluster. Loop through the array and create an array of Location objects. Pass this Location array into the LocationRect.fromLocations function to generate a bounding box. On the clustered pushpin do something like pin.metadata = {clusterBounds : bounds }; where bounds is the generated LocationRect. When the cluster is clicked, you can get to this value from the event by doing e.target.metadata. Use this to set the map view. You will also want to add a padding since this won't take into consideration the size of the pushpin icon. Here is a code sample:

    function createClusteredPin(cluster, latlong) {
    	var pin = new Microsoft.Maps.Pushpin(latlong); 
    
    	var locs = [];
    	
    	for(var i=0;i< cluster.length;i++){
    		locs.push(cluster[i]._LatLong);
    	}
    	
    	pin.metadata = {
    		clusterBounds: Microsoft.Maps.LocationRect.fromLocations(locs);
    	};
    
    	Microsoft.Maps.Events.addHandler(pin, 'click', function(e){
    		map.setView({ bounds: e.target.metadata.clusterBounds, padding: 100 });
    	});
    
    	return pin;
    }
    Now, this will not guarantee that all pushpins will be displayed unclustered. This will simply zoom into cluster and break it down. It is highly possible that there will be sub-clusters still, especially if two locations are really close to each other. In the click event handler you could update the cluster layer options to disable clustering so that you see the individual pushpins, but then you would need to decide on how you want to re-enable it. Another option is to set a zoom level limit to the cluster layer. Say when the zoom level is greater than 15, disable clustering. You could do this fairly easy by updating the cluster function in the module.


    [Blog] [twitter] [LinkedIn]

    Thursday, May 19, 2016 4:34 PM

All replies

  • No. The Clustering layer only supports pushpins, not layers of pushpins. Note that you can have multiple clustering layers. Take a look at the FeaturesExample.html file that came with the clustering module for V7. It shows multiple clustering layers on the map.

    [Blog] [twitter] [LinkedIn]

    Friday, April 29, 2016 4:49 PM
  • Hi Ricky,

    We are using Clustering module of V7. It is working but is some case we want following to happed

    1. Do not create cluster when there are small number of pushpin i.e. 5 or 10.

    2. When we clicks on any cluster then it zoom out to Indivisual pushpin level.

    Can you please let us know your response for above our questions.

    Waiting for your reply.

    Thanks!

    Balasaheb 



    Balasaheb

    Monday, May 16, 2016 1:20 PM
  • If using the V7 clustering module, you can then customize the code anyway you want since it is open source.

    For your first requirement you can update the SetData function to do a check to see if the amount of data being passed in meets your requirement, if not, then disable clustering. Here is a simple if statement that you can add to that function:

    if(data.length <= 5){
    	_options.clusteringEnabled = false;
    } else {
    	_options.clusteringEnabled = true;
    }

    For your second requirement, you can do this already without changing the module. Simply add a click event to the cluster using the optional callback function. This callback function receives two values, an array of the data in the cluster, and a coordinate for the cluster. Loop through the array and create an array of Location objects. Pass this Location array into the LocationRect.fromLocations function to generate a bounding box. On the clustered pushpin do something like pin.metadata = {clusterBounds : bounds }; where bounds is the generated LocationRect. When the cluster is clicked, you can get to this value from the event by doing e.target.metadata. Use this to set the map view. You will also want to add a padding since this won't take into consideration the size of the pushpin icon. Here is a code sample:

    function createClusteredPin(cluster, latlong) {
    	var pin = new Microsoft.Maps.Pushpin(latlong); 
    
    	var locs = [];
    	
    	for(var i=0;i< cluster.length;i++){
    		locs.push(cluster[i]._LatLong);
    	}
    	
    	pin.metadata = {
    		clusterBounds: Microsoft.Maps.LocationRect.fromLocations(locs);
    	};
    
    	Microsoft.Maps.Events.addHandler(pin, 'click', function(e){
    		map.setView({ bounds: e.target.metadata.clusterBounds, padding: 100 });
    	});
    
    	return pin;
    }
    Now, this will not guarantee that all pushpins will be displayed unclustered. This will simply zoom into cluster and break it down. It is highly possible that there will be sub-clusters still, especially if two locations are really close to each other. In the click event handler you could update the cluster layer options to disable clustering so that you see the individual pushpins, but then you would need to decide on how you want to re-enable it. Another option is to set a zoom level limit to the cluster layer. Say when the zoom level is greater than 15, disable clustering. You could do this fairly easy by updating the cluster function in the module.


    [Blog] [twitter] [LinkedIn]

    Thursday, May 19, 2016 4:34 PM