我要疯了。我试图重现 OpenLayers 2.10 初学者指南中的一个示例,我试图在其中显示保存在 json 文件中的功能并在地图上添加功能,并将它们保存到文件中。
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 文件位于同一文件夹中,我正在服务器上运行我的项目