Appearance
添加
add(geojson: Object) => Array<string> 此方法采用 GeoJSON Feature、FeatureCollection 或 Geometry 并将其添加到 Draw。它返回一个 id 数组,用于与添加的功能进行交互。如果某个要素没有自己的 ID,则会自动生成一个。
支持的 GeoJSON 要素类型支持:Point、LineString、Polygon、
如果您的add()某个功能的 id 已在存在,则自动更新。
javascript
var feature = { type: 'Point', coordinates: [0, 0] }
var featureIds = draw.add(feature)
console.log(featureIds)
//=> ['some-random-string']具有指定功能 ID 的示例:
javascript
var feature = {
id: 'unique-id',
type: 'Feature',
properties: {},
geometry: { type: 'Point', coordinates: [0, 0] },
}
var featureIds = draw.add(feature)
console.log(featureIds)
//=> ['unique-id']获取
get(featureId: string): ?Feature 返回具有指定 id 的 Draw 中的 GeoJSON 特征,或者undefined如果 id 不匹配任何特征。
javascript
var featureIds = draw.add({ type: 'Point', coordinates: [0, 0] })
var pointId = featureIds[0]
console.log(draw.get(pointId))
//=> { type: 'Feature', geometry: { type: 'Point', coordinates: [0, 0] } }获取指定点位下 所有要素
getFeatureIdsAt(point: { x: number, y: number }): Array<string> 返回当前在指定点呈现的要素的要素 ID 数组。
请注意,point参数需要x,y来自屏幕坐标系,而不是经度、纬度坐标。
javascript
var featureIds = Draw.getFeatureIdsAt({ x: 20, y: 20 })
console.log(featureIds)
//=> ['top-feature-at-20-20', 'another-feature-at-20-20']获取选定的所有要素
getSelected(): FeatureCollection 返回当前选定的所有要素的 FeatureCollection。
获取所有要素
getAll(): FeatureCollection 返回所有要素的 FeatureCollection
javascript
draw.add({ type: 'Point', coordinates: [0, 0] })
draw.add({ type: 'Point', coordinates: [1, 1] })
draw.add({ type: 'Point', coordinates: [2, 2] })
console.log(draw.getAll())
// => {
// type: 'FeatureCollection',
// features: [
// {
// id: 'random-0'
// type: 'Feature',
// geometry: {
// type: 'Point',
// coordinates: [0, 0]
// }
// },
// {
// id: 'random-1'
// type: 'Feature',
// geometry: {
// type: 'Point',
// coordinates: [1, 1]
// }
// },
// {
// id: 'random-2'
// type: 'Feature',
// geometry: {
// type: 'Point',
// coordinates: [2, 2]
// }
// }
// ]
// }删除指定ID要素
delete(ids: string | Array<string>): draw 删除具有指定 ID 的功能。返回用于链接的绘制实例。 在direct_select模式中,删除活动功能将退出该模式并恢复到该simple_select模式。
javascript
var feature = { type: 'Point', coordinates: [0, 0] }
var ids = draw.add(feature)
draw.delete(ids).getAll()
// =>{ type: 'FeatureCollection', features: [] }删除所有要素
delete(ids: string | Array<string>): draw 删除所有要素
javascript
draw.deleteAll().getAll()设置要素
set(featureCollection: FeatureCollection): Array<string> 设置要素
javascript
var ids = draw.set({
type: 'FeatureCollection',
features: [
{
type: 'Feature',
properties: {},
id: 'example-id',
geometry: { type: 'Point', coordinates: [0, 0] },
},
],
})
//=> ['example-id']获取当前绘制模式
getMode(): string
启用绘制模式
changeMode(mode: string, options?: Object): draw 启用绘制模式
javascript
draw.changeMode(mode, options)设置指定ID要素的属性值
setFeatureProperty(featureId: string, property: string, value: any): draw 启用绘制模式
javascript
draw.setFeatureProperty(id, key, value)