作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我在 eclipse 中使用它时,我的 webview 就像魅力一样工作,但是一旦我将应用程序打包到一个 jar 文件中,它就会引发以下错误:
This page contains the following errors:
error on line 33 at column 26: StartTag: invalid element name
Below is a rendering of the page up to the first error.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="EN">
<head>
<style>
html,body {
height: 99%;
width: 99%;
}
#map {
width: 100%;
height: 100%;
border: 1px solid black;
}
</style>
<script src='http://openlayers.org/api/OpenLayers.js'></script>
</head>
<body>
<div id='map'></div>
<script type="text/javascript">
var map = new OpenLayers.Map("map",{projection:"EPSG:3857"});
var toMercator = OpenLayers.Projection.transforms['EPSG:4326']['EPSG:3857'];
var center = toMercator({x:-0.05,y:51.5});
var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);
map.zoomToMaxExtent();
function addPoints(lon,lat,merkm){
var features = [];
for(var i = 0; i < lon.length; i++) {
var center = toMercator({x:lon[i],y:lat[i]});
features[i] = new OpenLayers.Feature.Vector(
toMercator(new OpenLayers.Geometry.Point(
lon[i],
lat[i])),
{
infoitems : merkm[i]
}, {
fillColor : '#008040',
fillOpacity : 0.8,
strokeColor : "#ee9900",
strokeOpacity : 1,
strokeWidth : 1,
pointRadius : 8
});
}
// create the layer with listeners to create and destroy popups
var vector = new OpenLayers.Layer.Vector("Points",{
eventListeners:{
'featureselected':function(evt){
var feature = evt.feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
null,
"<div style='font-size:.8em'>"+feature.attributes.infoitems+"</div>",
null,
true
);
feature.popup = popup;
map.addPopup(popup);
},
'featureunselected':function(evt){
var feature = evt.feature;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
vector.addFeatures(features);
var line = new OpenLayers.Control.DrawFeature(vector,
OpenLayers.Handler.Path);
// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
hover:true,
autoActivate:true
});
// map.destroy();
// map = new OpenLayers.Map("map",{projection:"EPSG:3857"});
// var osm = new OpenLayers.Layer.OSM();
map.addLayer(vector);
map.addControl(selector);
map.addControl(line);
map.setCenter(new OpenLayers.LonLat(center.x,center.y), 13);
}
function pageOnLoad(){
alert();
}
</script>
</body>
</html>
WebView browser = new WebView();
final WebEngine webEngine = browser.getEngine();
String mapfolder = "mapview";
File map = new File(new File("."), "/mapview/mapview.html");
final URL mapUrl = MapTab.class.getResource("mapview.html");
webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<State>() {
public void changed(ObservableValue ov, State oldState, State newState) {
if (newState == State.SUCCEEDED) {
webEngine.executeScript("addPoints("+arg0+","+arg1+","+arg2+")");
}
}
});
webEngine.javaScriptEnabledProperty().set(true);
webEngine.load(mapUrl.toExternalForm());
this.setContent(browser);
最佳答案
当您从 jar 中加载某些内容时,我认为您不能将 File 协议(protocol)与 getResource 协议(protocol)结合使用。我也不认为 jar 协议(protocol)会理解像 .
这样的文件类型说明符。和 ..
.
如果 map html 在 jar 之外的本地文件系统上,则使用 file://
从文件系统加载 map html协议(protocol)。
如果 map html 打包在你的 jar 中 /mapview/mapview.html
下正如我所期望的那样,将其从 jar 中加载出来:
webEngine.load(MapTab.class.getResource("/mapview/mapview.html").toExternalForm());
<!doctype html>
<html lang="en">
<head>
<style>
html,body {
height: 99%;
width: 99%;
}
#map {
width: 100%;
height: 100%;
border: 1px solid black;
}
</style>
<script language="javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script language="javascript" type="text/javascript">
function doload() {
var map = new OpenLayers.Map("map",{projection:"EPSG:3857"});
var toMercator = OpenLayers.Projection.transforms['EPSG:4326']['EPSG:3857'];
var center = toMercator({x:-0.05,y:51.5});
var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);
map.zoomToMaxExtent();
}
function addPoints(lon,lat,merkm){
var features = [];
for(var i = 0; i < lon.length; i++) {
var center = toMercator({x:lon[i],y:lat[i]});
features[i] = new OpenLayers.Feature.Vector(
toMercator(new OpenLayers.Geometry.Point(
lon[i],
lat[i])),
{
infoitems : merkm[i]
}, {
fillColor : '#008040',
fillOpacity : 0.8,
strokeColor : "#ee9900",
strokeOpacity : 1,
strokeWidth : 1,
pointRadius : 8
});
}
// create the layer with listeners to create and destroy popups
var vector = new OpenLayers.Layer.Vector("Points",{
eventListeners:{
'featureselected':function(evt){
var feature = evt.feature;
var popup = new OpenLayers.Popup.FramedCloud("popup",
OpenLayers.LonLat.fromString(feature.geometry.toShortString()),
null,
"<div style='font-size:.8em'>"+feature.attributes.infoitems+"</div>",
null,
true
);
feature.popup = popup;
map.addPopup(popup);
},
'featureunselected':function(evt){
var feature = evt.feature;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
});
vector.addFeatures(features);
var line = new OpenLayers.Control.DrawFeature(vector,
OpenLayers.Handler.Path);
// create the select feature control
var selector = new OpenLayers.Control.SelectFeature(vector,{
hover:true,
autoActivate:true
});
// map.destroy();
// map = new OpenLayers.Map("map",{projection:"EPSG:3857"});
// var osm = new OpenLayers.Layer.OSM();
map.addLayer(vector);
map.addControl(selector);
map.addControl(line);
map.setCenter(new OpenLayers.LonLat(center.x,center.y), 13);
}
function pageOnLoad(){
alert();
}
</script>
</head>
<body onload="doload()">
<div id="map"></div>
</body>
</html>
package javafxsamples;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.web.WebView;
import javafx.stage.Stage;
public class MapViewer extends Application {
public static void main(String[] args) { launch(args); }
@Override public void start(Stage stage) {
WebView webview = new WebView();
webview.getEngine().load(
MapViewer.class.getResource("/mapview/mapview.html").toExternalForm()
);
stage.setScene(new Scene(webview));
stage.show();
}
}
关于webview - 如何在 DesktopApp 中将 JavaFX WebView 与本地文件一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12573406/
当我在 eclipse 中使用它时,我的 webview 就像魅力一样工作,但是一旦我将应用程序打包到一个 jar 文件中,它就会引发以下错误: This page contains the foll
如果能帮助我理解如何在本地桌面应用程序中使用声明,我将不胜感激。这是场景:我想显示一个选项卡 f.e.取决于用户是否有像“AnalysisAllowed:true”这样的声明。所以我想在应用程序启动时
我是一名优秀的程序员,十分优秀!