我要瘋了。我試圖從OpenLayers 2.10初學者指南中重現一個例子,我試圖展示保存在json文件中的功能並在地圖上添加功能,並將它們保存到文件中。讀取和保存文件的功能 - OpenLayers
var map;
function init(){
map = new OpenLayers.Map('map');
var options = {numZoomLevels: 3}
var floorplan = new OpenLayers.Layer.Image(
'Floorplan Map',
'temp_photos/sample-floor-plan.jpg',
new OpenLayers.Bounds(-180, -88.759, 180, 88.759),
new OpenLayers.Size(580, 288),
options
);
var roomPolygonLayer = new OpenLayers.Layer.Vector('Rooms', {
protocol: new OpenLayers.Protocol.HTTP({
url: "myFloorPlanData.json",
format: new OpenLayers.Format.GeoJSON({})}),
strategies: [new OpenLayers.Strategy.Fixed(), new OpenLayers.Strategy.Save()]
});
map.addLayers([floorplan, roomPolygonLayer]);
map.zoomToMaxExtent();
map.addControl(new OpenLayers.Control.EditingToolbar(roomPolygonLayer));
map.layers[1].onFeatureInsert = function(feature){
alert("feature id: "+feature.id);
alert("feature geometry: "+ feature.geometry);
};
}
到目前爲止,我的地圖顯示,我可以在地圖上繪製矢量,但它拒絕顯示兩點我已經在我的JSON文件,並保存新的點,我得出:
{
"type": "FeatureCollection",
"features": [
{"type":"Feature","properties":{}, "geometry":{"type":"Point", "coordinates":[5, 63]}},
{"type":"Feature","properties":{}, "geometry":{"type":"Point", "coordinates":[-48, 27]}}
]
}
JSON文件是在同一文件夾作爲我的jsp文件,我跑我的項目在服務器上
嘗試用'OpenLayers.Format.GeoJSON({})'替換這個'新的OpenLayers.Format.GeoJSON()' – capdragon
我刪除了編輯工具欄並正確顯示了點...我假設你不能使用相同的矢量圖層顯示點和繪製點。但是,我仍然在努力保存我正在繪製的新功能,一旦我得到它的工作,我會在這裏發佈答案。我正在玩這個例子:http://openlayers.org/dev/examples/vector-formats.html –