您好,我正在使用以下代码从我的 java 服务器应用程序加载 geoJson 文件。它没有问题,我可以在openlayers中将geojson显示为矢量图层。但是在服务器端,我还将一些参数保存到我想稍后在客户端 javaScript 端读取的 geoJson 文件中(例如路径的总长度和路径的总时间。)我不知道如何访问它们.
这就是我所拥有的,并且有效的方法:
layer = new OpenLayers.Layer.Vector("Path", {
style: style,
strategies: [new OpenLayers.Strategy.Fixed()],
projection: geographic,
protocol: new OpenLayers.Protocol.HTTP({
url: "webresources/getJosmAspects?startLon=" + document.getElementById('startLon').value +
"&startLat=" + document.getElementById('startLat').value +
"&endLon=" + document.getElementById('endLon').value +
"&endLat=" + document.getElementById('endLat').value +
"&avgSpeed=" + document.getElementById('avgSpeed').value +
"&speedWeight=" + document.getElementById('speedInput').value +
"&comfortWeight=" + document.getElementById('comfortInput').value +
"&quietnessWeight=" + document.getElementById('quietInput').value +
"&avgSpeedWeight=" + document.getElementById('shortestInput').value,
format: new OpenLayers.Format.GeoJSON()
})
});
我想从响应中获取一些参数而不再次调用它。来自服务器的 geojson 看起来像
{"type":"Feature","geometry":{"type":"LineString","coordinates":[[14.420414,50.07352]......,[14.38296,50.077154],[14.382867,50.077228]]},"properties":{"total_length":3603.656606483625,"total_time":782.4648477846279,"total_elevationGain":130.9226633310318,"total_elevationDrop":-48.82620286941528}}