plot_drawGeoGraphicObject.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="utf-8">
  8. <title data-i18n="resources.title_drawGeoGraphicObject"></title>
  9. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. text-align: center;
  27. z-index: 100;
  28. border-radius: 4px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="toolbar" class="panel panel-primary">
  34. <div class='panel-heading'>
  35. <h5 class='panel-title text-center' data-i18n="resources.title_drawGeoGraphicObject"></h5></div>
  36. <div class='panel-body content'>
  37. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_drawLine" onclick="draw_line()"/>
  38. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_drawPolygon" onclick="draw_polygon()"/>
  39. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_drawText" onclick="draw_text()"/>
  40. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearFeatures()"/>
  41. </div>
  42. </div>
  43. <div id="map"></div>
  44. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  45. <script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
  46. <script>
  47. var map, layer, plottingEdit, lineLayer, plottingLayer,
  48. drawFeature;
  49. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  50. var mapurl = host + "/iserver/services/map-world/rest/maps/World";
  51. var plotUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
  52. init();
  53. function init() {
  54. map = new SuperMap.Map("map", {
  55. controls: [
  56. new SuperMap.Control.Zoom(),
  57. new SuperMap.Control.Navigation(),
  58. ]
  59. });
  60. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  61. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, null, {maxResolution: "auto"});
  62. layer.events.on({"layerInitialized": addLayer});
  63. plottingLayer = new SuperMap.Layer.PlottingLayer("标绘图层", plotUrl);
  64. plottingLayer.style = {
  65. fillColor: "#66cccc",
  66. fillOpacity: 0.4,
  67. strokeColor: "#66cccc",
  68. strokeOpacity: 1,
  69. strokeWidth: 3,
  70. pointRadius: 6
  71. };
  72. drawFeature = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.GraphicObject);
  73. //态势标绘编辑
  74. plottingEdit = new SuperMap.Control.PlottingEdit();
  75. map.addControls([plottingEdit, drawFeature]);
  76. }
  77. function addLayer() {
  78. map.addLayers([layer, plottingLayer]);
  79. //显示地图范围
  80. map.setCenter(new SuperMap.LonLat(0, 0), 0);
  81. }
  82. function draw_line() {
  83. clearFeatures();
  84. var locationPointWCs = [];
  85. locationPointWCs.push(new SuperMap.Geometry.Point(0, 0));
  86. locationPointWCs.push(new SuperMap.Geometry.Point(0, 20));
  87. locationPointWCs.push(new SuperMap.Geometry.Point(20, 10));
  88. locationPointWCs.push(new SuperMap.Geometry.Point(10, 30));
  89. plottingLayer.createSymbolWC(0, SuperMap.Plot.SymbolType.POLYLINESYMBOL, locationPointWCs);
  90. }
  91. function draw_polygon() {
  92. clearFeatures();
  93. var locationPointWCs = [];
  94. locationPointWCs.push(new SuperMap.Geometry.Point(20, 0));
  95. locationPointWCs.push(new SuperMap.Geometry.Point(10, 20));
  96. locationPointWCs.push(new SuperMap.Geometry.Point(30, 40));
  97. locationPointWCs.push(new SuperMap.Geometry.Point(60, 10));
  98. plottingLayer.createSymbolWC(0, SuperMap.Plot.SymbolType.ARBITRARYPOLYGONSYMBOL, locationPointWCs);
  99. }
  100. function draw_text() {
  101. clearFeatures();
  102. plottingLayer.createTextWC("Text", new SuperMap.Geometry.Point(20, 0), {});
  103. }
  104. function clearFeatures() {
  105. plottingLayer.removeAllFeatures();
  106. }
  107. //取消标绘与编辑
  108. function plottingAllDeactivate() {
  109. drawFeature.deactivate();
  110. plottingEdit.deactivate();
  111. }
  112. //取消标绘,激活标绘编辑控件
  113. function PlottingDrawCancel() {
  114. plottingAllDeactivate();
  115. plottingEdit.activate();
  116. }
  117. document.onmouseup = function (evt) {
  118. var evt = evt || window.event;
  119. if (evt.button === 2) {
  120. PlottingDrawCancel();
  121. return false;
  122. }
  123. evt.stopPropagation();
  124. }
  125. </script>
  126. </body>
  127. </html>