调用Vector Layer的addFeatures方法可以在Vector Layer上添加新Feature
1. 定义WKT Geometry
var wkt = "POLYGON((0 0,0 90,180 90,180 0,0 0))”;
2. 创建Vector图层
var vlayer = new OpenLayers.Layer.Vector("Vector Layer");
map.addLayer(vlayer);
3. 创建Geometry
var wkt_c = new OpenLayers.Format.WKT();
var geometry = wkt_c.read(wkt);
4.将geometry添加到vlayer上
vlayer.addFeatures(geometry);
完整代码
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2 <HTML> 3 <HEAD> 4 <TITLE> OpenLayers : Add Feature </TITLE> 5 <link rel="stylesheet" href="./OpenLayers-2.10/theme/default/style.css" type