OGC_kml.html 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <title>Kml</title>
  8. <style type="text/css">
  9. .editPane {
  10. position: absolute;
  11. right: 50px;
  12. top: 50px;
  13. text-align: center;
  14. background: #FFF;
  15. z-index: 1000;
  16. display: inline-block;
  17. }
  18. </style>
  19. </head>
  20. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  21. <div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
  22. <div class='panel-heading'>
  23. <h5 class='panel-title text-center'>Kml</h5>
  24. </div>
  25. <div class='panel-body' id='params'>
  26. <p></p>
  27. <div align='center' class='button-group'>
  28. <input type='button' id='loadBt' class='btn btn-primary' data-i18n="[value]resources.btn_load" onclick="loadKml()"/>
  29. </div>
  30. </div>
  31. </div>
  32. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  33. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  34. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  35. <script>
  36. var map, layer, loaded = false,
  37. host = window.isLocal ? window.server : "https://iserver.supermap.io";
  38. url = host + "/iserver/services/map-china400/rest/maps/China";
  39. map = new SuperMap.Map("map", {
  40. controls: [
  41. new SuperMap.Control.ScaleLine(),
  42. new SuperMap.Control.Zoom(),
  43. new SuperMap.Control.LayerSwitcher(),
  44. new SuperMap.Control.MousePosition(),
  45. new SuperMap.Control.OverviewMap(),
  46. new SuperMap.Control.Navigation({
  47. dragPanOptions: {
  48. enableKinetic: true
  49. }
  50. })],
  51. projection: new SuperMap.Projection("EPSG:3857")
  52. });
  53. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {transparent: true}, {
  54. useCanvas: true,
  55. maxResolution: "auto"
  56. });
  57. layer.events.on({"layerInitialized": addLayer});
  58. function addLayer() {
  59. var center = new SuperMap.LonLat(0, 0);
  60. map.addLayer(layer);
  61. map.setCenter(center, 1);
  62. }
  63. function loadKml() {
  64. if (!loaded) {
  65. layer01 = new SuperMap.Layer.Vector("KML", {
  66. strategies: [new SuperMap.Strategy.Fixed()],
  67. protocol: new SuperMap.Protocol.HTTP({
  68. url: host + "/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features.kml", //"data/sichuang.kml",
  69. format: new SuperMap.Format.KML({
  70. extractStyles: true,
  71. extractAttributes: true,
  72. internalProjection: new SuperMap.Projection("EPSG:3857"), //所在地图的坐标系
  73. maxDepth: 2 //要解析外部链接文件时此值必须大于1
  74. })
  75. })
  76. });
  77. map.addLayer(layer01);
  78. layer01.events.on({"featuresadded": featuresadd});
  79. loaded = true;
  80. }
  81. }
  82. function featuresadd() {
  83. var center = new SuperMap.LonLat(5000000, 8000000);
  84. map.setCenter(center, 1);
  85. }
  86. </script>
  87. </body>
  88. </html>