components_uniquetheme_vue.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en-US">
  6. <head>
  7. <meta charset="UTF-8" />
  8. <title data-i18n="resources.title_componentsUniqueTheme_Vue"></title>
  9. <style>
  10. #main {
  11. margin: 0 auto;
  12. }
  13. #main,
  14. #map {
  15. position: absolute;
  16. width: 100%;
  17. height: 100%
  18. }
  19. .legendItemHeader,
  20. .legendItemValue {
  21. width: 120px;
  22. height: 18px;
  23. font-size: 14px;
  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="main">
  29. <sm-web-map :map-options="mapOptions" @load="mapIsLoaded">
  30. <sm-unique-theme-layer :options="themeOptions" layer-name="UniqueThemeLayer"
  31. :data="features" @load="layerLoaded" v-show="!!features.length">
  32. </sm-unique-theme-layer>
  33. </sm-web-map>
  34. <!-- 属性表 -->
  35. <div style="width: 272px;float:right">
  36. <div id="infoBox" class="panel panel-primary infoPane"
  37. style="width:272px;margin-top: 250px;position: absolute;fontSize:14px;display: none;float:right">
  38. <div class="panel-heading">
  39. <h5 class='panel-title text-center' data-i18n="resources.text_attributeTable"></h5>
  40. </div>
  41. <div id="infoContent" class="panel-body content">
  42. </div>
  43. </div>
  44. </div>
  45. </div>
  46. <script type="text/javascript" include="widgets,vue,bootstrap" src="../js/include-web.js"></script>
  47. <script include="iclient-mapboxgl-vue,mapbox-gl-enhance" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  48. <script>
  49. widgets.loader.showLoader('data loading...');
  50. var HOST = window.isLocal ? window.server : "https://iserver.supermap.io";
  51. var dataUrl = HOST + "/iserver/services/data-jingjin/rest/data";
  52. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParams;
  53. getFeatureParam = new SuperMap.FilterParameter({
  54. name: "Jingjin",
  55. attributeFilter: "SMID > -1"
  56. });
  57. getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
  58. queryParameter: getFeatureParam,
  59. toIndex: 500,
  60. datasetNames: ["Jingjin:Landuse_R"]
  61. });
  62. getFeatureBySQLService = new SuperMap.GetFeaturesBySQLService(dataUrl, {
  63. format: SuperMap.DataFormat.ISERVER,
  64. eventListeners: { "processCompleted": processCompleted }
  65. });
  66. getFeatureBySQLService.processAsync(getFeatureBySQLParams);
  67. function processCompleted(getFeaturesEventArgs) {
  68. var result = getFeaturesEventArgs.result;
  69. var feas = [];
  70. if (result && result.features) {
  71. widgets.loader.removeLoader();
  72. var resultFeatures = result.features;
  73. var IHFeas = []; //岛洞多面
  74. for (var i = 0, len = resultFeatures.length; i < len; i++) {
  75. var feature = resultFeatures[i];
  76. var smid = feature.fieldValues[0];
  77. if (smid === "86" || smid === "87" || smid === "89") {
  78. // islandHoleHandlerForFeature 处理岛洞面
  79. IHFeas.push(islandHoleHandlerForFeature(feature));
  80. }
  81. else {
  82. feas.push(feature);
  83. }
  84. }
  85. // 岛洞多面要素必需在其他要素之前添加
  86. features = IHFeas.concat(feas);
  87. new Vue({
  88. el: '#main',
  89. data() {
  90. var attribution =
  91. "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  92. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  93. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ";
  94. return {
  95. mapOptions: {
  96. container: 'map',
  97. style: {
  98. "version": 8,
  99. "sources": {
  100. "raster-tiles": {
  101. "attribution": attribution,
  102. "type": "raster",
  103. "tiles": [HOST + '/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}'],
  104. "tileSize": 256,
  105. },
  106. },
  107. "layers": [{
  108. "id": "simple-tiles",
  109. "type": "raster",
  110. "source": "raster-tiles",
  111. "minzoom": 0,
  112. "maxzoom": 22
  113. }]
  114. },
  115. center: [116.85, 39.79],
  116. zoom: 7
  117. },
  118. features,
  119. themeOptions: {
  120. // map: map, //该可选参数将在下个版本遗弃
  121. attributions: " ",
  122. style: {
  123. shadowBlur: 3,
  124. shadowColor: "#000000",
  125. shadowOffsetX: 1,
  126. shadowOffsetY: 1,
  127. fillColor: "#FFFFFF"
  128. },
  129. isHoverAble: true,
  130. highlightStyle: {
  131. stroke: true,
  132. strokeWidth: 2,
  133. strokeColor: 'blue',
  134. fillColor: "#00F5FF",
  135. fillOpacity: 0.2
  136. },
  137. themeField: "LANDTYPE",
  138. styleGroups: [
  139. {
  140. value: "草地",
  141. style: {
  142. fillColor: "#C1FFC1"
  143. }
  144. },
  145. {
  146. value: "城市",
  147. style: {
  148. fillColor: "#CD7054"
  149. }
  150. },
  151. {
  152. value: "灌丛",
  153. style: {
  154. fillColor: "#7CCD7C"
  155. }
  156. },
  157. {
  158. value: "旱地",
  159. style: {
  160. fillColor: "#EE9A49"
  161. }
  162. },
  163. {
  164. value: "湖泊水库",
  165. style: {
  166. fillColor: "#8EE5EE"
  167. }
  168. },
  169. {
  170. value: "经济林",
  171. style: {
  172. fillColor: "#548B54"
  173. }
  174. },
  175. {
  176. value: "沙漠",
  177. style: {
  178. fillColor: "#DEB887"
  179. }
  180. },
  181. {
  182. value: "水浇地",
  183. style: {
  184. fillColor: "#E0FFFF"
  185. }
  186. },
  187. {
  188. value: "水田",
  189. style: {
  190. fillColor: "#388E8E"
  191. }
  192. },
  193. {
  194. value: "用材林",
  195. style: {
  196. fillColor: "#556B2F"
  197. }
  198. },
  199. {
  200. value: "沼泽",
  201. style: {
  202. fillColor: "#2F4F4F"
  203. }
  204. },
  205. {
  206. value: "缺省风格",
  207. style: {
  208. fillColor: "#ABABAB"
  209. }
  210. }
  211. ]
  212. }
  213. };
  214. },
  215. methods: {
  216. mapIsLoaded(e) {
  217. this.map = e.map;
  218. },
  219. layerLoaded(themeLayer) {
  220. themeLayer.on('mousemove', function (e) {
  221. if (e.target && e.target.refDataID) {
  222. document.getElementById("infoBox").style.display = "block";
  223. var fid = e.target.refDataID;
  224. var fea = themeLayer.getFeatureById(fid);
  225. if (fea) {
  226. document.getElementById("infoContent").innerHTML = "";
  227. document.getElementById("infoContent").innerHTML += "ID: " + fea.attributes.SMID + "<br/>";
  228. document.getElementById("infoContent").innerHTML += resources.text_landType + ": " + fea.attributes.LANDTYPE + "<br/>";
  229. document.getElementById("infoContent").innerHTML += resources.text_area + parseFloat(fea.attributes.SMAREA).toFixed(5) + "<br/>";
  230. }
  231. }
  232. else {
  233. document.getElementById("infoContent").innerHTML = "";
  234. document.getElementById("infoBox").style.display = "none";
  235. }
  236. });
  237. }
  238. }
  239. });
  240. }
  241. }
  242. /*
  243. * Method: islandHoleHandlerForFeature。
  244. * 要素岛洞处理。
  245. *
  246. * 多面中,一个子面包含另一个子面,则被包含子面处理为岛洞。
  247. *
  248. * Parameters:
  249. * multiPolygon - {<SuperMap.Feature.Vector>} 需要进行岛洞处理的要素。
  250. *
  251. * Returns:
  252. * {<SuperMap.Feature.Vector>} 处理后的要素。
  253. */
  254. function islandHoleHandlerForFeature(feature) {
  255. if (feature.geometry instanceof SuperMap.Geometry.MultiPolygon && feature.geometry.components.length > 1) {
  256. var newGeometry = islandHoleHandlerForMultiPolygon(feature.geometry);
  257. feature.geometry = newGeometry;
  258. }
  259. return feature;
  260. /*
  261. * Method: islandHoleHandlerForMultiPolygon
  262. * 处理误判为岛洞的多面。
  263. *
  264. * iClient 在解析 iServer 数据时,默认将面要素处理为 MultiPolygon 类型,但有的面要素带有岛洞,
  265. * 这种情况下应该做特殊处理,本函数可以对一个多面进行岛洞处理,并返回新的多面。
  266. *
  267. * Parameters:
  268. * multiPolygon - {<SuperMap.Geometry.MultiPolygon>} 需要进行岛洞处理的多面。
  269. *
  270. * Returns:
  271. * {<SuperMap.Geometry.MultiPolygon>} 处理后的多面。
  272. */
  273. function islandHoleHandlerForMultiPolygon(multiPolygon) {
  274. if (multiPolygon instanceof SuperMap.Geometry.MultiPolygon && multiPolygon.components.length > 1) {
  275. var mPTmp = multiPolygon.clone();
  276. var componentsPolygons = mPTmp.components;
  277. //洞面关系数组
  278. var polygonHoleGroup = [];
  279. for (var k = 0, len = componentsPolygons.length; k < len; k++) {
  280. var geoPolygon = componentsPolygons[k];
  281. //不处理已经是岛洞的面
  282. if (geoPolygon.components.length = 1) {
  283. var lineRings = geoPolygon.components[0];
  284. //将每个点放到面中进行判断
  285. for (var j = 0, len1 = componentsPolygons.length; j < len1; j++) {
  286. if (componentsPolygons[j].components.length != 1) continue;
  287. if (j != k) {
  288. var polygonGeoComp = componentsPolygons[j].components[0].components;
  289. //假设此面为岛洞
  290. var isAllPoiIn = true;
  291. for (var i = 0, len2 = geoPolygon.components.length; i < len2; i++) {
  292. var point = lineRings.components[i];
  293. if (isPointInPoly(point, polygonGeoComp) == false) {
  294. isAllPoiIn = false;
  295. continue;
  296. }
  297. }
  298. //确定并记录洞面关系
  299. if (isAllPoiIn == true) {
  300. var polygonHole = [j, k];
  301. polygonHoleGroup.push(polygonHole);
  302. }
  303. }
  304. }
  305. }
  306. else {
  307. continue;
  308. }
  309. }
  310. // 根据洞面信息重构多面 Geometry。
  311. var bPsTmp = [];
  312. var hPsTmp = [];
  313. for (var m = 0, len3 = polygonHoleGroup.length; m < len3; m++) {
  314. bPsTmp.push(polygonHoleGroup[m][0]);
  315. hPsTmp.push(polygonHoleGroup[m][1]);
  316. }
  317. //岛洞基础面
  318. var bPs = delRepeatInArray(bPsTmp);
  319. //洞面
  320. var hPs = delRepeatInArray(hPsTmp);
  321. //独立面
  322. var iPs = [];
  323. //查找独立面
  324. for (var isIPs = 0, compLen = componentsPolygons.length; isIPs < compLen; isIPs++) {
  325. var isNoHP = true;
  326. for (var o = 0, len = bPs.length; o < len; o++) {
  327. if (isIPs == bPs[o]) {
  328. isNoHP = false;
  329. break;
  330. }
  331. }
  332. if (isNoHP == true) {
  333. for (var o = 0, len = hPs.length; o < len; o++) {
  334. if (isIPs == hPs[o]) {
  335. isNoHP = false;
  336. break;
  337. }
  338. }
  339. }
  340. if (isNoHP == true) {
  341. iPs.push(isIPs);
  342. }
  343. }
  344. //新洞面信息
  345. var hpInfo = [];
  346. //组织新geometry所需要的信息
  347. for (var o = 0, len4 = bPs.length; o < len4; o++) {
  348. var ph = [];
  349. ph.push(bPs[o]);
  350. for (var m = 0, len3 = polygonHoleGroup.length; m < len3; m++) {
  351. if (bPs[o] == polygonHoleGroup[m][0]) {
  352. ph.push(polygonHoleGroup[m][1]);
  353. }
  354. }
  355. if (ph.length > 1) {
  356. hpInfo.push(ph);
  357. }
  358. }
  359. var newComponents = [];
  360. //岛洞子面处理
  361. for (var m = 0, len3 = hpInfo.length; m < len3; m++) {
  362. var geoP = hpInfo[m];
  363. var newLineRings = [];
  364. for (var n = 0, len6 = geoP.length; n < len6; n++) {
  365. newLineRings.push(componentsPolygons[geoP[n]].components[0]);
  366. }
  367. var newGeoPolygon = new SuperMap.Geometry.Polygon(newLineRings);
  368. newComponents.push(newGeoPolygon)
  369. }
  370. //独立子面处理
  371. for (var s = 0, len7 = iPs.length; s < len7; s++) {
  372. var is = iPs[s];
  373. newComponents.push(componentsPolygons[is])
  374. }
  375. multiPolygon.components = newComponents;
  376. }
  377. return multiPolygon;
  378. }
  379. /*
  380. * Method: delRepeatInArray
  381. * 删除数组中的重复元素。
  382. *
  383. * Parameters:
  384. * arr - {Array} 要进行重复元素删除的数组。
  385. *
  386. * Returns:
  387. * {Array} 无重复元素的数组。
  388. */
  389. function delRepeatInArray(arr) {
  390. var newArray = [];
  391. var provisionalTable = {};
  392. for (var i = 0, a; (a = arr[i]) != null; i++) {
  393. if (!provisionalTable[a]) {
  394. newArray.push(a);
  395. provisionalTable[a] = true;
  396. }
  397. }
  398. return newArray;
  399. }
  400. /*
  401. * Method: PointInPoly
  402. * 判断一个点是否在多边形里面。(射线法)
  403. *
  404. * Parameters:
  405. * pt - {Object} 需要判定的点对象,该对象含有属性x(横坐标),属性y(纵坐标)。
  406. * poly - {Array(Objecy)} 多边形节点数组。例如一个四边形:[{"x":1,"y":1},{"x":3,"y":1},{"x":6,"y":4},{"x":2,"y":10},{"x":1,"y":1}]。
  407. *
  408. * Returns:
  409. * {Boolean} 点是否在多边形内。
  410. */
  411. function isPointInPoly(pt, poly) {
  412. for (var isIn = false, i = -1, l = poly.length, j = l - 1; ++i < l; j = i)
  413. ((poly[i].y <= pt.y && pt.y < poly[j].y) || (poly[j].y <= pt.y && pt.y < poly[i].y))
  414. && (pt.x < (poly[j].x - poly[i].x) * (pt.y - poly[i].y) / (poly[j].y - poly[i].y) + poly[i].x)
  415. && (isIn = !isIn);
  416. return isIn;
  417. }
  418. }
  419. </script>
  420. </body>
  421. </html>