我正在尝试使用 Openlayers 在单个图层上绘制单独的线段。该网站可以在这里看到(点击地图然后放大)。红色框表示包含路段的四叉树。绿线显示为一条折线,我希望将其视为单独的线段。
这是我现有的功能
function DrawSegments(response){
var SegmentsData = eval( '(' + response.responseText + ')' );
var line;
var lineFeature;
if(segmentsLayer)
segmentsLayer.destroy();
segmentsLayer = new OpenLayers.Layer.Vector("Segments");
var points = new Array();
var style = { strokeColor: '#00ff00',
strokeOpacity: 0.8,
strokeWidth: 2
};
map.addLayer(segmentsLayer);
map.addControl(new OpenLayers.Control.DrawFeature(segmentsLayer, OpenLayers.Handler.Path));
//Used this block as code example to possibly add lines using a WKT geometry collection
//var feature = new OpenLayers.Feature.Vector(
//OpenLayers.Geometry.fromWKT(
//"POLYGON((28.828125 0.3515625, 132.1875 -13.0078125, -1.40625 -59.4140625, 28.828125 0.3515625))"
//).transform(WGS,SMP)
//);
//segmentsLayer.addFeatures([feature]);
for (var i = 0; i < SegmentsData.length; i++) {
points.push(new OpenLayers.Geometry.Point(SegmentsData[i][0], SegmentsData[i][1]).transform(WGS,SMP));
points.push(new OpenLayers.Geometry.Point(SegmentsData[i][2], SegmentsData[i][3]).transform(WGS,SMP));
line = new OpenLayers.Geometry.LineString(points);
lineFeature = new OpenLayers.Feature.Vector(line, null, style);
}
segmentsLayer.addFeatures([lineFeature]);
}
我试过了:
寻找例子
OpenLayers.Geometry.MultiLineString
和
OpenLayers.Geometry.Collection
我尝试将 lineFeature var 转换为数组并单独添加每个数组元素,但没有成功。文档对我没有帮助。任何帮助将不胜感激。