我知道这听起来有点奇怪,但情况就是这样……我有一个 JSF 表单,它在底部加载一个“图像查看器”,纯粹用 javascript 实现:
...
<p:fieldset legend="Viewer">
<p:outputPanel layout="block" styleClass="imageEditorImagePanel" />
</p:fieldset>
...
以及加载图像编辑器(OpenLayers)的 javascript 代码:
...
function setImageEditorHeight(){
imageEditorID = $(".imageEditorImagePanel")[0].id;
....
}
...
function initialiseMap(){
...
map = new OpenLayers.Map(imageEditorID, options);
...
imageLayer = new OpenLayers.Layer.TMS(imgURL, "", {
url : '',
serviceVersion : '.',
layername : '.',
alpha : true,
type : 'png',
getURL : overlay_getTileURL,
transitionEffect: 'resize'
});
map.addLayer(imageLayer);
var vlayer = new OpenLayers.Layer.Vector("Editable");
map.addLayer(vlayer);
//add controls for drawing shaped on the map like:
var drawPointControl = new OpenLayers.Control.DrawFeatureOpt(vlayer, OpenLayers.Handler.Point,
{title:'Draw a point', text: 'Point','displayClass':'olControlDrawFeaturePoint'});
...
//add a save button to store shapes as geoJSON object
var save = new OpenLayers.Control.Button({
title: 'Save', text: 'Save',
trigger: function(){
var GEOJSON_PARSER = new OpenLayers.Format.GeoJSON();
var vectorLayerAsJson = GEOJSON_PARSER.write(vlayer.features);
alert(vectorLayerAsJson);
//i want something similar
//just for demonstrating, instead of URL i would like a way to post JSON object to bean
jQuery.ajax({
type: 'POST',
url: '/ajax/add',
dataType: 'json',
data: {"vLayerAsJson": vectorLayerAsJson}
});
}, 'displayClass': "olControlSaveFeatures"
});
...
panel.addControls([hand, zoomToDrawControl, drawPointControl, drawPathControl, drawPolygonControl, drawRegularPolygonControl,
new OpenLayers.Control.ZoomToMaxExtent({title:"Zoom to the max extent", text: "World"}), modifyFeatureControl, deleteFeatureControl, save]);
...
map.addControl(panel);
...
最后,当我按下 javascript“保存”按钮时,我想以某种方式在我的支持 bean 中提交这个 JSON 对象......特别是我想调用一个 bean 方法来处理 JSON 对象并将其存储为 XML。
有任何想法吗?