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. </head>
    10. <body>
    11. <button onclick="topAnalysis()">拓扑相交分析</button>
    12. <div id="map_container">
    13. </div>
    14. <script>
    15. var map = new ol.Map({
    16. target: "map_container",
    17. layers: [gaode],
    18. view: new ol.View({
    19. projection: 'EPSG:4326',
    20. center: [114.30, 30.50],
    21. zoom: 8
    22. })
    23. })
    24. //1、准备第一个图形
    25. const lineObj = new Zondy.Object.GLine(
    26. new Zondy.Object.AnyLine([
    27. new Zondy.Object.Arc([
    28. new Zondy.Object.Point2D(114.4, 30.6),
    29. new Zondy.Object.Point2D(114.45, 30.2)
    30. ])
    31. ])
    32. )
    33. //2、准备第二个比较图形
    34. const regionObj = new Zondy.Object.GRegion([
    35. new Zondy.Object.AnyLine([
    36. new Zondy.Object.Arc([
    37. new Zondy.Object.Point2D(114.301586, 30.533613),
    38. new Zondy.Object.Point2D(114.301586, 30.396517),
    39. new Zondy.Object.Point2D(114.544453, 30.396517),
    40. new Zondy.Object.Point2D(114.444453, 30.533613),
    41. new Zondy.Object.Point2D(114.401586, 30.533613)
    42. ])
    43. ])
    44. ])
    45. //将点几何和区几何添加到地图进行显示(非必需,仅仅为了在地图上高亮显示图形)
    46. var linePntArr = [];
    47. var linPointArr = [];
    48. for (var i = 0; i < lineObj.Line.Arcs[0].Dots.length; i++) {
    49. linePntArr.push([lineObj.Line.Arcs[0].Dots[i].x, lineObj.Line.Arcs[0].Dots[i].y]);
    50. }
    51. for (var i = 0; i < regionObj.Rings[0].Arcs[0].Dots.length; i++) {
    52. linPointArr.push([regionObj.Rings[0].Arcs[0].Dots[i].x, regionObj.Rings[0].Arcs[0].Dots[i].y]);
    53. }
    54. //创建要素1(线要素)
    55. var feature1 = new ol.Feature({
    56. geometry: new ol.geom.LineString(linePntArr)
    57. });
    58. //设置要素样式
    59. feature1.setStyle(new ol.style.Style({
    60. stroke: new ol.style.Stroke({
    61. color: 'rgba(41,57,85,1)',
    62. width: 3
    63. })
    64. }));
    65. //创建要素2(区要素)
    66. var feature2 = new ol.Feature({
    67. geometry: new ol.geom.Polygon([linPointArr])
    68. });
    69. //设置要素样式
    70. feature2.setStyle(new ol.style.Style({
    71. fill: new ol.style.Fill({
    72. color: 'rgba(22,197,199,0.5)'
    73. }),
    74. stroke: new ol.style.Stroke({
    75. color: 'rgba(22,197,199,0.5)',
    76. width: 3
    77. })
    78. }));
    79. //创建资源
    80. var source = new ol.source.Vector({
    81. features: [feature1, feature2],
    82. warpX: false
    83. });
    84. var graphicLayer = new ol.layer.Vector({
    85. source: source
    86. });
    87. map.addLayer(graphicLayer);
    88. //3、调用分析服务
    89. function topAnalysis() {
    90. var topParam = new Zondy.Service.TopAnalysis({
    91. ip: 'localhost',
    92. port: '6163'
    93. })
    94. topParam.setLine(lineObj)
    95. //调用setRelativeObj方法,设置拓扑分析参照物
    96. topParam.setRelativeObj(regionObj);
    97. topParam.nearDis = '0.05'
    98. topParam.execute(onSuccess, onError)
    99. }
    100. function onSuccess(result) {
    101. console.log(result)
    102. }
    103. function onError(err) {
    104. console.log(err)
    105. }
    106. </script>
    107. </body>
    108. </html>