02_getFeatureBySQL.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  9. <title data-i18n="resources.title_getFeatureBySQL"></title>
  10. <script type="text/javascript" src="../js/include-web.js"></script>
  11. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  12. <style>
  13. body {
  14. margin: 0;
  15. padding: 0;
  16. }
  17. #map {
  18. position: absolute;
  19. top: 0;
  20. bottom: 0;
  21. width: 100%;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id="map"></div>
  27. <script>
  28. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  29. "with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  30. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span>";
  31. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  32. var baseUrl = host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}';
  33. var dataUrl = host + "/iserver/services/data-world/rest/data";
  34. var map = new mapboxgl.Map({
  35. container: 'map', //div id
  36. style: {
  37. "version": 8,
  38. "sources": {
  39. "raster-tiles": {
  40. "attribution": attribution,
  41. "type": "raster",
  42. "tiles": [baseUrl],
  43. "tileSize": 256
  44. }
  45. },
  46. "layers": [{
  47. "id": "simple-tiles",
  48. "type": "raster",
  49. "source": "raster-tiles",
  50. "maxzoom": 18
  51. }]
  52. },
  53. center: [120.143, 30.236],
  54. zoom: 3
  55. });
  56. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  57. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  58. map.on('load', function () {
  59. query();
  60. });
  61. function query() {
  62. var sqlParam = new SuperMap.GetFeaturesBySQLParameters({
  63. queryParameter: {
  64. name: "Countries@World",
  65. attributeFilter: "SMID = 247"
  66. },
  67. datasetNames: ["World:Countries"]
  68. });
  69. new mapboxgl.supermap.FeatureService(dataUrl).getFeaturesBySQL(sqlParam, function (serviceResult) {
  70. map.addSource("queryDatas", {
  71. "type": "geojson",
  72. "data": serviceResult.result.features
  73. });
  74. map.addLayer({
  75. "id": "queryDatas",
  76. "type": "fill", /* fill类型一般用来表示一个面,一般较大 */
  77. "source": "queryDatas",
  78. "paint": {
  79. "fill-color": "#FF3300", /* 填充的颜色 */
  80. "fill-opacity": 0.6 /* 透明度 */
  81. },
  82. });
  83. map.on('click', 'queryDatas', function (e) {
  84. new mapboxgl.Popup()
  85. .setLngLat(e.lngLat)
  86. .setHTML(e.features[0].properties.SMID + "<br>" + resources.text_country + ":" + e.features[0].properties.COUNTRY)
  87. .addTo(map);
  88. });
  89. });
  90. }
  91. </script>
  92. </body>
  93. </html>