OpenLayers V3.19.1 doesn't show in JavaFX WebView -
i'm having trouble displaying map openlayers v3 in javafx's webview. here's code:
openlayersv3.html
<!doctype html> <html lang="en"> <head> <link rel="stylesheet" href="https://openlayers.org/en/v3.19.1/css/ol.css" type="text/css"> <style> .map { height: 400px; width: 400px; } </style> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestanimationframe,element.prototype.classlist"></script> <script src="https://openlayers.org/en/v3.19.1/build/ol.js" type="text/javascript"></script> <title>openlayers 3 example</title> <script type="text/javascript"> function loadmap() { var map = new ol.map({ target: 'map', layers: [ new ol.layer.tile({ source: new ol.source.osm() }) ], view: new ol.view({ center: ol.proj.fromlonlat([10.0, 53.55]), zoom: 10 }) }); } </script> </head> <body onload="loadmap()"> <h2>my map</h2> <div id="map" class="map"></div> </body> </html>
and here's excerpt of loader:
osmview.java
... protected webview webview = new webview(); protected webengine webengine = webview.getengine(); public osmview() { final url urlosmmap = getclass().getresource("/some/package/name/openlayersv3.html"); webengine.load(urlosmmap.toexternalform()); getchildren().add(webview); } ...
when load html in browser ie or firefox, shows without complications. in java program, there blank page h2 ("my map"). javascript doesn't load. so, doing wrong here?
ok, found solution: requestanimationframe not found have add following lines before every other javascript stuff:
window.requestanimframe = (function(){ return window.requestanimationframe || window.webkitrequestanimationframe || window.mozrequestanimationframe || window.orequestanimationframe || window.msrequestanimationframe || function(callback, element) { window.settimeout(callback, 1000 / 60); }; })(); var requestanimationframe = window.requestanimframe;
Comments
Post a Comment