views:

95

answers:

1

I am working in Flash Builder 4 with Google Map's ActionScript API. I have created a map, loaded some custom markers onto it and added some MouseEvent listeners to each marker.

The trouble comes when I load an InfoWindow panel. I want to dynamically set the htmlContent based off of information stored in a database. The trouble is that this information can change every couple of seconds and each marker has a unique data set so I can not statically set it at the time I actually create the markers. I have a method that will every minute or so load all of the records from my database into an Object variable. Everything I need to display in the htmlContent is contained in this object under a unique identifier.

The basic crux of the problem is that there is no way for me to uniquely identify an info window, so I can not determine what information to pull into the panel.

marker.addEventListener(MapMouseEvent.ROLL_OVER, function(e:MapMouseEvent):void { showInfoWindow(e.latLng) }, false, 0, false);

That is my mouse event listener. The function I call, "showInfowindow" looks like this:

private function showInfoWindow(latlng:LatLng):void
{
    var options:InfoWindowOptions = new InfoWindowOptions({title: appData[*I NEED A UNIQUE ID HERE!!!*].type + " Summary", contentHTML: appData[*I NEED A UNIQUE ID HERE!!!*].info});
    this.map.openInfoWindow(latlng, options);
}

I thought I was onto something by being able to pass a variable in my event listener declaration, but it simply hates having a dynamic variable passed through, it only returns the last value use.

Example:

marker.addEventListener(MapMouseEvent.ROLL_OVER, function(e:MapMouseEvent):void { showInfoWindow(e.latLng, record.unit_id) }, false, 0, false);

That solution is painfully close to working. I iterate through a loop to create my markers when I try the above solution and roll over a marker I get information, but every marker's information reflects whatever information the last marker created had.

I apologize for the long explaination but I just wanted to make my question as clear as possible. Does anyone have any ideas about how to patch up my almost-there-solution that I posted at the bottom or any from the ground up solutions?

Thanks in advance,

Peter Hanneman

A: 

I created a very ugly workaround for the time being..

Since each marker's longitude & latitude is unique I added a bit of code where the markers get added to the map that created a globally visible associative array that used a hash of the Google Map's API's location object as the key and my unique identifier as the value. Then later when my event listener fired I could extract the location object from the returned event, hash it, perform a lookup in my array and pull the unique id out to pull marker specific information into the InfoWindow.

It works wonderfully, but it leaves me feeling dirty. Please tell me someone has a better solution?

Peter Hanneman