plot_operatePlottingLayer.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_operatePlottingLayer"></title>
  9. <script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot" src="../../dist/classic/include-classic.js"></script>
  10. <style type="text/css">
  11. body {
  12. margin: 0;
  13. overflow: hidden;
  14. background: #fff;
  15. width: 100%;
  16. height: 100%
  17. }
  18. #map {
  19. position: absolute;
  20. width: 100%;
  21. height: 100%;
  22. }
  23. #toolbar {
  24. position: absolute;
  25. top: 50px;
  26. right: 10px;
  27. text-align: center;
  28. z-index: 100;
  29. border-radius: 4px;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id="toolbar" class="panel panel-primary">
  35. <div class='panel-heading'>
  36. <h5 class='panel-title text-center' data-i18n="resources.title_operatePlottingLayer"></h5></div>
  37. <div class='panel-body content'>
  38. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_createLayer" onclick="createLayer()"/>
  39. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_deleteLayer" onclick="removeLayer()"/>
  40. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_drawMarker" onclick="plotSymbol()"/>
  41. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker" onclick="PlottingDrawCancel()"/>
  42. </div>
  43. </div>
  44. <div id="map"></div>
  45. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  46. <script>
  47. var map, baseLayer, drawGraphicObject, plottingEdit, symbolLibManager, plotting, plottingLayers = [],
  48. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  49. url = host + "/iserver/services/map-world/rest/maps/World";
  50. var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
  51. init();
  52. function init() {
  53. map = new SuperMap.Map("map", {
  54. controls: [
  55. new SuperMap.Control.ScaleLine(),
  56. new SuperMap.Control.Zoom(),
  57. new SuperMap.Control.Navigation({
  58. dragPanOptions: {
  59. enableKinetic: true
  60. }
  61. })]
  62. });
  63. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  64. baseLayer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
  65. transparent: true,
  66. cacheEnabled: true
  67. }, {maxResolution: "auto"});
  68. baseLayer.events.on({"layerInitialized": addLayer});
  69. plotting = SuperMap.Plotting.getInstance(map, serverUrl);
  70. symbolLibManager = plotting.getSymbolLibManager();
  71. symbolLibManager.initializeAsync();
  72. }
  73. function addLayer() {
  74. map.addLayers([baseLayer]);
  75. map.setCenter(new SuperMap.LonLat(0, 0), 0);
  76. }
  77. function createLayer() {
  78. widgets.alert.clearAlert();
  79. PlottingDrawCancel();
  80. if (plottingEdit) {
  81. plottingEdit.deactivate();
  82. }
  83. var plottingLayerName = "plottingLayer_" + Math.ceil(Math.random() * 1000);
  84. var plottingLayer = new SuperMap.Layer.PlottingLayer(plottingLayerName, serverUrl);
  85. plottingLayer.events.on({"added": layerAdded});
  86. map.addLayers([plottingLayer]);
  87. }
  88. function layerAdded(addedEvt) {
  89. plottingLayers.push(addedEvt.layer);
  90. var successMessage = resources.text_layer + addedEvt.layer.name + resources.text_createSuccess;
  91. widgets.alert.showAlert(successMessage, true);
  92. // 绘制标号;
  93. drawGraphicObject = new SuperMap.Control.DrawFeature(addedEvt.layer, SuperMap.Handler.GraphicObject);
  94. //态势标绘编辑
  95. plottingEdit = new SuperMap.Control.PlottingEdit();
  96. //添加态势标绘控件
  97. map.addControls([plottingEdit, drawGraphicObject]);
  98. }
  99. function removeLayer() {
  100. widgets.alert.clearAlert();
  101. if (plottingLayers.length !== 0) {
  102. plottingEdit.unselectFeatures();
  103. var plottingLayer = plottingLayers[plottingLayers.length - 1];
  104. plottingLayer.events.on({"removed": layerRemoved});
  105. map.removeLayer(plottingLayer);
  106. map.removeControl(plottingLayer.drawGraphicObject);
  107. } else {
  108. widgets.alert.showAlert(resources.msg_NoPlottingLayer, false);
  109. }
  110. if (plottingLayers.length !== 0) {
  111. drawGraphicObject.layer = plottingLayers[plottingLayers.length - 1];
  112. } else {
  113. drawGraphicObject = null;
  114. }
  115. }
  116. function layerRemoved(removedEvt) {
  117. plottingLayers.pop();
  118. var successMessage = resources.text_layer + removedEvt.layer.name + resources.text_deleteSuccess;
  119. widgets.alert.showAlert(successMessage, true);
  120. }
  121. function plotSymbol() {
  122. widgets.alert.clearAlert();
  123. if (drawGraphicObject && drawGraphicObject !== null) {
  124. drawGraphicObject.activate();
  125. drawGraphicObject.handler.libID = 421;
  126. drawGraphicObject.handler.symbolCode = 10200;
  127. drawGraphicObject.handler.serverUrl = serverUrl;
  128. }
  129. }
  130. //取消绘制
  131. function PlottingDrawCancel() {
  132. widgets.alert.clearAlert();
  133. if (drawGraphicObject) {
  134. drawGraphicObject.deactivate();
  135. } else {
  136. var map = document.getElementById('map');
  137. map.oncontextmenu = function () {
  138. window.event.returnValue = false;
  139. return false;
  140. }
  141. }
  142. if (plottingEdit) {
  143. plottingEdit.activate();
  144. } else {
  145. var map = document.getElementById('map');
  146. map.oncontextmenu = function () {
  147. window.event.returnValue = false;
  148. return false;
  149. }
  150. }
  151. }
  152. document.onmouseup = function (evt) {
  153. var evt = evt || window.event;
  154. if (evt.button === 2) {
  155. PlottingDrawCancel(evt);
  156. return false;
  157. }
  158. };
  159. </script>
  160. </body>
  161. </html>