【发布时间】:2012-05-23 18:44:36
【问题描述】:
我快疯了。我试图重现 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 文件在同一个文件夹中,我正在服务器上运行我的项目
【问题讨论】:
-
尝试用这个
new OpenLayers.Format.GeoJSON()替换new OpenLayers.Format.GeoJSON({}) -
我删除了编辑工具栏和点显示正确...我假设你不能使用相同的矢量图层来显示点和绘制点。但是我仍在努力保存我正在绘制的新功能,一旦我开始工作,我会在这里发布答案。我现在正在玩这个例子:openlayers.org/dev/examples/vector-formats.html
标签: serialization deserialization openlayers