一、创建一个区

1-1、创区要素

image.png

1-2、以武汉为中心,创建一个区域

image.png
之后再IGServer中发布

二、点击事件,添加区要素

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