123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title data-i18n="resources.title_graphThemeLayer"></title>
- <script src='../data/chinaConsumptionLevel.js'></script>
- <style>
- .editPane {
- position: absolute;
- right: 65px;
- top: 8px;
- text-align: center;
- background: #FFF;
- z-index: 1000;
- border-radius: 4px;
- }
- .tooltip-inner {
- width: 68px;
- background-color: transparent;
- color: #515151;
- }
- .graph {
- margin: 5px;
- width: 26px;
- height: 26px;
- border: none;
- border-radius: 4px;
- background-size: 100%;
- }
- .btn {
- margin-bottom: 5px !important;
- }
- #bar {
- background-image: url("../img/bar.png");
- }
- #bar3d {
- background-image: url("../img/bar3D.png");
- }
- #ling {
- background-image: url("../img/ling.png");
- }
- #point {
- background-image: url("../img/point.png");
- }
- #pie {
- background-image: url("../img/pie.png");
- }
- #ring {
- background-image: url("../img/ring.png");
- }
- .btn {
- margin-bottom: 10px;
- }
- .ol-popup {
- position: absolute;
- background-color: white;
- -webkit-filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
- filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.2));
- padding: 15px;
- border-radius: 10px;
- border: 1px solid #cccccc;
- bottom: 12px;
- left: -50px;
- min-width: 300px;
- }
- .ol-popup:after, .ol-popup:before {
- top: 100%;
- border: solid transparent;
- content: " ";
- height: 0;
- width: 0;
- position: absolute;
- pointer-events: none;
- }
- .ol-popup:after {
- border-top-color: white;
- border-width: 10px;
- left: 48px;
- margin-left: -10px;
- }
- .ol-popup:before {
- border-top-color: #cccccc;
- border-width: 11px;
- left: 48px;
- margin-left: -11px;
- }
- </style>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
- <div id="popup" class="ol-popup">
- <div id="popup-content"></div>
- </div>
- <div class="editPane" role="group" aria-label="...">
- <button type='button' class='btn btn-default graph active' id='bar' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphBar"></button>
- <button type='button' class='btn btn-default graph' id='bar3d' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphBar3D"></button>
- <button type='button' class='btn btn-default graph' id='ling' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphLine"></button>
- <button type='button' class='btn btn-default graph' id='point' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphPoint"></button>
- <button type='button' class='btn btn-default graph' id='pie' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphPie"></button>
- <button type='button' class='btn btn-default graph' id='ring' data-toggle='tooltip' data-placement='bottom' data-i18n="[title]resources.title_GraphRing"></button>
- </div>
- <div id="map" style="width: 100%;height:100%"></div>
- <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
- <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
- <script type="text/javascript">
- var map, themeSource,
- host = window.isLocal ? window.server : "https://iserver.supermap.io",
- url = host + "/iserver/services/map-china400/rest/maps/China_4326",
- container = document.getElementById('popup'),
- content = document.getElementById('popup-content'),
- overlay = new ol.Overlay(({
- element: container,
- autoPan: true,
- autoPanAnimation: {
- duration: 250
- }
- })),
- map = new ol.Map({
- target: 'map',
- controls: ol.control.defaults({attributionOptions: {collapsed: false}})
- .extend([new ol.supermap.control.Logo()]),
- view: new ol.View({
- center: [105.85, 36.79],
- zoom: 5,
- projection: 'EPSG:4326',
- multiWorld: true
- }),
- overlays: [overlay]
- });
- new ol.supermap.MapService(url).getMapInfo(function (serviceResult) {
- var mapJSONObj = serviceResult.result;
- var options = ol.source.TileSuperMapRest.optionsFromMapJSON(url, mapJSONObj);
- options.wrapX = true;
- var layer = new ol.layer.Tile({
- source: new ol.source.TileSuperMapRest(options)
- });
- map.addLayer(layer);
- map.once('postrender', function () {
- initFeaterDatasAddStyles();
- createBarThemeLayer();
- bindEvent();
- });
- });
- function bindEvent() {
- $("[data-toggle='tooltip']").on("mouseover", function () {
- $("[data-toggle='tooltip']").tooltip();
- });
- $("[data-toggle='tooltip']").on("mouseout", function () {
- $("[data-toggle='tooltip']").tooltip("hide");
- });
- $(".graph").on("click", function () {
- $(".graph").removeClass("active");
- });
- $("#bar").on("click", function () {
- $("#bar").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createBarThemeLayer();
- });
- $("#bar3d").on("click", function () {
- $("#bar3d").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createBar3DThemeLayer();
- });
- $("#ling").on("click", function () {
- $("#ling").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createLineThemeLayer();
- });
- $("#point").on("click", function () {
- $("#point").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createPointThemeLayer();
- });
- $("#pie").on("click", function () {
- $("#pie").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createPieThemeLayer();
- });
- $("#ring").on("click", function () {
- $("#ring").addClass("active");
- initFeaterDatasAddStyles();
- clearThemeLayer();
- createRingThemeLayer();
- });
- }
- var features,
- themeLayer,
- chartsSettingForBarAddBar3DCommon,
- chartsSettingForPointOrLine,
- chartsSettingForPieOrRing,
- themeLayerOptions;
- function initFeaterDatasAddStyles() {
- //创建附着要素
- //features = [];
- var feas = [];
- for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
- // 省居民消费水平(单位:元)信息
- var provinceInfo = chinaConsumptionLevel[i];
- //支持传入 ol.supermap.ThemeFeature:
- /* var geo = new ol.geom.Point([provinceInfo[1], provinceInfo[2]]);
- var attrs = {};
- attrs.NAME = provinceInfo[0];
- attrs.CON2009 = provinceInfo[3];
- attrs.CON2010 = provinceInfo[4];
- attrs.CON2011 = provinceInfo[5];
- attrs.CON2012 = provinceInfo[6];
- attrs.CON2013 = provinceInfo[7];
- var fea = new ol.supermap.ThemeFeature(geo, attrs);
- features.push(fea);*/
- //支持传入 GeoJSON 规范数据类型:
- var fea = {
- "type": "feature",
- "geometry": {
- "type": "Point",
- "coordinates": [provinceInfo[1], provinceInfo[2]]
- },
- "properties": {
- "NAME": provinceInfo[0],
- "CON2009": provinceInfo[3],
- "CON2010": provinceInfo[4],
- "CON2011": provinceInfo[5],
- "CON2012": provinceInfo[6],
- "CON2013": provinceInfo[7],
- }
- };
- feas.push(fea);
- }
- features = {
- "type": "FeatureCollection",
- "features": feas
- };
- //Bar add Bar3D chartsSetting
- chartsSettingForBarAddBar3DCommon = {
- width: 260,
- height: 120,
- codomain: [0, 40000],
- xShapeBlank: [15, 15, 15],
- axisYTick: 4,
- axisYLabels: ["4万", "3万", "2万", "1万", "0"],
- axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
- backgroundRadius: [5, 5, 5, 5],
- backgroundStyle: {
- fillColor: "#d1eeee",
- shadowBlur: 12,
- shadowColor: "#d1eeee"
- }
- };
- //Point add Line chartsSetting
- chartsSettingForPointOrLine = {
- width: 220,
- height: 100,
- codomain: [0, 40000],
- xShapeBlank: [10, 10],
- axisYTick: 4,
- axisYLabels: ["4万", "3万", "2万", "1万", "0"],
- axisXLabels: ["09年", "10年", "11年", "12年", "13年"],
- backgroundStyle: {fillColor: "#d1eeee"},
- backgroundRadius: [5, 5, 5, 5],
- useXReferenceLine: true,
- pointStyle: {
- pointRadius: 5,
- shadowBlur: 12,
- shadowColor: "#D8361B",
- fillOpacity: 0.8
- },
- pointHoverStyle: {
- stroke: true,
- strokeColor: "#D8361B",
- strokeWidth: 2,
- fillColor: "#ffffff",
- pointRadius: 4
- },
- };
- //Pie add Ring chartsSetting
- chartsSettingForPieOrRing = {
- width: 240,
- height: 100,
- codomain: [0, 40000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
- sectorStyle: {fillOpacity: 0.8}, // 柱状图中柱条的(表示字段值的图形)样式
- sectorStyleByFields: [
- {fillColor: "#FFB980"},
- {fillColor: "#5AB1EF"},
- {fillColor: "#B6A2DE"},
- {fillColor: "#2EC7C9"},
- {fillColor: "#D87A80"}],
- sectorHoverStyle: {fillOpacity: 1},
- xShapeBlank: [10, 10, 10], // 水平方向上的空白间距参数
- axisYLabels: ["4万", "3万", "2万", "1万", "0"], // y 轴标签内容
- axisXLabels: ["09年", "10年", "11年", "12年", "13年"], // x 轴标签内容
- backgroundStyle: {fillColor: "#CCE8CF"}, // 背景样式
- backgroundRadius: [5, 5, 5, 5], // 背景框圆角参数
- };
- //设置graphThemeLayer option参数
- themeLayerOptions = {
- map: map,
- attributions: " ",
- themeFields: ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"],
- opacity: 0.9,
- chartsSetting: {},
- };
- }
- var pointerInteraction = null;
- function addPointerInteraction(themeSource) {
- pointerInteraction = new ol.interaction.Pointer({
- handleMoveEvent: function (event) {
- themeSource.fire('mousemove', event);
- }
- });
- map.addInteraction(pointerInteraction);
- }
- //创建Bar图表
- function createBarThemeLayer() {
- var chartsSettingForBar = chartsSettingForBarAddBar3DCommon;
- chartsSettingForBar.barStyle = {fillOpacity: 0.7}; // 柱状图中柱条的(表示字段值的图形)样式
- chartsSettingForBar.barHoverStyle = {fillOpacity: 1}; // 柱条 hover 样式
- //阴影样式
- chartsSettingForBar.barShadowStyle = {
- shadowBlur: 8,
- shadowOffsetX: 2,
- shadowOffsetY: 2,
- shadowColor: "rgba(100,100,100,0.8)"
- };
- chartsSettingForBar.barLinearGradient = [
- ["#00FF00", "#00CD00"],
- ["#00CCFF", "#5E87A2"],
- ["#00FF66", "#669985"],
- ["#CCFF00", "#94A25E"],
- ["#FF9900", "#A2945E"]];
- themeLayerOptions.chartsSetting = chartsSettingForBar;
- themeSource = new ol.source.Graph("BarLayer", "Bar", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource,
- });
- map.addLayer(themeLayer);
- }
- //创建Bar3D图表
- function createBar3DThemeLayer() {
- var chartsSettingForBar3D = chartsSettingForBarAddBar3DCommon;
- chartsSettingForBar3D.useXReferenceLine = true;
- chartsSettingForBar3D.xReferenceLineStyle = {strokeColor: "#008acd", strokeOpacity: 0.4};
- // 3d 柱条正面样式(3d 柱条的侧面和顶面会以 3d 柱条正面样式为默认样式)
- chartsSettingForBar3D.barFaceStyle = {stroke: true};
- // 按字段设置 3d 柱条正面样式
- chartsSettingForBar3D.barFaceStyleByFields = [
- {fillColor: "#FFB980"},
- {fillColor: "#5AB1EF"},
- {fillColor: "#B6A2DE"},
- {fillColor: "#2EC7C9"},
- {fillColor: "#D87A80"}];
- // 3d 柱条正面 hover 样式(3d 柱条的侧面和顶面 hover 会以 3d 柱条正面 hover 样式为默认 hover 样式)
- chartsSettingForBar3D.barFaceHoverStyle = {
- stroke: true,
- strokeWidth: 1,
- strokeColor: "#ffff00"
- };
- themeLayerOptions.chartsSetting = chartsSettingForBar3D;
- themeSource = new ol.source.Graph("Bar3DLayer", "Bar3D", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource
- });
- map.addLayer(themeLayer);
- }
- //创建Line图表
- function createLineThemeLayer() {
- chartsSettingForPointOrLine.pointStyle.fillColor = "#9966CC";
- themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
- themeSource = new ol.source.Graph("LineLayer", "Line", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource
- });
- map.addLayer(themeLayer);
- }
- //创建Point图表
- function createPointThemeLayer() {
- chartsSettingForPointOrLine.pointStyle.fillColor = "#D8361B";
- themeLayerOptions.chartsSetting = chartsSettingForPointOrLine;
- themeSource = new ol.source.Graph("PointLayer", "Point", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource
- });
- map.addLayer(themeLayer);
- }
- //创建Pie图表
- function createPieThemeLayer() {
- themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
- themeSource = new ol.source.Graph("PieLayer", "Pie", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource
- });
- map.addLayer(themeLayer);
- }
- //创建Ring图表
- function createRingThemeLayer() {
- chartsSettingForPieOrRing.innerRingRadius = 20;
- themeLayerOptions.chartsSetting = chartsSettingForPieOrRing;
- themeSource = new ol.source.Graph("RingLayer", "Ring", themeLayerOptions);
- themeSource.on("mousemove", showInfoWin);
- themeSource.addFeatures(features);
- addPointerInteraction(themeSource);
- themeLayer = new ol.layer.Image({
- source: themeSource
- });
- map.addLayer(themeLayer);
- }
- //清除图表专题图
- function clearThemeLayer() {
- if (themeSource && themeLayer) {
- map.removeLayer(themeLayer);
- map.removeInteraction(pointerInteraction);
- themeSource = null;
- themeLayer = null;
- }
- }
- // 地图弹窗的显示
- function showInfoWin(e) {
- // e.target 是图形对象,即数据的可视化对象,柱状图中是柱条;
- // 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
- // 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field 和 value;
- if (e.target && e.target.refDataID && e.target.dataInfo) {
- closeInfoWin();
- // 获取图形对应的数据 (feature)
- var fea = themeSource.getFeatureById(e.target.refDataID);
- var info = e.target.dataInfo;
- // 弹窗内容
- var contentHTML = "<div style='color: #000; background-color: #fff'>";
- contentHTML += resources.text_Name + "<br><strong>" + fea.attributes.NAME + "</strong>";
- contentHTML += "<hr style='margin: 3px'>";
- switch (info.field) {
- case "CON2009":
- contentHTML += resources.text_consumptionLevel1 + "09" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
- break;
- case "CON2010":
- contentHTML += resources.text_consumptionLevel1 + "10" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
- break;
- case "CON2011":
- contentHTML += resources.text_consumptionLevel1 + "11" + resources.text_consumptionLevel2 + "<br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
- break;
- case "CON2012":
- contentHTML += resources.text_consumptionLevel1 + "12" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
- break;
- case "CON2013":
- contentHTML += resources.text_consumptionLevel1 + "13" + resources.text_consumptionLevel2 + " <br/><strong>" + info.value + "</strong>(" + resources.text_yuan + ")";
- break;
- default:
- contentHTML += "No Data";
- }
- contentHTML += "</div>";
- content.innerHTML = contentHTML;
- overlay.setPosition(map.getCoordinateFromPixel([e.event.x, e.event.y]));
- return;
- }
- closeInfoWin();
- }
- // 移除地图弹窗
- function closeInfoWin() {
- if (overlay) {
- overlay.setPosition(undefined);
- }
- }
- </script>
- </body>
- </html>
|