Search code examples
javafxwebview

Javafx WebView is not able to show pages of geoportal.ch correctly (tested with javafx 22, javafx 17.10)


its not about google maps, all pages containing any kind of map visualisation are not showing these. But how specifically show the content of geoportal.ch? A bunch of pages not working:

geoportal.ch or google maps or openstreetmaps

these pages are not usable as the maps are missing.

Why is it not possible to show a page with maps - specifically geoportal.ch - with Javafx Webview Component? And how to enhance/correct so its works as expected?

My examinations: Other questions answers are saying for the google-maps case they changed their api from a certain javafx version. Well why should they (it was working before...)? If for any reason that was true, why do other pages not showing maps either. SwingNode in combination with jcef does also not work or kept secret.

So in the end it looks like the only solution is to buy proprietary software... whats going wrong here? The web is most crucial - having a half way working Javafx-Webview Component is just strange. That for years. But its not about google maps, its about a immature webview component. Maybe one sees why maps are not showed in general.

I enabled com.sun.webkit.WebPage.level = FINE for logging which does not give me a solution how to solve it.

Demoapplication:

package com.example.webviewsample;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;

public class WebViewSample extends Application {

    @Override
    public void start(Stage primaryStage) {
        WebView webView = new WebView();
        WebEngine webEngine = webView.getEngine();

        TextField urlField = new TextField("https://www.geoportal.ch/ch/map/40?y=2683332.00&x=1247089.90&scale=2000&rotation=0&topic=property&highlight=1&bfsnr=3203&property=W7391");
        Button goButton = new Button("Go");

        goButton.setOnAction(event -> {
            String url = urlField.getText();
            webEngine.load(url);
        });

        BorderPane root = new BorderPane();
        root.setTop(urlField);
        root.setCenter(webView);
        root.setBottom(goButton);

        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.setTitle("WebView Sample");
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Solution

  • It was working with Version JDK8u411 and jfx18 only. So in the end its a bug of the webview component. I fulfilled a bug-report which you can now find officially here:

    https://bugs.java.com/bugdatabase/view_bug?bug_id=JDK-8331640