plot_saveload.html 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_saveload"></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. left: 250px;
  20. right: 0px;
  21. width: 100%;
  22. height: 100%;
  23. }
  24. #menu {
  25. position: absolute;
  26. float: left;
  27. background: #ffffff;
  28. width: 250px;
  29. height: 100%;
  30. border: 1px solid #3473b7;
  31. z-index: 100;
  32. }
  33. #toolbar {
  34. position: absolute;
  35. top: 50px;
  36. right: 10px;
  37. width: 315px;
  38. text-align: center;
  39. z-index: 100;
  40. border-radius: 4px;
  41. }
  42. #toolbar .panel-title {
  43. font-size: 16px;
  44. color: white;
  45. }
  46. .input-group {
  47. margin-bottom: 10px;
  48. }
  49. .panel-title {
  50. font-size: 16px;
  51. color: #ffffff;
  52. }
  53. </style>
  54. </head>
  55. <body>
  56. <div id="toolbar" class="panel panel-primary">
  57. <div class='panel-heading'>
  58. <h5 class='panel-title text-center' data-i18n="resources.title_saveload"></h5></div>
  59. <div class='panel-body content'>
  60. <div class='panel'>
  61. <div class='input-group' style="margin-top:15px;margin-left: 50px;">
  62. <select class="search-query form-control" id="SLT" style="width: 200px"></select>
  63. </div>
  64. <div class='input-group' style="margin-left: 20px;">
  65. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_load"
  66. onclick="loadSimulationMap()"/>&nbsp;
  67. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker"
  68. onclick="PlottingDrawCancel()"/>&nbsp;
  69. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
  70. onclick="PlottingClear()"/>&nbsp;
  71. <input type="button" class="btn btn-default " data-i18n="[value]resources.btn_save" onclick="save()"/>
  72. </div>
  73. <div class='input-group' style="margin-left: 50px;margin-bottom: 15px;">
  74. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_saveAs"
  75. onclick="SaveAsSmlFile()"/>
  76. <input type="text" id="txt" class='form-control' style="width: 100px;float: right"/>
  77. </div>
  78. </div>
  79. </div>
  80. </div>
  81. <div id="menu">
  82. <div class="easyui-panel" style="position:absolute;top:0px;bottom:0px;left:0px;right:0px;padding:5px; width: 100%;">
  83. <div class="easyui-tabs" style="width: 100%;height: 100%">
  84. <div id="plotPanel" data-i18n="[title]resources.text_drawPanel" style="overflow: hidden"></div>
  85. <div id="stylePanel" data-i18n="[title]resources.text_attributePanel"></div>
  86. </div>
  87. </div>
  88. </div>
  89. <div id="map"></div>
  90. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  91. <script type="text/javascript" exclude="iclient-classic" include="iclient8c-plot,PlottingPanel"
  92. src="../../dist/classic/include-classic.js"></script>
  93. <script>
  94. var map, plottingLayer, layer, plotting, plotPanel, stylePanel, plottingEdit, drawGraphicObjects = [];
  95. var select, SMLName = null;
  96. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  97. var mapurl = host + "/iserver/services/map-china400/rest/maps/China_4326";
  98. var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
  99. init();
  100. function init() {
  101. map = new SuperMap.Map("map", {
  102. controls: [
  103. new SuperMap.Control.LayerSwitcher(),
  104. new SuperMap.Control.ScaleLine(),
  105. new SuperMap.Control.Zoom(),
  106. new SuperMap.Control.Navigation({
  107. dragPanOptions: {
  108. enableKinetic: true
  109. }
  110. })]
  111. });
  112. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", mapurl, {
  113. transparent: true,
  114. cacheEnabled: true
  115. }, {maxResolution: "auto"});
  116. layer.events.on({"layerInitialized": addLayer});
  117. //总控类
  118. plotting = SuperMap.Plotting.getInstance(map, serverUrl);
  119. sitManager = plotting.getSitDataManager();
  120. sitManager.events.on({
  121. "getSMLInfosCompleted": getSMLInfosSucess,
  122. "getSMLInfosFailed": getSMLInfosFail,
  123. "openSmlFileCompleted": openSuccess,
  124. "openSmlFileFailed": openFail,
  125. "saveSmlFileCompleted": saveSuccess,
  126. "saveSmlFileFailed": saveFail
  127. });
  128. plottingLayer = new SuperMap.Layer.PlottingLayer("标绘图层", serverUrl);
  129. //空间分析服务地址:目前使用的是服务器默认空间分析地址,可更换成实际使用的空间分析服务地址
  130. //plottingLayer.spatialAnalystUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
  131. plottingLayer.style = {
  132. fillColor: "#66cccc",
  133. fillOpacity: 0.4,
  134. strokeColor: "#66cccc",
  135. strokeOpacity: 1,
  136. strokeWidth: 3,
  137. pointRadius: 6
  138. };
  139. //态势标绘编辑
  140. plottingEdit = new SuperMap.Control.PlottingEdit();
  141. // 绘制标号;
  142. var drawGraphicObject = new SuperMap.Control.DrawFeature(plottingLayer, SuperMap.Handler.GraphicObject);
  143. drawGraphicObjects.push(drawGraphicObject);
  144. //添加态势标绘控件
  145. map.addControls([plottingEdit, drawGraphicObject]);
  146. }
  147. function addLayer() {
  148. map.addLayers([layer, plottingLayer]);
  149. map.setCenter(new SuperMap.LonLat(104, 35), 3);
  150. //创建标绘面板
  151. plotPanel = new SuperMap.Plotting.PlotPanel("plotPanel", serverUrl, map);
  152. plotPanel.events.on({"initializeCompleted": initializeCompleted});
  153. plotPanel.initializeAsync();
  154. //创建属性面板
  155. stylePanel = new SuperMap.Plotting.StylePanel("stylePanel");
  156. stylePanel.addEditLayer(plottingLayer);
  157. //获取标号的列表
  158. getSMLInfos();
  159. }
  160. function initializeCompleted() {
  161. if (drawGraphicObjects.length > 0) {
  162. plotPanel.setDrawFeature(drawGraphicObjects[0]);
  163. }
  164. }
  165. //取消标绘
  166. function plottingAllDeactivate() {
  167. for (var i = 0; i < drawGraphicObjects.length; i++) {
  168. drawGraphicObjects[i].deactivate();
  169. }
  170. plottingEdit.deactivate();
  171. }
  172. //取消标绘,激活标绘编辑控件
  173. function PlottingDrawCancel() {
  174. widgets.alert.clearAlert();
  175. plottingAllDeactivate();
  176. plottingEdit.activate();
  177. }
  178. function getSMLInfos() {
  179. sitManager.getSMLInfos(0, 10);
  180. }
  181. function getSMLInfosSucess(result) {
  182. select = document.getElementById("SLT");
  183. while (select.hasChildNodes()) {
  184. select.removeChild(select.firstChild);
  185. }
  186. for (var i = 0, len = result.length; i < len; i++) {
  187. var options = document.createElement("option");
  188. options.setAttribute("value", result[i].SMLFileName);
  189. options.innerHTML = result[i].SMLFileName;
  190. select.appendChild(options);
  191. }
  192. return false;
  193. }
  194. function getSMLInfosFail(result) {
  195. console.log(result);
  196. }
  197. //态势图保存
  198. function save() {
  199. widgets.alert.clearAlert();
  200. plottingAllDeactivate();
  201. sitManager.saveSmlFile();
  202. }
  203. //态势图另存为
  204. function SaveAsSmlFile() {
  205. plottingAllDeactivate();
  206. SMLName = document.getElementById("txt").value;
  207. if (SMLName.length !== 0) {
  208. sitManager.saveAsSmlFile(SMLName);
  209. } else {
  210. widgets.alert.showAlert(resources.msg_inputName, true);
  211. }
  212. }
  213. function saveSuccess() {
  214. getSMLInfos();
  215. }
  216. function saveFail() {
  217. }
  218. //加载态势图
  219. function loadSimulationMap() {
  220. widgets.alert.clearAlert();
  221. var select = document.getElementById("SLT");
  222. for (var i = 0; i < select.children.length; i++) {
  223. if (select.children[i].selected) {
  224. sitManager.openSmlFileOnServer(select.children[i].value);
  225. }
  226. }
  227. }
  228. function openSuccess() {
  229. var sitDataLayers = sitManager.getSitDataLayers();
  230. drawGraphicObjects = [];
  231. for (var i = 0; i < sitDataLayers.length; i++) {
  232. drawGraphicObjects.push(sitDataLayers[i].drawGraphicObject);
  233. stylePanel.addEditLayer(sitDataLayers[i]);
  234. }
  235. plotPanel.setDrawFeature(drawGraphicObjects[0]);
  236. }
  237. function openFail() {
  238. console.log("error");
  239. }
  240. //清空绘制
  241. function PlottingClear() {
  242. widgets.alert.clearAlert();
  243. plottingAllDeactivate();
  244. for (var i = 0; i < map.layers.length; i++) {
  245. if (map.layers[i].CLASS_NAME === "SuperMap.Layer.PlottingLayer") {
  246. map.layers[i].removeAllFeatures();
  247. }
  248. }
  249. }
  250. document.onmouseup = function (evt) {
  251. var evt = evt || window.event;
  252. if (evt.button === 2) {
  253. PlottingDrawCancel();
  254. return false;
  255. }
  256. evt.stopPropagation();
  257. }
  258. </script>
  259. </body>
  260. </html>