Recursive method annoyance


So I’ve been working on incarnations of a mapping application over the last year or so and am rather happy with how it’s been growing so far but one thing has come to my attention. 

The map pulls in hotel properties and displays them as markers on the map depending on the x and y values that I get returned back to me via a service I call. Everything is fine for, say, 84, properties. But pulling 159 properties becomes a task for the map to handle. Basically it stems down to the method I’ve implemented for clustering markers. If a marker is touching another marker it should gather the data from both of the markers, likewise, if that marker is touching a different maker then all 3 have the collection of data from all three. Once a click is done on any one of those markers it then displays all of the markers data that are overlapped. 

The method I have that does this determines based on an array of items that are touching each other, goes through the array and cancels out if it is in the markers’ neighbors array. Otherwise it loops through that neighbor array and adds itself to the neighbor array. 

Earlier I said it was fine with 84 but a nightmare with 159, but that’s not entirely true. It’s really based on how many items are overlapping each other. So I suppose this would be a issue if there were 84 markers overlapping each other in one big cluster as well.

Here is the code to give you a better idea.

public function addNeighbor(item:CityOnMap):void
{
	var hasItem:Boolean = false;
	var i:int = 0;
	var itemNeighborsLength:int;
	var neighborsArrLength:int = neighbors.length;
	
	for each (var name:CityOnMap in neighbors)
	{
		if(name == item)hasItem = true;
	}
	
	if(!hasItem)
	{
		neighbors.push(item)
		itemNeighborsLength = item.neighbors.length;
		item.addNeighbor(this);
		
		while(i

I'll be doing more research and post an update to this issue I'm having. Hopefully someone can shed some light on a different methodology to use. ugh. I just need another set of eyes...


Leave a Reply