graphThemeLayer.html 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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_graphThemeLayer"></title>
  9. <script src='../data/chinaConsumptionLevel.js'></script>
  10. <style>
  11. .editPane {
  12. position: absolute;
  13. right: 65px;
  14. top: 8px;
  15. text-align: center;
  16. background: #FFF;
  17. z-index: 1000;
  18. border-radius: 4px;
  19. }
  20. .tooltip-inner {
  21. width: 68px;
  22. background-color: transparent;
  23. color: #515151;
  24. }
  25. .graph {
  26. margin: 5px;
  27. width: 26px;
  28. height: 26px;
  29. border: none;
  30. border-radius: 4px;
  31. background-size: 100%;
  32. }
  33. .btn {
  34. margin-bottom: 5px !important;
  35. }
  36. #bar {
  37. background-image: url("../img/bar.png");
  38. }
  39. #bar3d {
  40. background-image: url("../img/bar3D.png");
  41. }
  42. #ling {
  43. background-image: url("../img/ling.png");
  44. }
  45. #point {
  46. background-image: url("../img/point.png");
  47. }
  48. #pie {
  49. background-image: url("../img/pie.png");
  50. }
  51. #ring {
  52. background-image: url("../img/ring.png");
  53. }
  54. .btn {
  55. margin-bottom: 10px;
  56. }
  57. .ol-popup {
  58. position: absolute;
  59. background-color: white;
  60. -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  61. filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
  62. padding: 15px;
  63. border-radius: 10px;
  64. border: 1px solid #cccccc;
  65. bottom: 12px;
  66. left: -50px;
  67. min-width: 300px;
  68. }
  69. .ol-popup:after, .ol-popup:before {
  70. top: 100%;
  71. border: solid transparent;
  72. content: " ";
  73. height: 0;
  74. width: 0;
  75. position: absolute;
  76. pointer-events: none;
  77. }
  78. .ol-popup:after {
  79. border-top-color: white;
  80. border-width: 10px;
  81. left: 48px;
  82. margin-left: -10px;
  83. }
  84. .ol-popup:before {
  85. border-top-color: #cccccc;
  86. border-width: 11px;
  87. left: 48px;
  88. margin-left: -11px;
  89. }
  90. </style>
  91. </head>
  92. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  93. <div id="popup" class="ol-popup">
  94. <div id="popup-content"></div>
  95. </div>
  96. <div class="editPane" role="group" aria-label="...">
  97. <button type='button' class='btn btn-default graph active' id='bar' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphBar"></button>
  98. <button type='button' class='btn btn-default graph' id='bar3d' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphBar3D"></button>
  99. <button type='button' class='btn btn-default graph' id='ling' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphLine"></button>
  100. <button type='button' class='btn btn-default graph' id='point' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphPoint"></button>
  101. <button type='button' class='btn btn-default graph' id='pie' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphPie"></button>
  102. <button type='button' class='btn btn-default graph' id='ring' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphRing"></button>
  103. </div>
  104. <div id="map" style="width: 100%;height:100%"></div>
  105. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  106. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  107. <script type="text/javascript">
  108. var map, themeSource,
  109. host = window.isLocal ? window.server : "https://iserver.supermap.io",
  110. url = host + "/iserver/services/map-china400/rest/maps/China_4326",
  111. container = document.getElementById('popup'),
  112. content = document.getElementById('popup-content'),
  113. overlay = new ol.Overlay(({
  114. element: container,
  115. autoPan: true,
  116. autoPanAnimation: {
  117. duration: 250
  118. }
  119. })),
  120. map = new ol.Map({
  121. target: 'map',
  122. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  123. .extend([new ol.supermap.control.Logo()]),
  124. view: new ol.View({
  125. center: [105.85, 36.79],
  126. zoom: 5,
  127. projection: 'EPSG:4326',
  128. multiWorld: true
  129. }),
  130. overlays: [overlay]
  131. });
  132. new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
  133. var mapJSONObj = serviceResult.result;
  134. var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
  135. options.wrapX = true;
  136. var layer = new ol.layer.Tile({
  137. source: new ol.source.TileSuperMapRest(options)
  138. });
  139. map.addLayer(layer);
  140. map.once('postrender', function () {
  141. initFeaterDatasAddStyles();
  142. createBarThemeLayer();
  143. bindEvent();
  144. });
  145. });
  146. function bindEvent() {
  147. $("[data-toggle='tooltip']").on("mouseover", function () {
  148. $("[data-toggle='tooltip']").tooltip();
  149. });
  150. $("[data-toggle='tooltip']").on("mouseout", function () {
  151. $("[data-toggle='tooltip']").tooltip("hide");
  152. });
  153. $(".graph").on("click", function () {
  154. $(".graph").removeClass("active");
  155. });
  156. $("#bar").on("click", function () {
  157. $("#bar").addClass("active");
  158. initFeaterDatasAddStyles();
  159. clearThemeLayer();
  160. createBarThemeLayer();
  161. });
  162. $("#bar3d").on("click", function () {
  163. $("#bar3d").addClass("active");
  164. initFeaterDatasAddStyles();
  165. clearThemeLayer();
  166. createBar3DThemeLayer();
  167. });
  168. $("#ling").on("click", function () {
  169. $("#ling").addClass("active");
  170. initFeaterDatasAddStyles();
  171. clearThemeLayer();
  172. createLineThemeLayer();
  173. });
  174. $("#point").on("click", function () {
  175. $("#point").addClass("active");
  176. initFeaterDatasAddStyles();
  177. clearThemeLayer();
  178. createPointThemeLayer();
  179. });
  180. $("#pie").on("click", function () {
  181. $("#pie").addClass("active");
  182. initFeaterDatasAddStyles();
  183. clearThemeLayer();
  184. createPieThemeLayer();
  185. });
  186. $("#ring").on("click", function () {
  187. $("#ring").addClass("active");
  188. initFeaterDatasAddStyles();
  189. clearThemeLayer();
  190. createRingThemeLayer();
  191. });
  192. }
  193. var features,
  194. themeLayer,
  195. chartsSettingForBarAddBar3DCommon,
  196. chartsSettingForPointOrLine,
  197. chartsSettingForPieOrRing,
  198. themeLayerOptions;
  199. function initFeaterDatasAddStyles() {
  200. //创建附着要素
  201. //features = [];
  202. var feas = [];
  203. for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
  204. // 省居民消费水平(单位:元)信息
  205. var provinceInfo = chinaConsumptionLevel[i];
  206. //支持传入 ol.supermap.ThemeFeature:
  207. /* var geo = new ol.geom.Point([provinceInfo[1], provinceInfo[2]]);
  208. var attrs = {};
  209. attrs.NAME = provinceInfo[0];
  210. attrs.CON2009 = provinceInfo[3];
  211. attrs.CON2010 = provinceInfo[4];
  212. attrs.CON2011 = provinceInfo[5];
  213. attrs.CON2012 = provinceInfo[6];
  214. attrs.CON2013 = provinceInfo[7];
  215. var fea = new ol.supermap.ThemeFeature(geo, attrs);
  216. features.push(fea);*/
  217. //支持传入 GeoJSON 规范数据类型:
  218. var fea = {
  219. "type": "feature",
  220. "geometry": {
  221. "type": "Point",
  222. "coordinates": [provinceInfo[1], provinceInfo[2]]
  223. },
  224. "properties": {
  225. "NAME": provinceInfo[0],
  226. "CON2009": provinceInfo[3],
  227. "CON2010": provinceInfo[4],
  228. "CON2011": provinceInfo[5],
  229. "CON2012": provinceInfo[6],
  230. "CON2013": provinceInfo[7],
  231. }
  232. };
  233. feas.push(fea);
  234. }
  235. features = {
  236. "type": "FeatureCollection",
  237. "features": feas
  238. };
  239. //Bar add Bar3D chartsSetting
  240. chartsSettingForBarAddBar3DCommon = {
  241. width: 260,
  242. height: 120,
  243. codomain: [0, 40000],
  244. xShapeBlank: [15, 15, 15],
  245. axisYTick: 4,
  246. axisYLabels: ["4万", "3万", "2万", "1万", "0"],
  247. axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
  248. backgroundRadius: [5, 5, 5, 5],
  249. backgroundStyle: {
  250. fillColor: "#d1eeee",
  251. shadowBlur: 12,
  252. shadowColor: "#d1eeee"
  253. }
  254. };
  255. //Point add Line chartsSetting
  256. chartsSettingForPointOrLine = {
  257. width: 220,
  258. height: 100,
  259. codomain: [0, 40000],
  260. xShapeBlank: [10, 10],
  261. axisYTick: 4,
  262. axisYLabels: ["4万", "3万", "2万", "1万", "0"],
  263. axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
  264. backgroundStyle: {fillColor: "#d1eeee"},
  265. backgroundRadius: [5, 5, 5, 5],
  266. useXReferenceLine: true,
  267. pointStyle: {
  268. pointRadius: 5,
  269. shadowBlur: 12,
  270. shadowColor: "#D8361B",
  271. fillOpacity: 0.8
  272. },
  273. pointHoverStyle: {
  274. stroke: true,
  275. strokeColor: "#D8361B",
  276. strokeWidth: 2,
  277. fillColor: "#ffffff",
  278. pointRadius: 4
  279. },
  280. };
  281. //Pie add Ring chartsSetting
  282. chartsSettingForPieOrRing = {
  283. width: 240,
  284. height: 100,
  285. codomain: [0, 40000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
  286. sectorStyle: {fillOpacity: 0.8}, // 柱状图中柱条的(表示字段值的图形)样式
  287. sectorStyleByFields: [
  288. {fillColor: "#FFB980"},
  289. {fillColor: "#5AB1EF"},
  290. {fillColor: "#B6A2DE"},
  291. {fillColor: "#2EC7C9"},
  292. {fillColor: "#D87A80"}],
  293. sectorHoverStyle: {fillOpacity: 1},
  294. xShapeBlank: [10, 10, 10], // 水平方向上的空白间距参数
  295. axisYLabels: ["4万", "3万", "2万", "1万", "0"], // y 轴标签内容
  296. axisXLabels: ["09年", "10年", "11年", "12年", "13年"], // x 轴标签内容
  297. backgroundStyle: {fillColor: "#CCE8CF"}, // 背景样式
  298. backgroundRadius: [5, 5, 5, 5], // 背景框圆角参数
  299. };
  300. //设置graphThemeLayer option参数
  301. themeLayerOptions = {
  302. map: map,
  303. attributions: " ",
  304. themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
  305. opacity: 0.9,
  306. chartsSetting: {},
  307. };
  308. }
  309. var pointerInteraction = null;
  310. function addPointerInteraction(themeSource) {
  311. pointerInteraction = new ol.interaction.Pointer({
  312. handleMoveEvent: function (event) {
  313. themeSource.fire('mousemove', event);
  314. }
  315. });
  316. map.addInteraction(pointerInteraction);
  317. }
  318. //创建Bar图表
  319. function createBarThemeLayer() {
  320. var chartsSettingForBar = chartsSettingForBarAddBar3DCommon;
  321. chartsSettingForBar.barStyle = {fillOpacity: 0.7}; // 柱状图中柱条的(表示字段值的图形)样式
  322. chartsSettingForBar.barHoverStyle = {fillOpacity: 1}; // 柱条 hover 样式
  323. //阴影样式
  324. chartsSettingForBar.barShadowStyle = {
  325. shadowBlur: 8,
  326. shadowOffsetX: 2,
  327. shadowOffsetY: 2,
  328. shadowColor: "rgba(100,100,100,0.8)"
  329. };
  330. chartsSettingForBar.barLinearGradient = [
  331. ["#00FF00", "#00CD00"],
  332. ["#00CCFF", "#5E87A2"],
  333. ["#00FF66", "#669985"],
  334. ["#CCFF00", "#94A25E"],
  335. ["#FF9900", "#A2945E"]];
  336. themeLayerOptions.chartsSetting = chartsSettingForBar;
  337. themeSource = new ol.source.Graph("BarLayer", "Bar", themeLayerOptions);
  338. themeSource.on("mousemove", showInfoWin);
  339. themeSource.addFeatures(features);
  340. addPointerInteraction(themeSource);
  341. themeLayer = new ol.layer.Image({
  342. source: themeSource,
  343. });
  344. map.addLayer(themeLayer);
  345. }
  346. //创建Bar3D图表
  347. function createBar3DThemeLayer() {
  348. var chartsSettingForBar3D = chartsSettingForBarAddBar3DCommon;
  349. chartsSettingForBar3D.useXReferenceLine = true;
  350. chartsSettingForBar3D.xReferenceLineStyle = {strokeColor: "#008acd", strokeOpacity: 0.4};
  351. // 3d 柱条正面样式(3d 柱条的侧面和顶面会以 3d 柱条正面样式为默认样式)
  352. chartsSettingForBar3D.barFaceStyle = {stroke: true};
  353. // 按字段设置 3d 柱条正面样式
  354. chartsSettingForBar3D.barFaceStyleByFields = [
  355. {fillColor: "#FFB980"},
  356. {fillColor: "#5AB1EF"},
  357. {fillColor: "#B6A2DE"},
  358. {fillColor: "#2EC7C9"},
  359. {fillColor: "#D87A80"}];
  360. // 3d 柱条正面 hover 样式(3d 柱条的侧面和顶面 hover 会以 3d 柱条正面 hover 样式为默认 hover 样式)
  361. chartsSettingForBar3D.barFaceHoverStyle = {
  362. stroke: true,
  363. strokeWidth: 1,
  364. strokeColor: "#ffff00"
  365. };
  366. themeLayerOptions.chartsSetting = chartsSettingForBar3D;
  367. themeSource = new ol.source.Graph("Bar3DLayer", "Bar3D", themeLayerOptions);
  368. themeSource.on("mousemove", showInfoWin);
  369. themeSource.addFeatures(features);
  370. addPointerInteraction(themeSource);
  371. themeLayer = new ol.layer.Image({
  372. source: themeSource
  373. });
  374. map.addLayer(themeLayer);
  375. }
  376. //创建Line图表
  377. function createLineThemeLayer() {
  378. chartsSettingForPointOrLine.pointStyle.fillColor = "#9966CC";
  379. themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
  380. themeSource = new ol.source.Graph("LineLayer", "Line", themeLayerOptions);
  381. themeSource.on("mousemove", showInfoWin);
  382. themeSource.addFeatures(features);
  383. addPointerInteraction(themeSource);
  384. themeLayer = new ol.layer.Image({
  385. source: themeSource
  386. });
  387. map.addLayer(themeLayer);
  388. }
  389. //创建Point图表
  390. function createPointThemeLayer() {
  391. chartsSettingForPointOrLine.pointStyle.fillColor = "#D8361B";
  392. themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
  393. themeSource = new ol.source.Graph("PointLayer", "Point", themeLayerOptions);
  394. themeSource.on("mousemove", showInfoWin);
  395. themeSource.addFeatures(features);
  396. addPointerInteraction(themeSource);
  397. themeLayer = new ol.layer.Image({
  398. source: themeSource
  399. });
  400. map.addLayer(themeLayer);
  401. }
  402. //创建Pie图表
  403. function createPieThemeLayer() {
  404. themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
  405. themeSource = new ol.source.Graph("PieLayer", "Pie", themeLayerOptions);
  406. themeSource.on("mousemove", showInfoWin);
  407. themeSource.addFeatures(features);
  408. addPointerInteraction(themeSource);
  409. themeLayer = new ol.layer.Image({
  410. source: themeSource
  411. });
  412. map.addLayer(themeLayer);
  413. }
  414. //创建Ring图表
  415. function createRingThemeLayer() {
  416. chartsSettingForPieOrRing.innerRingRadius = 20;
  417. themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
  418. themeSource = new ol.source.Graph("RingLayer", "Ring", themeLayerOptions);
  419. themeSource.on("mousemove", showInfoWin);
  420. themeSource.addFeatures(features);
  421. addPointerInteraction(themeSource);
  422. themeLayer = new ol.layer.Image({
  423. source: themeSource
  424. });
  425. map.addLayer(themeLayer);
  426. }
  427. //清除图表专题图
  428. function clearThemeLayer() {
  429. if (themeSource && themeLayer) {
  430. map.removeLayer(themeLayer);
  431. map.removeInteraction(pointerInteraction);
  432. themeSource = null;
  433. themeLayer = null;
  434. }
  435. }
  436. // 地图弹窗的显示
  437. function showInfoWin(e) {
  438. // e.target 是图形对象,即数据的可视化对象,柱状图中是柱条;
  439. // 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
  440. // 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field 和 value;
  441. if (e.target && e.target.refDataID && e.target.dataInfo) {
  442. closeInfoWin();
  443. // 获取图形对应的数据 (feature)
  444. var fea = themeSource.getFeatureById(e.target.refDataID);
  445. var info = e.target.dataInfo;
  446. // 弹窗内容
  447. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  448. contentHTML += resources.text_Name + "<br><strong>" + fea.attributes.NAME + "</strong>";
  449. contentHTML += "<hr style='margin: 3px'>";
  450. switch (info.field) {
  451. case "CON2009":
  452. contentHTML += resources.text_consumptionLevel1 + "09" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  453. break;
  454. case "CON2010":
  455. contentHTML += resources.text_consumptionLevel1 + "10" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  456. break;
  457. case "CON2011":
  458. contentHTML += resources.text_consumptionLevel1 + "11" + resources.text_consumptionLevel2 + "<br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  459. break;
  460. case "CON2012":
  461. contentHTML += resources.text_consumptionLevel1 + "12" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  462. break;
  463. case "CON2013":
  464. contentHTML += resources.text_consumptionLevel1 + "13" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
  465. break;
  466. default:
  467. contentHTML += "No Data";
  468. }
  469. contentHTML += "</div>";
  470. content.innerHTML = contentHTML;
  471. overlay.setPosition(map.getCoordinateFromPixel([e.event.x, e.event.y]));
  472. return;
  473. }
  474. closeInfoWin();
  475. }
  476. // 移除地图弹窗
  477. function closeInfoWin() {
  478. if (overlay) {
  479. overlay.setPosition(undefined);
  480. }
  481. }
  482. </script>
  483. </body>
  484. </html>