一、封装点的更新

  1. class Point{
  2. static update({
  3. fid,
  4. position,
  5. attr,
  6. service,
  7. layer
  8. }) {
  9. /* 1、确定修改的几何位置 */
  10. var gpoint = new Zondy.Object.GPoint(position[0],position[1]) // 修改位置
  11. /* 设置当前点要素的几何信息 */
  12. var fGeom = new Zondy.Object.FeatureGeometry({
  13. PntGeom: [gpoint]
  14. })
  15. /* 2、样式信息 */
  16. /* 2.2 设置样式信息 */
  17. var pointInfo = new Zondy.Object.CPointInfo(POINT_STYLE)
  18. /* 设置当点要素的图形参数信息 */
  19. var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
  20. InfoType: 1, //点
  21. PntInfo: pointInfo
  22. })
  23. /* 3、属性 */
  24. var attValue = attr.map(item=>item.value)
  25. /* 4、设置要素 */
  26. var feature = new Zondy.Object.Feature({
  27. fGeom: fGeom, //坐标--几何信息
  28. GraphicInfo: webGraphicInfo, //样式信息
  29. AttValue: attValue //属性
  30. })
  31. /* 设置要素为点要素
  32. 点 -->1
  33. 线 -->2
  34. 面 -->3
  35. */
  36. feature.setFType(1)
  37. feature.setFID(fid) //++
  38. /* 5、设置要素集,添加要素 */
  39. //创建一个要素数据集
  40. var featureSet = new Zondy.Object.FeatureSet()
  41. /* 设置属性结构 */
  42. var cAttStruct = new Zondy.Object.CAttStruct({
  43. FldName: attr.map(item=>item.key),
  44. FldNumber: attr.length, //属性的个数
  45. FldType: attr.map(item=>item.type)
  46. })
  47. featureSet.AttStruct = cAttStruct
  48. /* 添加要素到要素数据集 */
  49. featureSet.addFeature(feature)
  50. /* 6、调用服务,执行更新 */
  51. /*
  52. 创建一个编辑服务类
  53. 第一个参数:服务的名称 第二参数:图层的名称
  54. */
  55. var editService = new Zondy.Service.EditDocFeature(service.name, service.layerId, {
  56. ip: 'localhost',
  57. port: '6163' //访问IGServer的端口号, .net为6163,Java为8089
  58. })
  59. //执行添加点要素功能
  60. editService.update(featureSet, this.onPntSuccess(layer))
  61. }
  62. }

二、例子

1、通过拉框查询获取geometry
2、调用查询服务,获取fid
3、根据fid,更新元素的位置及属性
draw.gif

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <script src="./dist/include-openlayers-local.js"></script>
  8. <script src="./libs/gaode.js"></script>
  9. <script src="./utils/Draw.js"></script>
  10. <script src="./libs/Query.js"></script>
  11. <script src="./libs/Point.js"></script>
  12. </head>
  13. <body>
  14. <button class="btn btn-primary" onclick="active()">激活</button>
  15. <div id="map_container">
  16. </div>
  17. <script>
  18. var ig_server = 'xzd_city'
  19. var docLayer = new Zondy.Map.Doc('', ig_server, {
  20. ip: 'localhost',
  21. port: 6163
  22. })
  23. var map = new ol.Map({
  24. target: "map_container",
  25. layers: [gaode],
  26. view: new ol.View({
  27. projection: 'EPSG:4326',
  28. center: [114.30, 30.50],
  29. zoom: 4
  30. })
  31. })
  32. map.addLayer(docLayer)
  33. const source = new ol.source.Vector({
  34. wrapX: false
  35. })
  36. const layer = new ol.layer.Vector({
  37. source: source
  38. })
  39. map.addLayer(layer);
  40. //2.3 创建画笔
  41. let draw = null;
  42. function active() {
  43. draw = createDraw({
  44. type: "Rectangle",
  45. source,
  46. callback: handleDraw
  47. })
  48. map.addInteraction(draw);
  49. }
  50. function handleDraw(e) {
  51. var geometry = e.feature.getGeometry();
  52. Query.queryByGeom({
  53. geometry,
  54. service: {
  55. name: ig_server,
  56. layerId: 2
  57. },
  58. callback: onQuerySuccess
  59. })
  60. }
  61. function onQuerySuccess(e) {
  62. var res = e.SFEleArray
  63. var fids = res.map(item => item.FID);
  64. var attr = [{key:"name",value:"北京",type:"string"}]
  65. var service = {name:ig_server,layerId:2}
  66. var layer = docLayer;
  67. Point.update({
  68. fid:fids[0],
  69. position:[120,40],
  70. attr,
  71. service,
  72. layer
  73. })
  74. }
  75. </script>
  76. </body>
  77. </html>