123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- <!--********************************************************************
- * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
- *********************************************************************-->
- <!DOCTYPE html>
- <html lang="en-US">
- <head>
- <meta charset="UTF-8">
- <title data-i18n='resources.title_chart_iPortal'></title>
- <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
- <script type="text/javascript" include="iclient-mapboxgl-css,echarts" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
- <style>
- .chart-setting {
- position: absolute;
- top: 50px;
- right: 10px;
- width: 450px;
- height: 50px;
- z-index: 800;
- background-color: #fff;
- }
- .chart-type-btn {
- position: absolute;
- top: 8px;
- right: 20px;
- width: 112px;
- height: 36px;
- float: right;
- z-index: 800;
- }
- .chart-setting .input-group {
- left: 16px;
- top: 8px;
- width: 260px;
- }
- .graph {
- margin: 5px;
- width: 26px;
- height: 26px;
- border: none;
- border-radius: 4px;
- background-size: 100%;
- outline: none;
- }
- button {
- float: right;
- }
- #bar {
- background-image: url("../img/bar.png");
- }
- #line {
- background-image: url("../img/ling.png");
- }
- #scatter {
- background-image: url("../img/scatter.png");
- }
- #chart {
- position: absolute;
- top: 100px;
- right: 10px;
- width: 450px;
- height: 350px;
- z-index: 800;
- }
- </style>
- </head>
- <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
- <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
- <div class="chart-setting"></div>
- <div id="chart"></div>
- <script>
- init();
- function init() {
- var container = document.getElementsByClassName("chart-setting")[0];
- container.innerHTML =
- "<div class='chart-type-btn'>" +
- "<button type='button' class='btn btn-default graph' id='scatter' title='" + resources.title_Scatter +
- "'></button>" +
- "<button type='button' class='btn btn-default graph' id='line' title='" + resources.title_GraphLine +
- "'></button>" +
- "<button type='button' class='btn btn-default graph active' id='bar' title='" + resources.title_GraphBar +
- "''></button></div>"
- }
- var host = window.isLocal ? window.server : "https://iserver.supermap.io";
- var map, resultLayer, url = host + "/iserver/services/map-world/rest/maps/World";
- var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
- " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
- " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
- map = new mapboxgl.Map({
- container: 'map',
- style: {
- "version": 8,
- "sources": {
- "raster-tiles": {
- "attribution": attribution,
- "type": "raster",
- "tiles": [url + "/zxyTileImage.png?z={z}&x={x}&y={y}"],
- "tileSize": 256
- }
- },
- "layers": [{
- "id": "simple-tiles",
- "type": "raster",
- "source": "raster-tiles",
- }]
- },
- center: [118, 40],
- zoom: 6
- });
- //图表组件
- var options = {
- type: 'bar',
- datasets: {
- type: 'iPortal', //iServer iPortal
- url: 'https://iportal.supermap.io/iportal/web/datas/676516522',
- withCredentials: false, //默认值是false
- queryInfo: {
- attributeFilter: "SmID > 0"
- }
- },
- chartOptions: [{
- xAxis: {
- field: "机场",
- name: "Airport"
- },
- yAxis: {
- field: "同比增速%",
- name: "GrowthRate%"
- }
- }]
- }
- var barChart = new SuperMap.Components.Chart("chart", options);
- //加载图表之后,将要素添加到地图上
- barChart.onAdd(addDataToMap);
- function addDataToMap() {
- var features = barChart.getFeatures();
- var layer = {
- "id": '1',
- "type": 'circle',
- "layout": {
- 'visibility': 'visible',
- },
- "paint": {
- "circle-radius": 8,
- "circle-color": 'blue'
- },
- "source": {
- "type": "geojson",
- "data": features
- }
- };
- resultLayer = map.addLayer(layer);
- }
- //为图表类型按钮绑定事件
- bindEvent();
- function bindEvent() {
- $(".graph").on("click", function () {
- $(".graph").removeClass("active");
- });
- $("#bar").on("click", function () {
- $("#bar").addClass("active");
- barChart.changeType('bar');
- });
- $("#line").on("click", function () {
- $("#line").addClass("active");
- barChart.changeType('line');
- });
- $("#scatter").on("click", function () {
- $("#scatter").addClass("active");
- barChart.changeType('scatter');
- });
- }
- </script>
- </body>
- </html>
|