Source
addFeature | 添加要素 |
addFeatures([]) | 传递数据 |
Layer
setSource | 添加数据源 |
<body>
<div id="map">
</div>
<script>
const map = new ol.Map({
target: "map",
layers: [gaode],
view: new ol.View({
center: [114, 30],
zoom: 6,
projection: "EPSG:4326"
})
})
var Point = new ol.Feature({
geometry: new ol.geom.Point([114, 30])
})
var style = new ol.style.Style({
image: new ol.style.Circle({
radius: 20,
fill: new ol.style.Fill({
color: '#ffcc33'
})
})
})
/* addFeature/addFeatures */
var source = new ol.source.Vector({
// features: [Point]
});
// source.addFeature(Point)
source.addFeatures([Point])
var vector = new ol.layer.Vector({
source: source,
// style
});
// console.log(vector)
vector.setStyle(style)
vector.setSource(source);
/* 5、将图层添加到map */
map.addLayer(vector)
/*
layer setSource
source addFeature, addFeatures
*/
</script>
</body>