我是 OL 的初学者,但我需要解决这个问题......我想把这个数组放到我的 map 中。谢谢帮忙!;) 我的数组 ces 的片段:
["1192.4692,1107.0745","1190.5201,1107.0029","1190.5201,1101.8436","1190.5201,1098.0733", "1192.4162,1097.9464"]
var LineSource = new ol.source.Vector({
projection: 'EPSG:3857',
format: new ol.format.Feature(LineFeat)
});
var LineFeat = new ol.Feature( {
name: "krLine",
geometry: new ol.geom.MultiLineString(ces), });
LineSource.addFeature( LineFeat );
var krLineLayer = new ol.layer.Vector({
source: LineSource,
projection: 'EPSG:3857',
});
这是我的地图:
var map = new ol.Map({
layers: [
krLineLayer,
],
target: 'map',
controls: [
new ol.control.ScaleLine(),
new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(3),
})
],
view: mapView
});
这是@Mikelis 的解决方案和一个示例,我如何将线条放入我的地图:
var elem;
var arr2 = [];
for (var i=0; i<ces.length; i++){
elem = ces[i].split(",");
arr2.push([parseFloat(elem[0]), parseFloat(elem[1])]);
}
console.log(arr2);
var layerLines = new ol.layer.Vector({
source: new ol.source.Vector({
features: [new ol.Feature({
geometry: new ol.geom.LineString(arr2),
name: 'Line',
projection: 'EPSG:3857'
})]
}),
});