include-leaflet.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* Copyright© 2000 - 2022 SuperMap Software Co.Ltd. All rights reserved.
  2. * This program are made available under the terms of the Apache License, Version 2.0
  3. * which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
  4. (function () {
  5. var r = new RegExp('(^|(.*?\\/))(include-leaflet.js)(\\?|$)'),
  6. s = document.getElementsByTagName('script'),
  7. targetScript;
  8. for (var i = 0; i < s.length; i++) {
  9. var src = s[i].getAttribute('src');
  10. if (src) {
  11. var m = src.match(r);
  12. if (m) {
  13. targetScript = s[i];
  14. break;
  15. }
  16. }
  17. }
  18. function inputScript(url) {
  19. var script = '<script type="text/javascript" src="' + url + '"><' + '/script>';
  20. document.writeln(script);
  21. }
  22. function inputCSS(url) {
  23. var css = '<link rel="stylesheet" href="' + url + '">';
  24. document.writeln(css);
  25. }
  26. function inArray(arr, item) {
  27. for (i in arr) {
  28. if (arr[i] == item) {
  29. return true;
  30. }
  31. }
  32. return false;
  33. }
  34. function supportES6() {
  35. var code = "'use strict'; class Foo {}; class Bar extends Foo {};";
  36. try {
  37. new Function(code)();
  38. } catch (err) {
  39. return false;
  40. }
  41. if (!Array.from) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. //加载类库资源文件
  47. function load() {
  48. var includes = (targetScript.getAttribute('include') || '').split(',');
  49. var excludes = (targetScript.getAttribute('exclude') || '').split(',');
  50. // 在线
  51. if (!inArray(excludes, 'leaflet')) {
  52. inputCSS('https://iclient.supermap.io/web/libs/leaflet/1.7.1/leaflet.css');
  53. inputScript('https://iclient.supermap.io/web/libs/leaflet/1.7.1/leaflet.js');
  54. }
  55. if (inArray(includes, 'mapbox-gl-enhance')) {
  56. inputCSS('https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.0/mapbox-gl-enhance.css');
  57. inputScript('https://iclient.supermap.io/web/libs/mapbox-gl-js-enhance/1.12.0/mapbox-gl-enhance.js');
  58. }
  59. if (inArray(includes, 'leaflet.heat')) {
  60. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.heat/leaflet-heat.js');
  61. }
  62. if (inArray(includes, 'leaflet.markercluster')) {
  63. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.markercluster/1.5.3/MarkerCluster.Default.css');
  64. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.markercluster/1.5.3/MarkerCluster.css');
  65. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.markercluster/1.5.3/leaflet.markercluster.js');
  66. }
  67. if (inArray(includes, 'leaflet.draw')) {
  68. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.draw/1.0.4/leaflet.draw.css');
  69. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.draw/1.0.4/leaflet.draw.js');
  70. }
  71. if (inArray(includes, 'leaflet-geoman')) {
  72. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-geoman/2.11.3/leaflet-geoman.css');
  73. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-geoman/2.11.3/leaflet-geoman.min.js');
  74. }
  75. if (inArray(includes, 'leaflet.miniMap')) {
  76. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-miniMap/3.6.1/dist/Control.MiniMap.min.css');
  77. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-miniMap/3.6.1/dist/Control.MiniMap.min.js');
  78. }
  79. if (inArray(includes, 'mapv')) {
  80. inputScript('https://iclient.supermap.io/web/libs/mapv/2.0.62/mapv.min.js');
  81. }
  82. if (inArray(includes, 'turf')) {
  83. inputScript('https://iclient.supermap.io/web/libs/turf/6.5.0/turf.min.js');
  84. }
  85. if (inArray(includes, 'echarts')) {
  86. inputScript('https://iclient.supermap.io/web/libs/echarts/4.9.0/echarts.min.js');
  87. }
  88. if (inArray(includes, 'elasticsearch')) {
  89. inputScript('https://iclient.supermap.io/web/libs/elasticsearch/16.7.3/elasticsearch.min.js');
  90. }
  91. if (inArray(includes, 'xlsx')) {
  92. inputScript('https://iclient.supermap.io/web/libs/xlsx/0.18.5/xlsx.core.min.js');
  93. }
  94. // 本地
  95. if (inArray(includes, 'leaflet.sidebyside')) {
  96. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-side-by-side/leaflet-side-by-side.min.js');
  97. }
  98. if (inArray(includes, 'd3')) {
  99. inputScript('https://iclient.supermap.io/web/libs/d3/7.4.4/d3.min.js');
  100. }
  101. if (inArray(includes, 'd3-hexbin')) {
  102. inputScript('https://iclient.supermap.io/web/libs/d3/d3-hexbin.v0.2.min.js');
  103. }
  104. if (inArray(includes, 'd3Layer')) {
  105. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.d3Layer/leaflet-d3Layer.js');
  106. }
  107. if (inArray(includes, 'osmbuildings')) {
  108. inputScript('https://iclient.supermap.io/web/libs/osmbuildings/OSMBuildings-Leaflet.js');
  109. }
  110. if (inArray(includes, 'leaflet-icon-pulse')) {
  111. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-icon-pulse/L.Icon.Pulse.css');
  112. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-icon-pulse/L.Icon.Pulse.js');
  113. }
  114. if (inArray(includes, 'deck')) {
  115. inputScript('https://iclient.supermap.io/web/libs/deck.gl/5.1.3/deck.gl.min.js');
  116. }
  117. if (inArray(includes, 'pixi')) {
  118. inputScript('https://iclient.supermap.io/web/libs/pixi/4.8.7/pixi.min.js');
  119. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/Leaflet.PixiOverlay/1.8.2/L.PixiOverlay.min.js');
  120. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/Leaflet.PixiOverlay/MarkerContainer.js');
  121. inputScript('https://iclient.supermap.io/web/libs/bezier-easing/2.1.0/bezier-easing.js');
  122. }
  123. if (inArray(includes, 'tensorflow')) {
  124. inputScript('https://iclient.supermap.io/web/libs/tensorflow/3.9.0/tf.min.js');
  125. }
  126. // iclient
  127. if (!inArray(excludes, 'iclient-leaflet')) {
  128. if (supportES6()) {
  129. inputScript('../../dist/leaflet/iclient-leaflet-es6.min.js');
  130. } else {
  131. inputScript('../../dist/leaflet/iclient-leaflet.min.js');
  132. }
  133. }
  134. if (inArray(includes, 'iclient-leaflet-css')) {
  135. inputCSS('../../dist/leaflet/iclient-leaflet.min.css');
  136. }
  137. if (inArray(includes, 'iclient-plot-leaflet')) {
  138. inputCSS('https://iclient.supermap.io/web/libs/plotting/leaflet/11.0.1/iclient-plot-leaflet.css');
  139. if (supportES6()) {
  140. inputScript('https://iclient.supermap.io/web/libs/plotting/leaflet/11.0.1/iclient-plot-leaflet-es6.min.js');
  141. } else {
  142. inputScript('https://iclient.supermap.io/web/libs/plotting/leaflet/11.0.1/iclient-plot-leaflet.min.js');
  143. }
  144. }
  145. if (inArray(includes, 'ant-design-vue')) {
  146. inputCSS('https://iclient.supermap.io/web/libs/ant-design-vue/1.7.8/antd.min.css');
  147. inputScript('https://iclient.supermap.io/web/libs/ant-design-vue/1.7.8/antd.min.js');
  148. }
  149. if (inArray(includes, 'echarts-vue')) {
  150. inputScript('https://iclient.supermap.io/web/libs/echarts/4.9.0/echarts.min.js');
  151. inputScript('https://iclient.supermap.io/web/libs/vue-echarts/4.1.0/vue-echarts.min.js');
  152. inputScript('https://iclient.supermap.io/web/libs/echarts-liquidfill/2.0.6/echarts-liquidfill.min.js');
  153. inputScript('https://iclient.supermap.io/web/libs/echartsLayer/EchartsLayer.min.js');
  154. }
  155. if (inArray(includes, 'iclient-leaflet-vue')) {
  156. inputCSS('../../dist/leaflet/iclient-leaflet-vue.css');
  157. inputScript('../../dist/leaflet/iclient-leaflet-vue.min.js');
  158. }
  159. if (inArray(includes, 'leaflet-mapbox-gl')) {
  160. inputScript('https://iclient.supermap.io/web/libs/leaflet-mapbox-gl/0.0.15/leaflet-mapbox-gl.min.js');
  161. }
  162. }
  163. load();
  164. window.isLocal = false;
  165. window.server = document.location.toString().match(/file:\/\//)
  166. ? 'http://localhost:8090'
  167. : document.location.protocol + '//' + document.location.host;
  168. })();