绘制多线几何

创建一个矢量源

var vectorSource = new ol.source.Vector({});

启动地图对象并将矢量图层添加到地图,将 Source 添加为 vectorSource

var map = new ol.Map({
  layers: [
      new ol.layer.Tile({
      source: new ol.source.OSM()
      }),
      new ol.layer.Vector({
          source: vectorSource
      })
  ],
  target: 'map',
  view: new ol.View({
    center: [45, 5],
    zoom:5
  })
});

将投影从源投影系统转换为目标项目系统

var points=[];
for (i = 0; i < 10; i++) { 
    var xx = Math.random() * (xmax - xmin) + xmin;
    var yy = Math.random() * (ymax - ymin) + ymin;
    points.push(ol.proj.transform([xx,yy],'EPSG:4326', 'EPSG:3857'));
}

将点传递给 ol.geom.MultiLineString([])构造函数

var thing = new ol.geom.MultiLineString([points1]);

创建一个特征并添加几何图形

var featurething = new ol.Feature({
    name: "Thing",
    geometry: thing,
    style : new ol.style.Style({
      stroke : new ol.style.Stroke({
        color : 'red'
      })
    })
});

最后将其添加到源代码

vectorSource.addFeature( featurething );

注意:放置适当的源和目标投影系统非常重要