一、封装点的更新
class Point{
static update({
fid,
position,
attr,
service,
layer
}) {
/* 1、确定修改的几何位置 */
var gpoint = new Zondy.Object.GPoint(position[0],position[1]) // 修改位置
/* 设置当前点要素的几何信息 */
var fGeom = new Zondy.Object.FeatureGeometry({
PntGeom: [gpoint]
})
/* 2、样式信息 */
/* 2.2 设置样式信息 */
var pointInfo = new Zondy.Object.CPointInfo(POINT_STYLE)
/* 设置当点要素的图形参数信息 */
var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
InfoType: 1, //点
PntInfo: pointInfo
})
/* 3、属性 */
var attValue = attr.map(item=>item.value)
/* 4、设置要素 */
var feature = new Zondy.Object.Feature({
fGeom: fGeom, //坐标--几何信息
GraphicInfo: webGraphicInfo, //样式信息
AttValue: attValue //属性
})
/* 设置要素为点要素
点 -->1
线 -->2
面 -->3
*/
feature.setFType(1)
feature.setFID(fid) //++
/* 5、设置要素集,添加要素 */
//创建一个要素数据集
var featureSet = new Zondy.Object.FeatureSet()
/* 设置属性结构 */
var cAttStruct = new Zondy.Object.CAttStruct({
FldName: attr.map(item=>item.key),
FldNumber: attr.length, //属性的个数
FldType: attr.map(item=>item.type)
})
featureSet.AttStruct = cAttStruct
/* 添加要素到要素数据集 */
featureSet.addFeature(feature)
/* 6、调用服务,执行更新 */
/*
创建一个编辑服务类
第一个参数:服务的名称 第二参数:图层的名称
*/
var editService = new Zondy.Service.EditDocFeature(service.name, service.layerId, {
ip: 'localhost',
port: '6163' //访问IGServer的端口号, .net为6163,Java为8089
})
//执行添加点要素功能
editService.update(featureSet, this.onPntSuccess(layer))
}
}
二、例子
1、通过拉框查询获取geometry
2、调用查询服务,获取fid
3、根据fid,更新元素的位置及属性
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./dist/include-openlayers-local.js"></script>
<script src="./libs/gaode.js"></script>
<script src="./utils/Draw.js"></script>
<script src="./libs/Query.js"></script>
<script src="./libs/Point.js"></script>
</head>
<body>
<button class="btn btn-primary" onclick="active()">激活</button>
<div id="map_container">
</div>
<script>
var ig_server = 'xzd_city'
var docLayer = new Zondy.Map.Doc('', ig_server, {
ip: 'localhost',
port: 6163
})
var map = new ol.Map({
target: "map_container",
layers: [gaode],
view: new ol.View({
projection: 'EPSG:4326',
center: [114.30, 30.50],
zoom: 4
})
})
map.addLayer(docLayer)
const source = new ol.source.Vector({
wrapX: false
})
const layer = new ol.layer.Vector({
source: source
})
map.addLayer(layer);
//2.3 创建画笔
let draw = null;
function active() {
draw = createDraw({
type: "Rectangle",
source,
callback: handleDraw
})
map.addInteraction(draw);
}
function handleDraw(e) {
var geometry = e.feature.getGeometry();
Query.queryByGeom({
geometry,
service: {
name: ig_server,
layerId: 2
},
callback: onQuerySuccess
})
}
function onQuerySuccess(e) {
var res = e.SFEleArray
var fids = res.map(item => item.FID);
var attr = [{key:"name",value:"北京",type:"string"}]
var service = {name:ig_server,layerId:2}
var layer = docLayer;
Point.update({
fid:fids[0],
position:[120,40],
attr,
service,
layer
})
}
</script>
</body>
</html>