Adding custom info windows to Google Maps in Flex

August 20th, 2008 · 6 Comments

I just tried to create a custom info window for a Google Map using the Google Maps API For Flash. Unfortunately it does not seem to work as expected by setting the customContent property in an object of type InfoWindowOptions. Therefore I wrote this little workaround that creates a popup window:

private function createInfoWindow(map:Map, marker:Marker, infoWindow:Class):IFlexDisplayObject {
  var popup:IFlexDisplayObject = PopUpManager.createPopUp(map, infoWindow);
  var globalPos:Point = map.localToGlobal(map.fromLatLngToViewport(marker.getLatLng()));
  popup.move(globalPos.x - popup.width/2, globalPos.y - popup.height - marker.getDisplayObject().height);
  return popup;
}
Social Bookmark
  • Digg
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • MisterWong.DE
  • Technorati
  • Webnews.de

Topics: · , , ,

6 responses so far ↓

  • 1   Stefan Löhr // 2008-08-21 at 5.04 pm

    Hallo,

    ich habe auch gerade angefangen mich mit der Google Maps Flash API zu beschäftigen.
    Leider habe ich von AS bisher nicht besonders viel Ahnung.
    Deshalb kapiere ich nicht ganz wie ich den Workaround einsetzen kann.
    Soll der Click-Event Handler des Markers die Funktion aufrufen? Oder soll sie schon beim Erstellen des Markers ausgeführt werden?
    Haben Sie vielleicht ein kleines Beispielscript mit den Zusammenhängen?

    Für etwas Hilfe wäre ich sehr dankbar.

    Schönen Tag,
    Stefan Löhr

  • 2   admin // 2008-08-22 at 12.32 am

    ja, definitiv im Event-Handler – die Funktion zeigt schliesslich das Popup-Fenster an.
    Beispiel:
    marker.addEventListener(MapMouseEvent.CLICK,
    function(event:MapMouseEvent):void {
    createInfoWindow(map, marker, ExampleInfoWindow)
    }
    );

    ExampleInfoWindow ist dann die anzuzeigende MXML-Komponente (es muss also eine Datei ExampleInfoWindow.mxml existieren)

  • 3   Elton Bicalho do Carmo // 2008-08-22 at 5.31 am

    Hi Marcus,

    well done. This code will help so much.

    Thanks for sharing your talent.

  • 4   Florian.S // 2008-09-25 at 11.14 pm

    Hi Markus – viele Dank! Aber wie werde ich das Popup wieder los? ;)

    Beste Grüße, Florian

  • 5   Marcus Schiesser // 2008-09-29 at 8.29 pm

    Hi Florian,
    schau dir mal meine Flex API an (http://www.marcusschiesser.de/?p=77), da gibt es ein closeFlexInfoWindow Methode

  • 6   Masha // 2008-11-06 at 12.07 am

    It is beautifully turned out .. I liked ..) would be continuously zahazhivat to you.

Leave a Comment