components_timeline_ncp.html 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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_componentsTimeLineNcp_Vue"></title>
  9. <script type="text/javascript" include="vue,jquery,papaparse" src="../js/include-web.js"></script>
  10. <script
  11. include="moment,echarts-vue,iclient-mapboxgl-vue,mapbox-gl-enhance"
  12. src="../../dist/mapboxgl/include-mapboxgl.js"
  13. ></script>
  14. <style>
  15. #main {
  16. display: inline-flex;
  17. margin: 0 auto;
  18. width: 100%;
  19. height: 100%;
  20. }
  21. .sm-component-time-line {
  22. position: absolute;
  23. bottom: 0px;
  24. width: 100%;
  25. z-index: 1000;
  26. }
  27. .sm-left-part {
  28. display: inline-block;
  29. width: 55%;
  30. height: 100%;
  31. }
  32. .sm-right-part {
  33. display: inline-block;
  34. width: 44.5%;
  35. height: 100%;
  36. margin-left: 0.5%;
  37. }
  38. .sm-right-part__top {
  39. position: relative;
  40. height: 45%;
  41. background: transparent;
  42. }
  43. .sm-right-part__bottom {
  44. position: relative;
  45. height: 54.5%;
  46. margin-top: 0.5%;
  47. background: transparent;
  48. }
  49. .sm-left-header {
  50. position: relative;
  51. display: inline-block;
  52. width: 100%;
  53. }
  54. .sm-left-header .sm-component-image {
  55. position: absolute;
  56. }
  57. .sm-left-header__title {
  58. width: 100%;
  59. }
  60. .sm-left-header__title .sm-component-text {
  61. display: flex;
  62. width: 100%;
  63. }
  64. .sm-left-content {
  65. position: relative;
  66. width: 100%;
  67. height: calc(100% - 100px);
  68. margin-top: 20px;
  69. }
  70. .sm-left-content .sm-component-text {
  71. position: absolute;
  72. top: 10px;
  73. z-index: 1000;
  74. }
  75. .sm-right-part__top .sm-component-web-map,
  76. .sm-component-chart {
  77. position: absolute;
  78. bottom: 0;
  79. width: 100%;
  80. height: calc(100% - 130px);
  81. }
  82. .sm-component-chart .sm-component-collapse-card__content {
  83. width: 100%;
  84. height: 100%;
  85. }
  86. .sm-right-part__top .sm-component-time-text {
  87. position: absolute;
  88. top: 0;
  89. right: 5px;
  90. z-index: 1000;
  91. }
  92. .sm-total-indicators {
  93. position: absolute;
  94. top: 50px;
  95. display: inline-flex;
  96. justify-content: space-between;
  97. width: 450px;
  98. margin-top: 10px;
  99. z-index: 1000;
  100. }
  101. .sm-total-indicator {
  102. width: 140px;
  103. height: 84px;
  104. }
  105. .sm-total-indicator .sm-component-indicator {
  106. width: 100%;
  107. }
  108. .sm-total-indicator .sm-component-image__content {
  109. background-size: 100% 100% !important;
  110. }
  111. .sm-indicators {
  112. position: absolute;
  113. left: 10px;
  114. top: 50px;
  115. display: inline-flex;
  116. justify-content: space-between;
  117. align-items: center;
  118. width: calc(100% - 20px);
  119. height: 70px;
  120. z-index: 1000;
  121. }
  122. .sm-indicator {
  123. display: inline-flex;
  124. justify-content: space-around;
  125. width: 180px;
  126. height: 100%;
  127. background: #1c2027;
  128. }
  129. </style>
  130. </head>
  131. <body style=" margin: 0;overflow: hidden;background: #000000;width: 100%;height:100%;position: absolute;top: 0;">
  132. <div id="main">
  133. <sm-border type="border6" class="sm-left-part">
  134. <div>
  135. <div class="sm-left-header">
  136. <sm-image
  137. src="./img/ncp/superMap.png"
  138. repeat="center"
  139. style="width:140px;height:50px"
  140. ></sm-image>
  141. <div class="sm-left-header__title">
  142. <sm-text
  143. title="全国新型冠状病毒感染的肺炎疫情分布"
  144. :font-style='{ fontSize: "27px", fontWeight: 700, textAlign: "center"}'
  145. ></sm-text>
  146. <sm-text
  147. title="截至2020年4月2日24时(数据来源:国家与地方卫健委官网)"
  148. :font-style='{ textAlign: "center"}'
  149. text-color="#C8BFBF"
  150. ></sm-text>
  151. </div>
  152. </div>
  153. <div class="sm-left-content">
  154. <sm-web-map
  155. server-url="https://www.supermapol.com"
  156. :map-id="1312968431"
  157. target="map_1"
  158. :map-options="mapOptions"
  159. @load="load"
  160. ></sm-web-map>
  161. <sm-text :title="timeInfo" :font-style="{fontSize: '20px', fontWeight: 600}"></sm-text>
  162. <div class="sm-total-indicators">
  163. <div class="sm-total-indicator">
  164. <sm-image src="./img/ncp/red.png" style="width:140px;height:8px"></sm-image>
  165. <sm-indicator
  166. title="新增确诊"
  167. unit=""
  168. :num="totalConfirmedAdd"
  169. indicator-color="#79BC45"
  170. text-font-size="14px"
  171. font-size="30px"
  172. ></sm-indicator>
  173. </div>
  174. <div class="sm-total-indicator">
  175. <sm-image src="./img/ncp/yellow.png" style="width:140px;height:8px"></sm-image>
  176. <sm-indicator
  177. title="现有确诊"
  178. unit=""
  179. :num="totalConfirmedNow"
  180. indicator-color="#F24B3D"
  181. text-font-size="14px"
  182. font-size="30px"
  183. ></sm-indicator>
  184. </div>
  185. <div class="sm-total-indicator">
  186. <sm-image src="./img/ncp/green.png" style="width:140px;height:8px"></sm-image>
  187. <sm-indicator
  188. title="疑似病例"
  189. unit=""
  190. :num="totalSuspected"
  191. indicator-color="#79BC45"
  192. text-font-size="14px"
  193. font-size="30px"
  194. ></sm-indicator>
  195. </div>
  196. </div>
  197. <sm-time-line
  198. :data="data"
  199. :play-interval="1000"
  200. :label="label"
  201. :control-style="timeLineStyle"
  202. :checkpoint-style="timeLineStyle"
  203. @timelinechanged="timelineChanged"
  204. ></sm-time-line>
  205. </div>
  206. </div>
  207. </sm-border>
  208. <div class="sm-right-part">
  209. <sm-border type="border6" class="sm-right-part__top">
  210. <div>
  211. <sm-text
  212. title="全省疫情监控"
  213. :font-style='{ fontSize: "22px", fontWeight: 700}'
  214. text-color="#e9e9e9"
  215. ></sm-text>
  216. <sm-time-text :font-style='{ fontSize: "14px"}' time-type="date+second"> </sm-time-text>
  217. <div class="sm-indicators">
  218. <div class="sm-indicator">
  219. <sm-image src="./img/ncp/icon-red.png" style="width:40px;height:100%"></sm-image>
  220. <sm-indicator
  221. title="新增确诊"
  222. unit=""
  223. :num="confirmedAdd"
  224. indicator-color="#FB016D"
  225. text-font-size="14px"
  226. font-size="24px"
  227. ></sm-indicator>
  228. </div>
  229. <div class="sm-indicator">
  230. <sm-image src="./img/ncp/icon-yellow.png" style="width:40px;height:100%"></sm-image>
  231. <sm-indicator
  232. title="现有确诊"
  233. unit=""
  234. :num="nowConfirmed"
  235. indicator-color="#FEAD00"
  236. text-font-size="14px"
  237. font-size="24px"
  238. ></sm-indicator>
  239. </div>
  240. <div class="sm-indicator">
  241. <sm-image src="./img/ncp/icon-green.png" style="width:40px;height:100%"></sm-image>
  242. <sm-indicator
  243. title="疑似病例"
  244. unit=""
  245. :num="suspectedAdd"
  246. indicator-color="#5AFBAE"
  247. text-font-size="14px"
  248. font-size="24px"
  249. ></sm-indicator>
  250. </div>
  251. </div>
  252. <sm-web-map
  253. server-url="https://www.supermapol.com"
  254. :map-id="558388156"
  255. target="map_2"
  256. :map-options="mapOptions2"
  257. @load="load1"
  258. ></sm-web-map>
  259. </div>
  260. </sm-border>
  261. <sm-border type="border6" class="sm-right-part__bottom">
  262. <div>
  263. <sm-text
  264. title="市区疫情监控"
  265. :font-style='{ fontSize: "22px", fontWeight: 700}'
  266. text-color="#e9e9e9"
  267. ></sm-text>
  268. <div class="sm-indicators">
  269. <div class="sm-indicator">
  270. <sm-image src="./img/ncp/icon-red.png" style="width:40px;height:100%"></sm-image>
  271. <sm-indicator
  272. title="新增确诊"
  273. unit=""
  274. :num="confirmedAdd"
  275. indicator-color="#FB016D"
  276. text-font-size="14px"
  277. font-size="24px"
  278. ></sm-indicator>
  279. </div>
  280. <div class="sm-indicator">
  281. <sm-image src="./img/ncp/icon-yellow.png" style="width:40px;height:100%"></sm-image>
  282. <sm-indicator
  283. title="现有确诊"
  284. unit=""
  285. :num="nowConfirmed"
  286. indicator-color="#FEAD00"
  287. text-font-size="14px"
  288. font-size="24px"
  289. ></sm-indicator>
  290. </div>
  291. <div class="sm-indicator">
  292. <sm-image src="./img/ncp/icon-green.png" style="width:40px;height:100%"></sm-image>
  293. <sm-indicator
  294. title="疑似病例"
  295. unit=""
  296. :num="suspectedAdd"
  297. indicator-color="#5AFBAE"
  298. text-font-size="14px"
  299. font-size="24px"
  300. ></sm-indicator>
  301. </div>
  302. </div>
  303. <sm-chart
  304. icon-class=""
  305. v-bind="options"
  306. :dataset="dataset"
  307. :dataset-options="datasetOptions"
  308. :options="options"
  309. :color-group="colorGroup"
  310. ></sm-chart>
  311. </div>
  312. </sm-border>
  313. </div>
  314. </div>
  315. <script>
  316. new Vue({
  317. el: '#main',
  318. data() {
  319. var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
  320. var attribution =
  321. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  322. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  323. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  324. return {
  325. data: [],
  326. colorGroup: ['#d53e4f', '#fc8d59', '#fee08b', '#ffffbf', '#e6f598'],
  327. datasetOptions: [
  328. {
  329. seriesType: 'line',
  330. isStastic: false,
  331. isStack: false,
  332. xField: 'name',
  333. yField: 'confirmedAdd',
  334. sort: 'descending'
  335. }
  336. ],
  337. dataset: {
  338. maxFeatures: 20,
  339. url: '',
  340. type: 'geoJSON',
  341. geoJSON: {
  342. type: 'FeatureCollection',
  343. features: []
  344. }
  345. },
  346. options: {
  347. series: [
  348. {
  349. data: ['3900', '3340', '3300', '2500', '2000', '520', '100'],
  350. name: 'Y1',
  351. emphasis: { itemStyle: {} },
  352. stack: 0,
  353. type: 'line',
  354. smooth: true,
  355. animationEasing: 'quadraticIn',
  356. animationEasingUpdate: 'quadraticIn',
  357. label: {
  358. normal: {
  359. position: 'top',
  360. show: true,
  361. textStyle: { color: '#d53e4f', fontSize: 12 },
  362. smart: true
  363. }
  364. },
  365. lineStyle: { color: '#d53e4f' },
  366. itemStyle: { borderColor: '#d53e4f', color: '#d53e4f' },
  367. symbol: 'circle',
  368. areaStyle: { opacity: 0.7 }
  369. }
  370. ],
  371. yAxis: {
  372. axisLabel: {
  373. rotate: 0,
  374. fontFamily: 'MicrosoftYaHei',
  375. show: true,
  376. color: '#fff',
  377. fontSize: 12
  378. },
  379. axisLine: { lineStyle: {} },
  380. name: '',
  381. show: true,
  382. splitLine: {
  383. lineStyle: { width: 0.3, type: 'solid', color: '#ccc', opacity: 1 },
  384. show: true
  385. },
  386. splitArea: { show: false },
  387. nameGap: 5,
  388. nameLocation: 'end',
  389. type: 'value',
  390. nameTextStyle: { padding: [0, 0, 5, 0] },
  391. axisTick: { show: true }
  392. },
  393. xAxis: {
  394. axisLabel: {
  395. rotate: 47,
  396. fontFamily: 'MicrosoftYaHei',
  397. show: true,
  398. color: '#fff',
  399. fontSize: 12
  400. },
  401. data: ['Fri', 'Thu', 'Sat', 'Sun', 'Wed', 'Tue', 'Mon'],
  402. axisLine: { lineStyle: {} },
  403. show: true,
  404. name: '',
  405. axisTick: { alignWithLabel: true, show: true },
  406. splitLine: {
  407. lineStyle: { type: 'solid', color: '#ccc', opacity: 1, width: 0.3 },
  408. show: false
  409. },
  410. nameGap: 2,
  411. nameLocation: 'end',
  412. type: 'category',
  413. boundaryGap: false
  414. },
  415. grid: { top: 20, left: 43, bottom: 77, right: 20 },
  416. legend: {
  417. data: ['confirmedAdd'],
  418. show: false,
  419. textStyle: { color: '#fff', fontSize: 12 },
  420. type: 'scroll',
  421. top: 'top',
  422. left: 'center'
  423. },
  424. tooltip: {
  425. axisPointer: { shadowStyle: {}, type: 'line' },
  426. trigger: 'axis',
  427. textStyle: { align: 'left' }
  428. },
  429. textStyle: { fontFamily: 'Microsoft YaHei Light' },
  430. title: {
  431. padding: [5, 0, 0, 20],
  432. x: 'left',
  433. text: '',
  434. textStyle: { fontFamily: 'Microsoft YaHei Light', fontWeight: '100' }
  435. },
  436. dataZoom: []
  437. },
  438. label: {
  439. color: '#EF6548',
  440. borderColor: '#EF6548',
  441. formatter: function(val, index) {
  442. var timestamp = val;
  443. return moment(timestamp * 1000).format('YYYY-MM-DD');
  444. }
  445. },
  446. timeLineStyle: {
  447. color: '#EF6548',
  448. borderColor: '#EF6548'
  449. },
  450. mapOptions: {
  451. style: { version: 8, sources: {}, layers: [] },
  452. center: [106.9163, 37.2424],
  453. zoom: 3,
  454. bearing: 0,
  455. pitch: 0
  456. },
  457. mapOptions2: {
  458. style: { version: 8, sources: {}, layers: [] },
  459. center: [112.7597, 31.1603],
  460. zoom: 4.63,
  461. bearing: 0,
  462. pitch: 0,
  463. preserveDrawingBuffer: true
  464. },
  465. layersIdField: { self_layers_ProviceDataWithNcp: 'provinceName' },
  466. timeInfo: '2020-04-02',
  467. totalConfirmedAdd: 399,
  468. totalConfirmedNow: 53371,
  469. totalSuspected: 1361,
  470. confirmedAdd: 366,
  471. nowConfirmed: 47547,
  472. suspectedAdd: 1125
  473. };
  474. },
  475. created() {
  476. SuperMap.Components.setTheme({ textColor: '#fff', background: 'rgb(0,0,0,0)' });
  477. var _this = this;
  478. this.requestData('../data/ncp/ncpTotal.json', function(res) {
  479. _this.ncpTotal = res;
  480. });
  481. this.requestData('../data/ncp/ncpProperties.json', function(res) {
  482. _this.ncpProperties = res;
  483. _this.data = _this.getTimeStamps(res);
  484. _this.timelineChanged({ currentIndex: 0 });
  485. });
  486. this.requestData('https://www.supermapol.com/web/maps/1312968431/map.json', function(res) {
  487. _this.layerInfo = res.layers[0];
  488. });
  489. this.requestData('https://www.supermapol.com/web/maps/558388156/map.json', function(res) {
  490. _this.layerInfo1 = res.layers[0];
  491. });
  492. },
  493. mounted() {},
  494. methods: {
  495. load(e, vm) {
  496. this.map = e.map;
  497. },
  498. load1(e, vm) {
  499. this.map1 = e.map;
  500. },
  501. requestData(url = '../data/ncp/ncpTotal.json', cb) {
  502. var _this = this;
  503. $.get(url, function(res) {
  504. cb(res);
  505. });
  506. },
  507. timelineChanged(val) {
  508. var currentIndex = val.currentIndex;
  509. var timestamp = this.data[currentIndex];
  510. var geoJSON = this.getNcpFeatures(this.ncpProperties, timestamp);
  511. this.timeInfo = this.timestamp2Date(timestamp);
  512. this.dataset.geoJSON = geoJSON;
  513. this.setIndicatorNum(timestamp);
  514. this.updateSourceData(
  515. this.map,
  516. 'ProviceDataWithNcp',
  517. this.layerInfo,
  518. geoJSON.features,
  519. 'provinceName'
  520. );
  521. this.updateSourceData(
  522. this.map1,
  523. 'ProviceDataWithNcp',
  524. this.layerInfo1,
  525. geoJSON.features,
  526. 'provinceName'
  527. );
  528. },
  529. setIndicatorNum(timestamp) {
  530. var ncpProperties = this.ncpProperties[timestamp];
  531. var hubeiInfo = this.getProvinceInfo(ncpProperties, '湖北');
  532. this.confirmedAdd = hubeiInfo.properties.confirmedAdd;
  533. this.suspectedAdd = hubeiInfo.properties.suspectedAdd;
  534. this.nowConfirmed = hubeiInfo.properties.nowConfirmed;
  535. var ncpTotal = this.ncpTotal[timestamp][0];
  536. this.totalConfirmedAdd = ncpTotal.properties.confirmedAdd;
  537. this.totalSuspected = ncpTotal.properties.suspectedAdd;
  538. this.totalConfirmedNow = ncpTotal.properties.nowConfirmed;
  539. },
  540. getProvinceInfo(data, provinceName) {
  541. var hubeiInfo = data.find(function(item) {
  542. return item.properties.provinceName === provinceName;
  543. }) || { properties: {} };
  544. return hubeiInfo;
  545. },
  546. timestamp2Date(timestamp) {
  547. return timestamp ? moment(timestamp * 1000).format('YYYY-MM-DD HH:mm:ss') : '';
  548. },
  549. date2Timestamp(date) {
  550. return moment(date, 'YYYY-MM-DD HH:mm:ss').valueOf() / 1000;
  551. },
  552. getTimeStamps(ncpData) {
  553. var data = [];
  554. for (var timestamp in ncpData) {
  555. data.push(timestamp);
  556. }
  557. return data;
  558. },
  559. getNcpFeatures(data, timestamp) {
  560. var features = data[timestamp];
  561. return {
  562. type: 'FeatureCollection',
  563. features: features
  564. };
  565. },
  566. updateSourceData(map, sourceId, layerInfo, features, mergeByField) {
  567. if (map && map.getSource(sourceId)) {
  568. var newFeatures = this.mergeFeatures(sourceId, features, mergeByField);
  569. map.getSource(sourceId).setData({
  570. type: 'FeatureCollection',
  571. features: newFeatures
  572. });
  573. var expression = this.getExpression(layerInfo, newFeatures);
  574. // 获取样式
  575. var layerStyle = {
  576. layout: {}
  577. };
  578. layerStyle.layout.visibility = layerInfo.visible;
  579. var featureType = layerInfo.featureType;
  580. var paint = this.transformStyleToMapBoxGl(layerInfo.style, featureType, expression);
  581. for (var key in paint) {
  582. map.setPaintProperty(sourceId, key, paint[key]);
  583. }
  584. }
  585. },
  586. mergeFeatures(layerId, features, mergeByField) {
  587. features = features.map(function(feature, index) {
  588. if (!feature.properties.hasOwnProperty('index')) {
  589. feature.properties.index = index;
  590. }
  591. return feature;
  592. });
  593. if (!mergeByField) {
  594. return features;
  595. }
  596. var source = this.map.getSource(layerId);
  597. if (!source || !source._data.features) {
  598. return features;
  599. }
  600. var prevFeatures = source._data.features;
  601. var nextFeatures = [];
  602. features.forEach(feature => {
  603. var prevFeature = prevFeatures.find(item => {
  604. if (isNaN(+item.properties[mergeByField]) && isNaN(+feature.properties[mergeByField])) {
  605. return (
  606. JSON.stringify(item.properties[mergeByField] || '') ===
  607. JSON.stringify(feature.properties[mergeByField] || '')
  608. );
  609. } else {
  610. return +item.properties[mergeByField] === +feature.properties[mergeByField];
  611. }
  612. });
  613. if (prevFeature) {
  614. nextFeatures.push({
  615. ...prevFeature,
  616. ...feature
  617. });
  618. } else if (feature.geometry) {
  619. nextFeatures.push(feature);
  620. }
  621. });
  622. return nextFeatures;
  623. },
  624. getExpression(layerInfo, features) {
  625. var fieldName = layerInfo.themeSetting.themeField;
  626. var featureType = layerInfo.featureType;
  627. var styleGroups = this.getRangeStyleGroup(layerInfo, features);
  628. var expression = ['match', ['get', 'index']];
  629. var datas = features.filter((row, index, arr) => {
  630. var tartget = parseFloat(row.properties[fieldName]);
  631. if (!tartget && tartget !== 0) {
  632. return false;
  633. }
  634. if (styleGroups) {
  635. for (var i = 0; i < styleGroups.length; i++) {
  636. if (styleGroups[i].start <= tartget && tartget < styleGroups[i].end) {
  637. expression.push(row.properties['index'], styleGroups[i].color);
  638. break;
  639. }
  640. }
  641. }
  642. return true;
  643. }, this);
  644. expression.push('rgba(255, 255, 255, 1)');
  645. return expression;
  646. },
  647. getRangeStyleGroup(layerInfo, features) {
  648. var featureType = layerInfo.featureType;
  649. var style = layerInfo.style;
  650. var themeSetting = layerInfo.themeSetting;
  651. var customSettings = themeSetting.customSettings;
  652. var themeField = themeSetting.themeField;
  653. var segmentMethod = themeSetting.segmentMethod;
  654. var colors = themeSetting.colors;
  655. var segmentCount = themeSetting.segmentCount;
  656. var values = [];
  657. var attributes;
  658. features.forEach(feature => {
  659. attributes = feature.properties;
  660. if (attributes) {
  661. var val = attributes[themeField];
  662. (val || val === 0) && Number(+val) && values.push(parseFloat(val));
  663. }
  664. }, this);
  665. var segements = SuperMap.ArrayStatistic.getArraySegments(values, segmentMethod, segmentCount);
  666. if (segements) {
  667. var itemNum = segmentCount;
  668. if (attributes && segements[0] === segements[attributes.length - 1]) {
  669. itemNum = 1;
  670. segements.length = 2;
  671. }
  672. for (var i = 0; i < segements.length; i++) {
  673. var value = segements[i];
  674. value = i === 0 ? Math.floor(value * 100) / 100 : Math.ceil(value * 100) / 100 + 0.1; // 加0.1 解决最大值没有样式问题
  675. segements[i] = Number(value.toFixed(2));
  676. }
  677. var curentColors = colors;
  678. curentColors = SuperMap.ColorsPickerUtil.getGradientColors(curentColors, itemNum, 'RANGE');
  679. for (var index = 0; index < itemNum; index++) {
  680. if (index in customSettings) {
  681. if (customSettings[index]['segment']['start']) {
  682. segements[index] = customSettings[index]['segment']['start'];
  683. }
  684. if (customSettings[index]['segment']['end']) {
  685. segements[index + 1] = customSettings[index]['segment']['end'];
  686. }
  687. }
  688. }
  689. var styleGroups = [];
  690. for (var i = 0; i < itemNum; i++) {
  691. var color = curentColors[i];
  692. if (i in customSettings) {
  693. if (customSettings[i].color) {
  694. color = customSettings[i].color;
  695. }
  696. }
  697. style.fillColor = color;
  698. var start = segements[i];
  699. var end = segements[i + 1];
  700. var styleObj = JSON.parse(JSON.stringify(style));
  701. styleGroups.push({
  702. style: styleObj,
  703. color: color,
  704. start: start,
  705. end: end
  706. });
  707. }
  708. return styleGroups;
  709. }
  710. },
  711. transformStyleToMapBoxGl(style, type, expression, expressionType) {
  712. var transTable = {};
  713. if (['REGION', 'POLYGON', 'MULTIPOLYGON'].includes(type)) {
  714. transTable = {
  715. fillColor: 'fill-color',
  716. fillOpacity: 'fill-opacity'
  717. };
  718. }
  719. var newObj = {};
  720. for (var item in style) {
  721. if (transTable[item]) {
  722. newObj[transTable[item]] = style[item];
  723. }
  724. }
  725. if (expression) {
  726. newObj['fill-color'] = expression;
  727. }
  728. return newObj;
  729. }
  730. }
  731. });
  732. </script>
  733. </body>
  734. </html>