|
| 1 | +<!--******************************************************************** |
| 2 | +* Copyright© 2000 - 2023 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_dataAttributes"></title> |
| 9 | + <script type="text/javascript" include="jquery,bootstrap,jquery-twbsPagination" src="../js/include-web.js"></script> |
| 10 | + <style> |
| 11 | + .attribute-container { |
| 12 | + position: absolute; |
| 13 | + bottom: 0px; |
| 14 | + left: 0px; |
| 15 | + width: 100%; |
| 16 | + background: #fff; |
| 17 | + z-index: 1000; |
| 18 | + } |
| 19 | + #pagination-demo { |
| 20 | + float: right; |
| 21 | + margin: 0; |
| 22 | + padding-right: 20px; |
| 23 | + padding-bottom: 20px; |
| 24 | + } |
| 25 | + </style> |
| 26 | + </head> |
| 27 | + <body style="margin: 0; overflow: hidden; background: #fff; width: 100%; height: 100%; position: absolute; top: 0"> |
| 28 | + <div id="map" style="margin: 0 auto; width: 100%; height: 100%"></div> |
| 29 | + <div class="attribute-container"> |
| 30 | + <table class="table table-bordered"> |
| 31 | + <thead> |
| 32 | + <tr class="header"></tr> |
| 33 | + </thead> |
| 34 | + <tbody class="tbody"></tbody> |
| 35 | + </table> |
| 36 | + <ul id="pagination-demo" class="pagination-sm"></ul> |
| 37 | + </div> |
| 38 | + <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script> |
| 39 | + <script type="text/javascript"> |
| 40 | + var attribution = |
| 41 | + "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" + |
| 42 | + "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" + |
| 43 | + " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span>"; |
| 44 | + var host = window.isLocal ? window.server : 'https://iserver.supermap.io'; |
| 45 | + var map, |
| 46 | + baseUrl = host + '/iserver/services/map-world/rest/maps/World', |
| 47 | + url = host + '/iserver/services/data-world/rest/data'; |
| 48 | + var datasSource = 'World'; |
| 49 | + var dataset = 'Countries'; |
| 50 | + var pageSize = 8; |
| 51 | + var totalCount; |
| 52 | + var fieldInfos; |
| 53 | + var fieldList = []; |
| 54 | + map = new mapboxgl.Map({ |
| 55 | + container: 'map', //div id |
| 56 | + style: { |
| 57 | + version: 8, |
| 58 | + sources: { |
| 59 | + 'raster-tiles': { |
| 60 | + attribution: attribution, |
| 61 | + type: 'raster', |
| 62 | + tiles: [baseUrl], |
| 63 | + tileSize: 256 |
| 64 | + } |
| 65 | + }, |
| 66 | + layers: [ |
| 67 | + { |
| 68 | + id: 'simple-tiles', |
| 69 | + type: 'raster', |
| 70 | + source: 'raster-tiles', |
| 71 | + maxzoom: 18 |
| 72 | + } |
| 73 | + ] |
| 74 | + }, |
| 75 | + center: [120.143, 30.236], |
| 76 | + zoom: 3 |
| 77 | + }); |
| 78 | + map.addControl(new mapboxgl.NavigationControl(), 'top-left'); |
| 79 | + map.addControl(new mapboxgl.supermap.LogoControl({ link: 'https://iclient.supermap.io' }), 'bottom-right'); |
| 80 | + |
| 81 | + map.on('load', function () { |
| 82 | + query(); |
| 83 | + }); |
| 84 | + |
| 85 | + function query() { |
| 86 | + var sqlParam1 = new mapboxgl.supermap.GetFeaturesBySQLParameters({ |
| 87 | + queryParameter: { |
| 88 | + name: dataset + '@' + datasSource |
| 89 | + }, |
| 90 | + datasetNames: [datasSource + ':' + dataset] |
| 91 | + }); |
| 92 | + |
| 93 | + new mapboxgl.supermap.FeatureService(url).getFeaturesCount(sqlParam1).then(function (serviceResult) { |
| 94 | + totalCount = serviceResult.result.totalCount; |
| 95 | + var totalPages = Math.ceil(totalCount / pageSize); |
| 96 | + $('#pagination-demo').twbsPagination({ |
| 97 | + totalPages: totalPages, |
| 98 | + visiblePages: 7, |
| 99 | + first: resources.text_firstPage, |
| 100 | + prev: resources.text_prevPage, |
| 101 | + next: resources.text_nextPage, |
| 102 | + last: resources.text_lastPage, |
| 103 | + onPageClick: function (event, page) { |
| 104 | + $('#page-content').text('Page ' + page); |
| 105 | + var fromIndex = (page - 1) * pageSize; |
| 106 | + var toIndex = page * pageSize - 1; |
| 107 | + getFeature(fromIndex, toIndex); |
| 108 | + } |
| 109 | + }); |
| 110 | + |
| 111 | + new mapboxgl.supermap.FeatureService(url).getFeaturesDatasetInfo(sqlParam1).then(function (serviceResult) { |
| 112 | + fieldInfos = serviceResult.result[0].fieldInfos; |
| 113 | + fieldInfos.forEach((fieldInfo) => { |
| 114 | + var th = document.createElement('th'); |
| 115 | + var field = fieldInfo.name; |
| 116 | + fieldList.push(field); |
| 117 | + th.innerHTML = fieldInfo.caption || fieldInfo.name; |
| 118 | + document.querySelector('.header').appendChild(th); |
| 119 | + }); |
| 120 | + getFeature(0, pageSize - 1); |
| 121 | + }); |
| 122 | + }); |
| 123 | + } |
| 124 | + |
| 125 | + function getFeature(fromIndex, toIndex) { |
| 126 | + var sqlParam = new mapboxgl.supermap.GetFeaturesBySQLParameters({ |
| 127 | + queryParameter: { |
| 128 | + name: dataset + '@' + datasSource, |
| 129 | + attributeFilter: 'SMID > 0' |
| 130 | + }, |
| 131 | + fromIndex, |
| 132 | + toIndex, |
| 133 | + datasetNames: [datasSource + ':' + dataset], |
| 134 | + returnFeaturesOnly: true |
| 135 | + }); |
| 136 | + new mapboxgl.supermap.FeatureService(url).getFeaturesBySQL(sqlParam).then(function (serviceResult) { |
| 137 | + var tbody = document.querySelector('.tbody'); |
| 138 | + tbody.innerHTML = ''; |
| 139 | + serviceResult.result.features.features.forEach((feature) => { |
| 140 | + var tr = document.createElement('tr'); |
| 141 | + var props = feature.properties; |
| 142 | + fieldList.forEach((field) => { |
| 143 | + var td = document.createElement('td'); |
| 144 | + td.innerHTML = props[field.toUpperCase()]; |
| 145 | + tr.appendChild(td); |
| 146 | + }); |
| 147 | + tbody.appendChild(tr); |
| 148 | + }); |
| 149 | + }); |
| 150 | + } |
| 151 | + </script> |
| 152 | + </body> |
| 153 | +</html> |
0 commit comments