package com.lynden.example.directions; import com.lynden.gmapsfx.GoogleMapView; import com.lynden.gmapsfx.MapComponentInitializedListener; import com.lynden.gmapsfx.javascript.object.*; import com.lynden.gmapsfx.service.directions.*; import java.net.URL; import java.util.ResourceBundle; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.Initializable; import javafx.scene.control.TextField; public class DirectionsFXMLController implements Initializable, MapComponentInitializedListener, DirectionsServiceCallback { protected DirectionsService directionsService; protected DirectionsPane directionsPane; protected StringProperty from = new SimpleStringProperty(); protected StringProperty to = new SimpleStringProperty(); protected DirectionsRenderer directionsRenderer = null; @FXML protected GoogleMapView mapView; @FXML protected TextField fromTextField; @FXML protected TextField toTextField; @FXML private void toTextFieldAction(ActionEvent event) { DirectionsRequest request = new DirectionsRequest(from.get(), to.get(), TravelModes.DRIVING); directionsRenderer = new DirectionsRenderer(true, mapView.getMap(), directionsPane); directionsService.getRoute(request, this, directionsRenderer); } @FXML private void clearDirections(ActionEvent event) { directionsRenderer.clearDirections(); } @Override public void directionsReceived(DirectionsResult results, DirectionStatus status) { } @Override public void initialize(URL url, ResourceBundle rb) { mapView.addMapInializedListener(this); to.bindBidirectional(toTextField.textProperty()); from.bindBidirectional(fromTextField.textProperty()); } @Override public void mapInitialized() { MapOptions options = new MapOptions(); options.center(new LatLong(47.606189, -122.335842)) .zoomControl(true) .zoom(12) .overviewMapControl(false) .mapType(MapTypeIdEnum.ROADMAP); GoogleMap map = mapView.createMap(options); directionsService = new DirectionsService(); directionsPane = mapView.getDirec(); } }