一、更新区要素

update setFID

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 1、加载ol -->
  9. <script src="../lib/include-openlayers-local.js"></script>
  10. <script src="../js/Gaode.js"></script>
  11. </head>
  12. <body>
  13. <!-- 2、创建地图容器 -->
  14. <button onclick="updatePolygon()">更新</button>
  15. <div id="map_container">
  16. </div>
  17. <!-- 3、实例化对象 -->
  18. <script>
  19. const docLayer = new Zondy.Map.Doc('', 'city', {
  20. ip: 'localhost',
  21. port: 6163
  22. })
  23. const map = new ol.Map({
  24. target: 'map_container',
  25. layers: [gaode, docLayer],
  26. view: new ol.View({
  27. projection: 'EPSG:4326',
  28. center: [114, 30],
  29. zoom: 4
  30. })
  31. })
  32. function updatePolygon(){
  33. /* 2.1 构建几何信息 */
  34. var pointObj = [];
  35. pointObj[0] = new Zondy.Object.Point2D(104,35.88); // 修改99.41为100
  36. pointObj[1] = new Zondy.Object.Point2D(99.41,26.82);
  37. pointObj[2] = new Zondy.Object.Point2D(108,26.82);
  38. pointObj[3] = new Zondy.Object.Point2D(108,35.88);
  39. //设置区要素的几何信息
  40. var gArc = new Zondy.Object.Arc(pointObj)
  41. //构成区要素折线
  42. var gAnyLine = new Zondy.Object.AnyLine([gArc])
  43. //构成区要素
  44. var gRegion = new Zondy.Object.GRegion([gAnyLine])
  45. //构成区要素的几何信息
  46. var fGeom = new Zondy.Object.FeatureGeometry({RegGeom:[gRegion]})
  47. /* 2.2 设置样式信息 */
  48. var cRegionInfo = new Zondy.Object.CRegionInfo({
  49. EndColor:1,
  50. FillColor:5,
  51. FillMode:0,
  52. OutPenWidth:1,
  53. OverMethod:0,
  54. PatAngle:1,
  55. PatColor:1,
  56. PatHeight:1,
  57. PatID:27,
  58. PatWidth:1
  59. })
  60. var graphicInfo = new Zondy.Object.WebGraphicsInfo({
  61. InfoType:3, //区
  62. RegInfo:cRegionInfo
  63. })
  64. /* 2.3 设置属性信息 */
  65. //设置区要素的属性信息
  66. var attValue = ["中地数码-成都",100,800]
  67. /* 2.4 构建区要素对象 */
  68. //创建一个新的区要素
  69. var newFeature = new Zondy.Object.Feature({
  70. fGeom:fGeom,
  71. GraphicInfo:graphicInfo,
  72. AttValue:attValue
  73. })
  74. newFeature.setFType(3)
  75. //++
  76. newFeature.setFID(2)
  77. /* 2.5 设置要素集 */
  78. var featureSet = new Zondy.Object.FeatureSet()
  79. var cAttValue = new Zondy.Object.CAttStruct({
  80. FldNumber:3,
  81. FldType:['string','float','int'],
  82. FldName:['name','area','num']
  83. })
  84. featureSet.AttStruct = cAttValue;
  85. featureSet.addFeature(newFeature)
  86. /* 2.6调用地图编辑服务接口 */
  87. //创建一个要素编辑服务对象
  88. var editDocFeature = new Zondy.Service.EditDocFeature(
  89. 'city',
  90. 0,
  91. {
  92. ip:'localhost',
  93. port:'6163'
  94. }
  95. )
  96. editDocFeature.update(featureSet,onSuccess)
  97. }
  98. function onSuccess(data) {
  99. if (data.succeed) {
  100. alert('更新成功')
  101. docLayer.refresh(); //重新加载地图文档
  102. } else {
  103. alert('更新失败')
  104. }
  105. }
  106. </script>
  107. </body>
  108. </html>

二、修改点

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 1、加载ol -->
  9. <script src="../lib/include-openlayers-local.js"></script>
  10. <script src="../js/Gaode.js"></script>
  11. </head>
  12. <body>
  13. <!-- 2、创建地图容器 -->
  14. <button onclick="updatePoint()">修改上海到东海</button>
  15. <div id="map_container">
  16. </div>
  17. <!-- 3、实例化对象 -->
  18. <script>
  19. const docLayer = new Zondy.Map.Doc('', 'city', {
  20. ip: 'localhost',
  21. port: 6163
  22. })
  23. const map = new ol.Map({
  24. target: 'map_container',
  25. layers: [gaode, docLayer],
  26. view: new ol.View({
  27. projection: 'EPSG:4326',
  28. center: [114, 30],
  29. zoom: 4
  30. })
  31. })
  32. /* 添加一个点到数据库 */
  33. function updatePoint() {
  34. /* 2.1构建几何信息 */
  35. /* 创建一个点形状,描述点形状的几何信息 */
  36. var gpoint = new Zondy.Object.GPoint(130, 30.40) // 修改位置
  37. /* 设置当前点要素的几何信息 */
  38. var fGeom = new Zondy.Object.FeatureGeometry({
  39. PntGeom: [gpoint]
  40. })
  41. /* 2.2 设置样式信息 */
  42. var pointInfo = new Zondy.Object.CPointInfo({
  43. Angle: 0,
  44. Color: 8, //子图的颜色
  45. Space: 0,
  46. SymHeight: 5, //点的高度
  47. SymID: 31,
  48. SymWidth: 5 //点的宽度
  49. })
  50. /* 设置当点要素的图形参数信息 */
  51. var webGraphicInfo = new Zondy.Object.WebGraphicsInfo({
  52. InfoType: 1, //点
  53. PntInfo: pointInfo
  54. })
  55. /* 2.3 设置属性信息 */
  56. /* 设置添加点要素的属性信息 */
  57. var attValue = ['东海', '1005']
  58. /* 2.4 构建要素对象 */
  59. var feature = new Zondy.Object.Feature({
  60. fGeom: fGeom, //坐标--几何信息
  61. GraphicInfo: webGraphicInfo, //样式信息
  62. AttValue: attValue //属性
  63. })
  64. /* 设置要素为点要素
  65. 点 -->1
  66. 线 -->2
  67. 面 -->3
  68. */
  69. feature.setFType(1)
  70. feature.setFID(15) //++
  71. /* 2.5 设置要素集 */
  72. //创建一个要素数据集
  73. var featureSet = new Zondy.Object.FeatureSet()
  74. /* 设置属性结构 */
  75. var cAttStruct = new Zondy.Object.CAttStruct({
  76. FldName: ['name', 'id'], //属性的字段名
  77. FldNumber: 2, //属性的个数
  78. FldType: ['string', 'string'] //属性的类型
  79. })
  80. featureSet.AttStruct = cAttStruct
  81. /* 添加要素到要素数据集 */
  82. featureSet.addFeature(feature)
  83. /* 2.6 调用编辑服务接口 */
  84. /*
  85. 创建一个编辑服务类
  86. 第一个参数:服务的名称 第二参数:图层的名称
  87. */
  88. var editService = new Zondy.Service.EditDocFeature('city', 2, {
  89. ip: 'localhost',
  90. port: '6163' //访问IGServer的端口号, .net为6163,Java为8089
  91. })
  92. //执行添加点要素功能
  93. editService.update(featureSet, onSuccess)
  94. }
  95. function onSuccess(data) {
  96. if (data.succeed) {
  97. alert('修改成功')
  98. docLayer.refresh(); //重新加载地图文档
  99. } else {
  100. alert('修改失败')
  101. }
  102. }
  103. </script>
  104. </body>
  105. </html>

三、修改线

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <!-- 1、加载ol -->
  9. <script src="../lib/include-openlayers-local.js"></script>
  10. <script src="../js/Gaode.js"></script>
  11. </head>
  12. <body>
  13. <!-- 2、创建地图容器 -->
  14. <button onclick="updateLine()">修改</button>
  15. <div id="map_container">
  16. </div>
  17. <!-- 3、实例化对象 -->
  18. <script>
  19. const docLayer = new Zondy.Map.Doc('', 'city', {
  20. ip: 'localhost',
  21. port: 6163
  22. })
  23. const map = new ol.Map({
  24. target: 'map_container',
  25. layers: [gaode, docLayer],
  26. view: new ol.View({
  27. projection: 'EPSG:4326',
  28. center: [114, 30],
  29. zoom: 4
  30. })
  31. })
  32. /* 添加一个线到数据库 */
  33. function updateLine(){
  34. /* 2.1 构建几何信息 */
  35. var pointObj = []
  36. pointObj[0] = new Zondy.Object.Point2D(114,30);
  37. pointObj[1] = new Zondy.Object.Point2D(118,20); //修改
  38. /* 构成折线的弧度 */
  39. var gArc = new Zondy.Object.Arc(pointObj);
  40. /* 构成线的折线 */
  41. var gAnyLine = new Zondy.Object.AnyLine([gArc])
  42. /* 设置线要素的几何信息 */
  43. var gLine = new Zondy.Object.GLine(gAnyLine)
  44. /* 设置要素的几何信息 */
  45. var fGeom = new Zondy.Object.FeatureGeometry({LinGeom:[gLine]})
  46. /* 2.2 设置而样式信息 */
  47. //设置添加线要素的图形参数信息
  48. var clineInfo = new Zondy.Object.CLineInfo({
  49. Color:1, //子图的颜色号
  50. LinStyleID:0,
  51. LinStyleID2:19,
  52. LinWidth:0.1, //线宽
  53. Xscale:10,
  54. Yscale:10
  55. })
  56. //设置要素的图形参数
  57. var graphicInfo = new Zondy.Object.WebGraphicsInfo({
  58. InfoType:2, //线
  59. LinInfo:clineInfo
  60. })
  61. /* 2.3 设置属性信息 */
  62. var attValue = ['武广线',1289]
  63. /* 2.4 构建要素类*/
  64. //创建一个线要素
  65. var newFeature = new Zondy.Object.Feature({
  66. fGeom:fGeom,
  67. GraphicInfo:graphicInfo,
  68. AttValue:attValue
  69. })
  70. //设置要为线要素
  71. newFeature.setFType(2)
  72. newFeature.setFID(5)
  73. /* 2.5 设置要素集 */
  74. //创建一个要素数据集
  75. var featureSet = new Zondy.Object.FeatureSet();
  76. //创建属性结构设置对象
  77. var cAttStruct = new Zondy.Object.CAttStruct({
  78. FldName:['name','length'],
  79. FldNumber:2,
  80. FldType:['string','double ']
  81. })
  82. //设置要素数据集的属性结构
  83. featureSet.AttStruct = cAttStruct;
  84. //将添加的线要素添加到属性数据集中
  85. featureSet.addFeature(newFeature);
  86. /* 2.6 调用地图编辑服务接口 */
  87. //创建一个地图编辑对象
  88. var editDocFeature = new Zondy.Service.EditDocFeature('city',1,{
  89. ip:'localhost',
  90. port:'6163'
  91. })
  92. editDocFeature.update(featureSet,onSuccess)
  93. }
  94. function onSuccess(data) {
  95. if (data.succeed) {
  96. alert('修改成功')
  97. docLayer.refresh(); //重新加载地图文档
  98. } else {
  99. alert('修改失败')
  100. }
  101. }
  102. </script>
  103. </body>
  104. </html>