Append the data that is shown within the InfoWindow via Ajax

Home Forums MapPress Support Append the data that is shown within the InfoWindow via Ajax

Tagged: , ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #14205
    grego3781
    Participant

    I’m looking to append the data that is shown within the InfoWindow via Ajax.

    For example, my current POI statement is:

    $mypoi_1 = new Mappress_Poi(array(“iconid” => “blue-dot”, “title” => “my home”, “body” => “<div id = ‘top’>top data</div><div id = ‘bottom’></div>”, “point” => array(“lat” => -25.363882, “lng” => 131.044922, “postid” =>”12CnRs34″)));

    I’d like to trigger an Ajax call to populate the “#bottom” div when the icon/link is clicked to show the InfoWindow all the while passing the “postid” value to the Ajax call.

    Any direction is greatly appreciated.

    Thanks

    #14210
    Chris
    Keymaster

    Hi,

    I don’t really know how to do that – it’s not something the plugin is set up to do – so I can only give you some ideas / suggestions:

    First, if possible, it would be much easier to just populate #bottom when you create the POI rather than using AJAX.

    If you do need AJAX, you might try catching the ‘domready’ event that occurs when an infoWindow is opened. The MapPress map ojbect has a name. By default the maps on a page are named ‘mapp0’, ‘mapp1’, etc. You can use ‘name=”myname”‘ in the shortcode to specify a name.

    With the map object, you can get the infowindow by calling getInfoWindow:
    mapp0.getInfoWindow()

    Then you can use the google event ‘domready’ to know when the window is opened. When that event occurs, you can make the AJAX call and replace the infoWindow contents. Below is some pseudo-code to illustrate the idea:

    var iw = mapp0.getInfoWindow();
    google.maps.event.addListenerOnce(iw, "domready", function() {
      .. your AJAX code here ..
      iw.setContent(newContent);
    });
    

    There is no event before the infoWindow is opened, so the infoWindow will show without the content and then resize with the new content after the AJAX call.

    #14211
    grego3781
    Participant

    Hi Chris,

    Thanks for the info!

    I’ll give this a shot and will let you know how it goes.

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.