1.比如一个有三个点的对象
let obj = [[1,1],[2,2],[3,3]];
2.用这三个点的坐标生成一个图层加载到地图上
let features = new Array();
for (let i = 0; i < obj .length; i++) {
let point = new Point([obj [i][0], obj[i][1]]);
features.push(new Feature(point));
}
let source = new VectorSource({
features: features,
});
let vectorLayer = new VectorLayer({
source: source,
style:
function (feature) {
return new Style({
image: new CircleStyle({
radius: 5,
fill: new Fill({//面的填充
color: 'rgba(0, 0, 255)',
}),
stroke: new Stroke({ color: 'red', 1 }),
})
})
}
});
this.map.addLayer(vectorLayer);
3.ol引入:
import Point from 'ol/geom/Point';
import Feature from 'ol/Feature';
import VectorLayer from 'ol/layer/Vector';
import VectorSource from 'ol/source/Vector';
import { Stroke, Style, Icon, Text as TextStyle, Circle as CircleStyle, Fill } from 'ol/style.js';