e22_weiVectorTile_geojson.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <!-- 2017-12-7 14:56:03 | 修改 木遥(微信: http://marsgis.cn/weixin.html ) -->
  2. <!DOCTYPE html>
  3. <html>
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  7. <meta name="apple-touch-fullscreen" content="yes" />
  8. <meta name="apple-mobile-web-app-capable" content="yes" />
  9. <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  10. <meta name="format-detection" content="telephone=no" />
  11. <meta name="x5-fullscreen" content="true" />
  12. <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />
  13. <!-- 标题及搜索关键字 -->
  14. <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  15. <meta
  16. name="description"
  17. content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型 gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包 地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
  18. />
  19. <link rel="shortcut icon" type="image/x-icon" href="" />
  20. <title>矢量瓦片方式加载GeoJson </title>
  21. <script
  22. type="text/javascript"
  23. src="../lib/include-lib.js"
  24. libpath="../lib/"
  25. include="jquery,font-awesome,bootstrap,layer,haoutil,turf,mars3d"
  26. ></script>
  27. <link href="css/style.css" rel="stylesheet" />
  28. </head>
  29. <body class="dark">
  30. <!--加载前进行操作提示,优化用户体验-->
  31. <div id="mask" class="signmask" onclick="removeMask()"></div>
  32. <div id="mars3dContainer" class="mars3d-container"></div>
  33. <!--需要引入额外的第3方插件js-->
  34. <script src="../lib/mars3d/thirdParty/weiVectorTile/CesiumVectorTile.min.js"></script>
  35. <script src="../lib/mars3d/thirdParty/weiVectorTile/WeiVectorTileLayer.js"></script>
  36. <script src="./js/common.js"></script>
  37. <script type="text/javascript">
  38. "use script"; //开发环境建议开启严格模式
  39. var map;
  40. function initMap(options) {
  41. //合并属性参数,可覆盖config.json中的对应配置
  42. var mapOptions = mars3d.Util.merge(options, {
  43. scene: {
  44. center: { lat: 27.689337, lng: 118.112448, alt: 762174, heading: 358, pitch: -62 },
  45. },
  46. });
  47. //创建三维地球场景
  48. map = new mars3d.Map("mars3dContainer", mapOptions);
  49. queryBJXLineData()
  50. .then(function (geojson) {
  51. showBJXLine(geojson.features[0]);
  52. })
  53. .catch(function () {
  54. haoutil.alert("Json文件加载失败!");
  55. });
  56. queryAreasData()
  57. .then(function (geojson) {
  58. showGeoJsonVectorTile(geojson);
  59. })
  60. .catch(function () {
  61. haoutil.alert("Json文件加载失败!");
  62. });
  63. }
  64. //获取安徽各市、边界线数据
  65. function queryAreasData() {
  66. return new Promise(function (resolve, reject) {
  67. //geojson 安徽各市
  68. $.ajax({
  69. type: "get",
  70. dataType: "json",
  71. url: "//data.mars3d.cn/file/geojson/areas/340000_full.json",
  72. success: function (result) {
  73. resolve(result);
  74. },
  75. error: function (data) {
  76. reject(data);
  77. },
  78. });
  79. });
  80. }
  81. function queryBJXLineData() {
  82. return new Promise(function (resolve, reject) {
  83. //geojson 安徽边界线
  84. $.ajax({
  85. type: "get",
  86. dataType: "json",
  87. url: "//data.mars3d.cn/file/geojson/areas/340000.json",
  88. success: function (result) {
  89. resolve(result);
  90. },
  91. error: function (data) {
  92. reject(data);
  93. },
  94. });
  95. });
  96. }
  97. //API文档,参考lib\mars3d\thirdParty\weiVectorTile\Document.rar(解压Document.rar)
  98. function showGeoJsonVectorTile(geojson) {
  99. var tileLayer = new mars3d.layer.WeiVectorTileLayer({
  100. source: geojson,
  101. zIndex: 2,
  102. removeDuplicate: false,
  103. allowPick: true, //允许单击
  104. defaultStyle: {
  105. //参考api文档的Cesium.VectorStyle类
  106. tileCacheSize: 200,
  107. fill: true, //是否填充,仅面数据有效。
  108. fillColor: "rgba(0,255,255,0.1)",
  109. outline: true, //是否显示边,仅面数据有效。
  110. outlineColor: "rgba(138,138,138,1)",
  111. lineWidth: 2,
  112. showMaker: false,
  113. showCenterLabel: true, //是否显示文本,仅对线和面数据有效
  114. centerLabelPropertyName: "name",
  115. fontColor: "rgba(255,255,255,1)",
  116. fontSize: 23,
  117. fontFamily: "楷体",
  118. labelOffsetX: -10,
  119. labelOffsetY: -5,
  120. },
  121. minimumLevel: 1,
  122. maximumLevel: 20,
  123. simplify: false,
  124. styleFilter: function (feature, style, x, y, level) {
  125. if (level < 6) {
  126. style.fontSize = level * 2;
  127. } else {
  128. style.fontSize = 23;
  129. }
  130. if (feature.properties && feature.properties.name && feature.properties.name == "合肥市") {
  131. style.fillColor = Cesium.Color.YELLOW.withAlpha(0.2);
  132. }
  133. return style;
  134. },
  135. //以下为mars3d参数,API参考http://mars3d.cn/api/BaseTileLayer.html#.ConstructorOptions
  136. popup: "all",
  137. });
  138. map.addLayer(tileLayer);
  139. }
  140. function showBJXLine(feature) {
  141. // console.log('边界线', feature)
  142. //缓冲区
  143. var bufferedOuter = turf.buffer(feature, 2000, {
  144. units: "meters",
  145. });
  146. var bufferedInner = turf.buffer(feature, 1000, {
  147. units: "meters",
  148. });
  149. bufferedInner = turf.difference(bufferedInner, feature);
  150. bufferedOuter = turf.difference(bufferedOuter, bufferedInner);
  151. bufferedInner = turf.featureCollection([bufferedInner]);
  152. bufferedOuter = turf.featureCollection([bufferedOuter]);
  153. var tileLayer = new mars3d.layer.WeiVectorTileLayer({
  154. source: bufferedOuter,
  155. zIndex: 99,
  156. removeDuplicate: false,
  157. defaultStyle: {
  158. outlineColor: "rgba(209,204,226,1)",
  159. lineWidth: 2,
  160. outline: true,
  161. fill: true,
  162. fillColor: "rgba(209,204,226,1)",
  163. tileCacheSize: 200,
  164. showMaker: false,
  165. showCenterLabel: false,
  166. },
  167. maximumLevel: 20,
  168. minimumLevel: 5,
  169. simplify: false,
  170. });
  171. map.addLayer(tileLayer);
  172. var tileLayer2 = new mars3d.layer.WeiVectorTileLayer({
  173. source: bufferedInner,
  174. zIndex: 99,
  175. removeDuplicate: false,
  176. defaultStyle: {
  177. outlineColor: "rgba(185,169,199,1)",
  178. lineWidth: 2,
  179. outline: true,
  180. fill: true,
  181. fillColor: "rgba(185,169,199,1)",
  182. tileCacheSize: 200,
  183. showMaker: false,
  184. showCenterLabel: false,
  185. },
  186. maximumLevel: 20,
  187. minimumLevel: 5,
  188. simplify: false,
  189. });
  190. map.addLayer(tileLayer2);
  191. }
  192. </script>
  193. </body>
  194. </html>