plot_operatePlottingLayer.html 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. </head>
  10. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  11. <div id="toolbar" class="panel panel-primary" style=" position: absolute;top: 10px;right: 10px;text-align: center;z-index: 9999;border-radius: 4px;">
  12. <div class='panel-heading' id="panelheading">
  13. <h5 class='panel-title text-center' data-i18n="resources.title_operatePlottingLayer"></h5></div>
  14. <div class='panel-body content' id="panelbodycontent">
  15. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_createLayer" onclick="createPlottingLayer()"/>
  16. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_deleteLayer" onclick="removePlottingLayer()"/>
  17. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_drawMarker" onclick="plotSymbol()"/>
  18. <input type="button" class="btn btn-default" data-i18n="[value]resources.btn_cancelMarker" onclick="plottingDrawCancel()"/>
  19. </div>
  20. </div>
  21. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  22. <script type="text/javascript" include="bootstrap,widgets.alert,jquery" src="../js/include-web.js"></script>
  23. <script type="text/javascript" include="iclient-leaflet-css,iclient-plot-leaflet" src="../../dist/leaflet/include-leaflet.js"></script>
  24. <script type="text/javascript">
  25. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  26. var url = host + "/iserver/services/map-china400/rest/maps/China_4326";
  27. var serverUrl = host + "/iserver/services/plot-jingyong/rest/plot/";
  28. var map,plottingLayer,plottingLayers=[],drawControl;
  29. map = L.map('map', {
  30. preferCanvas: true,
  31. crs: L.CRS.EPSG4326,
  32. center: [35,104],
  33. maxZoom: 18,
  34. zoom: 3
  35. });
  36. L.supermap.tiledMapLayer(url).addTo(map);
  37. drawControl = L.supermap.plotting.drawControl();
  38. drawControl.addTo(map);
  39. var editControl = L.supermap.plotting.editControl();
  40. editControl.addTo(map);
  41. function createPlottingLayer(){
  42. widgets.alert.clearAlert();
  43. var plottingLayerName = "plottingLayer_" + Math.ceil(Math.random() * 1000);
  44. plottingLayer = L.supermap.plotting.plottingLayer(plottingLayerName, serverUrl);
  45. drawControl.setDrawingLayer(plottingLayer);
  46. plottingLayer.addTo(map);
  47. plottingLayers.push(plottingLayer);
  48. var successMessage = "图层 " + plottingLayer.name + " 创建成功";
  49. widgets.alert.showAlert(successMessage,true);
  50. }
  51. function removePlottingLayer(){
  52. widgets.alert.clearAlert();
  53. if (plottingLayers.length !== 0) {
  54. var tempPlottingLayer = plottingLayers[plottingLayers.length - 1];
  55. map.removeLayer(tempPlottingLayer);
  56. var successMessage = "图层 " + tempPlottingLayer.name + " 删除成功";
  57. plottingLayers.splice(plottingLayers.length - 1, 1);
  58. if(plottingLayers.length > 0){
  59. drawControl.setDrawingLayer(plottingLayers[plottingLayers.length-1]);
  60. }
  61. widgets.alert.showAlert(successMessage,true);
  62. } else {
  63. widgets.alert.showAlert("当前地图无标绘图层",false);
  64. }
  65. }
  66. function plotSymbol(){
  67. widgets.alert.clearAlert();
  68. if(drawControl.drawingLayer !== undefined){
  69. drawControl.handler.libID = 421;
  70. drawControl.handler.code = 10100;
  71. drawControl.handler.serverUrl = serverUrl;
  72. drawControl.handler.enable();
  73. }else{
  74. widgets.alert.showAlert("请先添加标绘图层!",true);
  75. }
  76. }
  77. function plottingDrawCancel(){
  78. widgets.alert.clearAlert();
  79. drawControl.handler.disable();
  80. }
  81. $(document).ready(function(){
  82. $('#panelheading').click(function(){
  83. $('#panelbodycontent').toggle();
  84. });
  85. });
  86. </script>
  87. </body>
  88. </html>