leftside是 Google Chrome 中加载的 html页面,右侧是 JavaFx WebView中加载的 html页面 ,问题是Google Map的导航面板没有显示在 JavaFx WebView 中。我正在使用 Java 7u79 。
GoogleMap.java
webView = new WebView();
webEngine = webView.getEngine();
webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>(){
@Override
public void changed(ObservableValue<? extends State> ov, State t, State t1) {
System.out.println("STATE : " + t1);
if(t1.equals(State.SUCCEEDED)){
root.getChildren().remove(indicator);
}
}
});
indicator = new ProgressIndicator();
indicator.setMaxSize(40, 40);
String htmlcode = getFileContent("GoogleMap.html");
webEngine.loadContent(htmlcode);
root = new StackPane();
root.setAlignment(Pos.CENTER);
root.getChildren().add(webView);
root.getChildren().add(indicator);
Scene scene = new Scene(root, 550, 400);
primaryStage.setTitle("Google Map");
primaryStage.setScene(scene);
primaryStage.show();
GoogleMap.html
<!DOCTYPE html>
<html>
<head>
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script>
function initialize() {
var mapProp = {
center : new google.maps.LatLng(51.508742,-0.120850),
zoom : 5,
mapTypeId : google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<style>
body
{
padding : 0;
margin : 0;
}
#googleMap
{
width : 550px;
height : 400px;
}
</style>
</head>
<body>
<div id="googleMap"></div>
</body>
</html>