feature类:用于创建矢量对象
父类:BaseObject
构造函数参数:{Geometry|ObjectWithGeometry<Geometry>}geometryOrProperties,即自定义类型ObjectWithGeometry或者Geometry。
构造实例1:
import Feature from 'ol/Feature';
import Polygon from 'ol/geom/Polygon';
import Point from 'ol/geom/Point';
const feature = new Feature({
geometry: new Polygon(polyCoords),
labelPoint: new Point(labelCoords),
name: 'My Polygon',
});//包含geometry的对象
构造实例2:
const count = 20000;
const features = new Array(count);
const e = 4500000;
for (let i = 0; i < count; ++i) {
const coordinates = [2 * e * Math.random() - e, 2 * e * Math.random() - e];
features[i] = new Feature(new Point(coordinates));
}//随机坐标的点geometry
方法:
setStyle(style) 设置feature的样式以覆盖layer的样式。
事件:
change(BaseEvent) - Generic change event. Triggered when the revision counter is increased.(继承)change:geometry(ObjectEvent)error(BaseEvent) - Generic error event. Triggered when an error occurs.(继承)propertychange(ObjectEvent) - Triggered when a property is changed.(继承)
本文介绍OL库中Feature类的功能及使用方法,包括构造函数参数、构造实例、setStyle方法及触发事件等。通过具体示例展示了如何利用Feature类创建带有不同几何对象的矢量对象。
4359

被折叠的 条评论
为什么被折叠?



