title: JavaFX - displaying alert or dialog after javascript code completes (GMapsFX, WebView)
body: <p>In my JavaFX application I'm using GMapsFX to do route finding and visualizations. For the visualization, I simply use a timeout in Javascript and display markers on the map with delay. What I'm having trouble doing is displaying a dialog (or js alert) after the visualization ends telling information about the search (number of nodes visited, I have this available in both my java and js code). Is there a simple way to do this?</p>
  
  <p>GMapsFX package :
  <a href="http://rterp.github.io/GMapsFX/" rel="nofollow">http://rterp.github.io/GMapsFX/</a></p>
  
  <pre><code>public void startVisualization() {
  
          LatLongBounds bounds = new LatLongBounds();
          List&lt;LatLong&gt; latLongs = new ArrayList&lt;LatLong&gt;();
          JavascriptArray jsArray = new JavascriptArray();
          manager.hideIntermediateMarkers();
          manager.hideDestinationMarker();
  
          // create Markers
          for(geography.GeographicPoint point : points) {
              LatLong ll = new LatLong(point.getX(), point.getY());
              MarkerOptions options = MarkerManager.createDefaultOptions(ll);
              Marker newMarker = new Marker(options);
              jsArray.push(newMarker);
              markerList.add(newMarker);
              bounds.extend(ll);
          }
  
          // fit map bounds to visualization
          manager.getMap().fitBounds(bounds);
  
          // get javascript runtime and execute animation
          runtime = JavascriptRuntime.getInstance();
          String command = runtime.getFunction("visualizeSearch", manager.getMap(), jsArray);
          System.out.println(command);
  
          runtime.execute(command);
  
  //      MapApp.showInfoAlert("Nodes visited :"  , latLongs.size() +" nodes were visited in the search");
          manager.disableVisButton(true);
  //        manager.disableRouteButtons(false);
  }
  </code></pre>
  
  <p><br></p>
  
  <pre><code>var delay = 300;
  var map, markers;
  var markerURL = "http://maps.google.com/mapfiles/kml/paddle/red-diamond-lv.png";
  var destURL = "http://maps.google.com/mapfiles/kml/pal2/icon5.png";
  
  function visualizeSearch(mapParam, markersParam) {
      markers = markersParam;
      map = mapParam; 
      drop();
  }
  
  function displayMarker(marker, timeout, URL) {
      window.setTimeout(function() {
          marker.setIcon(URL);
          marker.setMap(map);
      }, timeout);
  }
  
  function drop() {
      var i;
      for(i = 1; i &lt; markers.length - 1; ++i) {
          displayMarker(markers[i], i*delay, markerURL);
      }
      displayMarker(markers[markers.length - 1], i*delay, destURL)
  }
  </code></pre>