Summary
Methods:
| clone |
克隆一个新的feature要素,新要素与原有要素相同。 |
| copyTo |
复制一个Feature,将得到的feature的地理范围中心变成传参的coordinate。该方法是以要素几何体的中心坐标到目标坐标为基准移动的,复制不影响原来的地理要素。 |
| destroy |
销毁要素内部所有属性。销毁指的是彻底将该要素从内存中移除。 |
| getAttributes |
获取当前要素的属性。 |
| getBBox |
获取该矢量地理要素的三维包围盒。 |
| getExtent |
获取当前地理要素的地理范围。 |
| getFid |
获取系统保留的唯一标识。 |
| getGeometry |
获取要素中的几何体 |
| getHighlight |
获取要素的高亮状态 |
| getStyle |
获取当前要素的样式。 |
| getVisibility |
获取当前地理要素的可见性 |
| offClick |
取消要素注册的单击事件。 |
| offHover |
取消要素注册的Hover(滑入滑出)事件。 |
| onClick |
注册要素的单击事件,需调用map.enableInteractive()开启点和要素的交互行为才有效。 |
| onHover |
注册要素的hover(滑入滑出)事件,需调用map.enableInteractive()开启点和要素的交互行为才有效。 |
| setAttributes |
设置地理要素的非空间属性。注意,该操作会覆盖原有属性 |
| setFid |
设置地理要素的唯一标识。 |
| setGeometry |
重新设置地理要素的几何体。 |
| setHighlight |
高亮当前地理要素。 |
| setStyle |
设置地理要素的样式。该要素原有的样式会被给出的样式替代。 |
| setVisibility |
设置在图层中可见性。可见性决定了当前地理要素是否在图层中显示。 |
Constructor
new Vector(geometry, attributes, style)
Parameters:
| Name | Type | Description |
|---|---|---|
geometry |
module:geom~Geometry | 地理几何体。 |
attributes |
Object | 一个对象,用来描述地理要素的非空间属性。 |
style |
module:style~Style | 用来描述地理要素在地图上表现形态。当添加到图层上时,如果不指定样式,则采用默认的图层样式。 |
Example
let coord = new hmap.basetype.Coordinate(120,30,0);
let point = new hmap.geom.Point(coord);
let style = hmap.style.Style.getDefault();
let feature = new hmap.feature.Vector(point,{name:'摄像头', id:205},style);
Methods
-
clone() → {module:feature~Vector}
-
克隆一个新的feature要素,新要素与原有要素相同。
Example
let newFeature = feature.clone(); -
copyTo(coordinate) → {module:feature~Vector}
-
复制一个Feature,将得到的feature的地理范围中心变成传参的coordinate。该方法是以要素几何体的中心坐标到目标坐标为基准移动的,复制不影响原来的地理要素。
Parameters:
Name Type Description coordinatemodule:basetype~Coordinate 目标地理坐标。
Example
let coordinate = new hmap.basetype.Coordinate(121,31,0); let result = feature.copyTo(coordinate); //result=new hmap.feature.Vector( // new hmap.geom.Point(new hmap.basetype.Coordinate(121,31,0)), // {name: "摄像头", id: 205}, // hmap.style.Style.getDefault() //) -
destroy()
-
销毁要素内部所有属性。销毁指的是彻底将该要素从内存中移除。
Example
feature.destroy(); -
getAttributes() → {JSON}
-
获取当前要素的属性。
Returns:
JSON -当前要素的属性信息。
Example
let result = feature.getAttributes();//result={name:'摄像头', id:205} -
getBBox() → {module:basetype~BBox}
-
获取该矢量地理要素的三维包围盒。
-
getExtent() → {module:basetype~Extent}
-
获取当前地理要素的地理范围。
Example
let result = feature.getExtent(); //result=new hmap.basetype.Extent(120,30,120,30) -
getFid() → {String}
-
获取系统保留的唯一标识。
Returns:
String -唯一标识。
Example
let fid = feature.getFid(); -
getGeometry() → {module:geom~Geometry}
-
获取要素中的几何体
Example
let result = feature.getGeometry(); //result=new hmap.geom.Point(new hmap.basetype.Coordinate(120,30,0)) -
getHighlight() → {Boolean}
-
获取要素的高亮状态
Returns:
Boolean -高亮状态返回true,非高亮状态返回false。
Example
let status = feature.getHighlight(); -
getStyle() → {module:style~Style}
-
获取当前要素的样式。
Example
let style = feature.getStyle(); -
getVisibility() → {Boolean}
-
获取当前地理要素的可见性
Returns:
Boolean -true表示可见,false表示不可见。
Example
let visible = feature.getVisibility(); -
offClick()
-
取消要素注册的单击事件。
-
offHover()
-
取消要素注册的Hover(滑入滑出)事件。
-
onClick(callback)
-
注册要素的单击事件,需调用map.enableInteractive()开启点和要素的交互行为才有效。
Parameters:
Name Type Description callback回调处理函数,参数是event对象,event.feature 可以取到要素本身。event.lonlat可以去到点击位置的经纬度,event.mapPixel可以取到像素位置
Example
map.enableInteractive(); const pointSymbol = new hmap.style.Circle({ radius: 10, fillColor: new hmap.style.Color(255, 0, 120, 1) }); const markerStyle = new hmap.style.Style({markerSymbols: [pointSymbol]}); const point = new hmap.geom.Point(new hmap.basetype.Coordinate(120.12778, 30.27871, 0.02)); pointFeature = new hmap.feature.Vector(point, {}, markerStyle); //注册click事件 pointFeature.onClick(this.click); vectorLayer.addFeatures([pointFeature]); -
onHover()
-
注册要素的hover(滑入滑出)事件,需调用map.enableInteractive()开启点和要素的交互行为才有效。
Example
map.enableInteractive(); const pointSymbol = new hmap.style.Circle({ radius: 10, fillColor: new hmap.style.Color(255, 0, 120, 1) }); const markerStyle = new hmap.style.Style({markerSymbols: [pointSymbol]}); const point = new hmap.geom.Point(new hmap.basetype.Coordinate(120.12778, 30.27871, 0.02)); pointFeature = new hmap.feature.Vector(point, {}, markerStyle); //注册Hover(滑入滑出)事件 pointFeature.onHover(this.mouseOverCallback,this.mouseOutCallback); vectorLayer.addFeatures([pointFeature]); -
setAttributes(attributes)
-
设置地理要素的非空间属性。注意,该操作会覆盖原有属性
Parameters:
Name Type Description attributesJSON 要设置的属性
Example
feature.setAttributes({name:'卡口', age:14}); let result = feature.getAttributes(); //result={name: "卡口", age: 14} -
setFid(id)
-
设置地理要素的唯一标识。
Parameters:
Name Type Description idString 唯一标识。
Example
feature.setFid("feature0"); -
setGeometry(geom)
-
重新设置地理要素的几何体。
Parameters:
Name Type Description geommodule:geom~Geometry 几何体对象。
Throws:
当参数geom不是Geometry子类的实例时,抛出异常:"the parameter is not a Geometry ."
Example
let coord = new hmap.basetype.Coordinate(122,32,0); let point = new hmap.geom.Point(coord); feature.setGeometry(point); let result = feature; //以下的point、style就是上面给出的变量值 //result=new hmap.feature.Vector(point,{},style) -
setHighlight(flag)
-
高亮当前地理要素。
Parameters:
Name Type Description flagBoolean 高亮设置true,取消高亮设置false。
Throws:
当参数flag既不是true,也不为false时,抛出参数类型异常。
Example
feature.setHighlight(true); -
setStyle(style)
-
设置地理要素的样式。该要素原有的样式会被给出的样式替代。
Parameters:
Name Type Description stylemodule:style~Style 样式
Throws:
当参数style不是Style实例时,抛出异常:"the parameter style is neither an instance of Style nor null"
Example
let style = new hmap.style.Style(); feature.setStyle(style); -
setVisibility(flag)
-
设置在图层中可见性。可见性决定了当前地理要素是否在图层中显示。
Parameters:
Name Type Description flagBoolean 可见用true,不可见用false。
Throws:
当参数flag既不是true,也不为false时,抛出参数类型异常。
Example
feature.setVisibility(true);