include-leaflet.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /* Copyright© 2000 - 2021 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://cdn.jsdelivr.net/npm/leaflet@1.7.1/dist/leaflet.css');
  53. inputScript('https://cdn.jsdelivr.net/npm/leaflet@1.7.1/dist/leaflet.js');
  54. }
  55. if (inArray(includes, 'leaflet.heat')) {
  56. inputScript('https://cdn.bootcss.com/leaflet.heat/0.2.0/leaflet-heat.js');
  57. }
  58. if (inArray(includes, 'leaflet.markercluster')) {
  59. inputCSS('https://cdn.bootcss.com/leaflet.markercluster/1.4.1/MarkerCluster.Default.css');
  60. inputCSS('https://cdn.bootcss.com/leaflet.markercluster/1.4.1/MarkerCluster.css');
  61. inputScript('https://cdn.bootcss.com/leaflet.markercluster/1.4.1/leaflet.markercluster.js');
  62. }
  63. if (inArray(includes, 'leaflet.draw')) {
  64. inputCSS('https://cdn.bootcss.com/leaflet.draw/1.0.4/leaflet.draw.css');
  65. inputScript('https://cdn.bootcss.com/leaflet.draw/1.0.4/leaflet.draw.js');
  66. }
  67. if (inArray(includes, 'leaflet-geoman')) {
  68. inputCSS('https://cdn.jsdelivr.net/npm/@geoman-io/leaflet-geoman-free@2.7.0/dist/leaflet-geoman.css');
  69. inputScript('https://cdn.jsdelivr.net/npm/@geoman-io/leaflet-geoman-free@2.7.0/dist/leaflet-geoman.min.js');
  70. }
  71. if (inArray(includes, 'leaflet.miniMap')) {
  72. inputCSS('https://cdn.bootcss.com/leaflet-minimap/3.6.1/Control.MiniMap.min.css');
  73. inputScript('https://cdn.bootcss.com/leaflet-minimap/3.6.1/Control.MiniMap.min.js');
  74. }
  75. if (inArray(includes, 'mapv')) {
  76. inputScript('https://cdn.jsdelivr.net/npm/mapv@2.0.56/build/mapv.min.js');
  77. }
  78. if (inArray(includes, 'turf')) {
  79. inputScript('https://cdn.bootcss.com/Turf.js/5.1.6/turf.min.js');
  80. }
  81. if (inArray(includes, 'echarts')) {
  82. inputScript('https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js');
  83. }
  84. if (inArray(includes, 'elasticsearch')) {
  85. inputScript('https://cdn.bootcss.com/elasticsearch/16.7.1/elasticsearch.js');
  86. }
  87. if (inArray(includes, 'xlsx')) {
  88. inputScript('https://cdn.jsdelivr.net/npm/xlsx@0.16.7/dist/xlsx.core.min.js');
  89. }
  90. // 本地
  91. if (inArray(includes, 'leaflet.sidebyside')) {
  92. inputScript(
  93. 'https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-side-by-side/leaflet-side-by-side.min.js'
  94. );
  95. }
  96. if (inArray(includes, 'd3')) {
  97. inputScript('https://cdn.bootcss.com/d3/6.1.1/d3.min.js');
  98. }
  99. if (inArray(includes, 'd3-hexbin')) {
  100. inputScript('https://d3js.org/d3-hexbin.v0.2.min.js');
  101. }
  102. if (inArray(includes, 'd3Layer')) {
  103. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet.d3Layer/leaflet-d3Layer.js');
  104. }
  105. if (inArray(includes, 'osmbuildings')) {
  106. inputScript('https://iclient.supermap.io/web/libs/osmbuildings/OSMBuildings-Leaflet.js');
  107. }
  108. if (inArray(includes, 'leaflet-icon-pulse')) {
  109. inputCSS('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-icon-pulse/L.Icon.Pulse.css');
  110. inputScript('https://iclient.supermap.io/web/libs/leaflet/plugins/leaflet-icon-pulse/L.Icon.Pulse.js');
  111. }
  112. if (inArray(includes, 'deck')) {
  113. inputScript('https://iclient.supermap.io/web/libs/deck.gl/5.1.3/deck.gl.min.js');
  114. }
  115. if (inArray(includes, 'pixi')) {
  116. inputScript('https://cdn.bootcss.com/pixi.js/4.8.7/pixi.js');
  117. inputScript('https://cdn.jsdelivr.net/npm/leaflet-pixi-overlay@1.8.1/L.PixiOverlay.min.js');
  118. inputScript(
  119. 'https://iclient.supermap.io/web/libs/leaflet/plugins/Leaflet.PixiOverlay/1.8.1/MarkerContainer.js'
  120. );
  121. inputScript('https://iclient.supermap.io/web/libs/bezier-easing/2.1.0/bezier-easing.js');
  122. }
  123. // iclient
  124. if (!inArray(excludes, 'iclient-leaflet')) {
  125. if (supportES6()) {
  126. inputScript('/static/maps/js/iclient-leaflet-es6.min.js');
  127. } else {
  128. inputScript('../../dist/leaflet/iclient-leaflet.min.js');
  129. }
  130. }
  131. if (inArray(includes, 'iclient-leaflet-css')) {
  132. inputCSS('../../dist/leaflet/iclient-leaflet.min.css');
  133. }
  134. if (inArray(includes, 'iclient-plot-leaflet')) {
  135. inputCSS('https://iclient.supermap.io/web/libs/plotting/leaflet/10.1.3/iclient-plot-leaflet.css');
  136. if (supportES6()) {
  137. inputScript(
  138. 'https://iclient.supermap.io/web/libs/plotting/leaflet/10.1.3/iclient-plot-leaflet-es6.min.js'
  139. );
  140. } else {
  141. inputScript('https://iclient.supermap.io/web/libs/plotting/leaflet/10.1.3/iclient-plot-leaflet.min.js');
  142. }
  143. }
  144. if (inArray(includes, 'ant-design-vue')) {
  145. inputCSS('https://cdn.jsdelivr.net/npm/ant-design-vue@1.3.9/dist/antd.min.css');
  146. inputScript('https://cdn.jsdelivr.net/npm/ant-design-vue@1.3.9/dist/antd.min.js');
  147. }
  148. if (inArray(includes, 'echarts-vue')) {
  149. inputScript('https://cdn.jsdelivr.net/npm/echarts@4.9.0/dist/echarts.min.js');
  150. inputScript('https://cdn.jsdelivr.net/npm/vue-echarts@4.1.0/dist/vue-echarts.min.js');
  151. inputScript('https://cdn.jsdelivr.net/npm/echarts-liquidfill@2.0.6/dist/echarts-liquidfill.min.js');
  152. inputScript('https://iclient.supermap.io/web/libs/echartsLayer/EchartsLayer.min.js');
  153. }
  154. if (inArray(includes, 'iclient-leaflet-vue')) {
  155. inputCSS('../../dist/leaflet/iclient-leaflet-vue.css');
  156. inputScript('../../dist/leaflet/iclient-leaflet-vue.min.js');
  157. }
  158. if (inArray(includes, 'leaflet-mapbox-gl')) {
  159. inputScript('https://cdn.jsdelivr.net/npm/mapbox-gl-leaflet@0.0.14/leaflet-mapbox-gl.js');
  160. }
  161. }
  162. load();
  163. window.isLocal = false;
  164. window.server = document.location.toString().match(/file:\/\//)
  165. ? 'http://localhost:8090'
  166. : document.location.protocol + '//' + document.location.host;
  167. })();