tmap.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <!--
  2. * @LastEditors: gcz
  3. -->
  4. <!--
  5. * @LastEditors: gcz
  6. -->
  7. <template>
  8. <div class="map-wrap">
  9. <div id="map"></div>
  10. <div id="mask"></div>
  11. <div class="yun-wrap">
  12. <img class="yun yun1" src="../assets/img/云1.png" alt="" />
  13. </div>
  14. <div class="yun-wrap">
  15. <img class="yun yun2" src="../assets/img/云2.png" alt="" />
  16. </div>
  17. <div class="yun-wrap">
  18. <img class="yun yun3" src="../assets/img/云3.png" alt="" />
  19. </div>
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: "",
  25. components: {},
  26. data() {
  27. return {
  28. lngLat:[116.40769,39.89945],
  29. zoom:9
  30. };
  31. },
  32. created() {},
  33. mounted() {
  34. this.initMap()
  35. },
  36. methods: {
  37. initMap() {
  38. const init = new Promise((resolve, reject) => {
  39. if (window.T) {
  40. // console.log("地图初始化成功");
  41. resolve(window.T);
  42. reject("error");
  43. } else {
  44. console.log("地图初始化失败");
  45. }
  46. });
  47. init
  48. .then((T) => {
  49. // let imageURL =
  50. // "http://t0.tianditu.gov.cn/img_w/wmts?" +
  51. // "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=img&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  52. // "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}&tk=7e5149a4e4bc98ccf53b9941d5f8ea62";
  53. // //创建自定义图层对象
  54. // let lay = new T.TileLayer(imageURL, { minZoom: 1, maxZoom: 18 });
  55. // let config = { layers: [lay] };
  56. // this.map = new T.Map('map',config);
  57. this.map = new T.Map("map");
  58. //清理地图上的覆盖物
  59. // this.map.clearOverLays();
  60. // console.log('options',this.options);
  61. // console.log('optionsData',this.optionsData);
  62. this.map.centerAndZoom(
  63. new T.LngLat(this.lngLat[0], this.lngLat[1]),
  64. this.zoom
  65. );
  66. // this.map.centerAndZoom(new T.LngLat(116.40769, 39.89945), 12);
  67. this.map.setMapType(window.TMAP_HYBRID_MAP);
  68. // this.addWmsLayer('demo_city,demo_road,demo_anno','http://gisserver.tianditu.com/tiandituService/wms')
  69. // this.map.setStyle('indigo')//设置地图样式
  70. // 允许鼠标滑轮滚动缩放地图大小
  71. // this.map.enableScrollWheelZoom()
  72. //获取行政区信息
  73. this.getMap();
  74. })
  75. .catch((err) => {
  76. console.log("map init err", err);
  77. });
  78. },
  79. getMap() {
  80. let that = this;
  81. //创建对象
  82. let administrative = new T.AdministrativeDivision(); //创建一个获取行政区划的实例
  83. let config = {
  84. needSubInfo: false, //是否需要下一级信息
  85. needAll: false, //是否需要所有子节点。
  86. needPolygon: true, //是否需要行政区划范围。
  87. needPre: false, //是否需要上一级所有信息。
  88. searchType: 1, //查询类型。0表示根据code查询,1表示根据名称查询。
  89. searchWord: '安顺' //查询行政区划的名称。
  90. };
  91. administrative.search(config, searchResult); //方法:根据检索词发起检索,searchResult:回调参数
  92. function searchResult(result) {
  93. // console.log('getMap',result);
  94. if (result.getStatus() == 100) {
  95. let data = result.getData();
  96. // console.log('AdministrativeDivision data',data);
  97. data[0].points = [{
  98. "region":"116.236 40.117,116.234 40.107,116.236 40.106,116.238 40.105,116.238 40.104,116.239 40.104,116.239 40.104,116.24 40.104,116.25 40.103,116.25 40.103,116.251 40.103,116.252 40.104,116.253 40.104,116.253 40.104,116.253 40.105,116.253 40.105,116.253 40.106"
  99. }];
  100. that.showMsg(data);
  101. } else {
  102. result.getMsg();
  103. }
  104. }
  105. //具体内容详见AdministrativeDivisionResult类。
  106. },
  107. showMsg(data) {
  108. for (let i = 0; i < data.length; i++) {
  109. //解释上级行政区划
  110. if (data[i].parents) {
  111. let upLevel = "";
  112. if (data[i].parents.country) {
  113. upLevel += data[i].parents.country.name;
  114. }
  115. if (data[i].parents.province) {
  116. upLevel += data[i].parents.province.name;
  117. }
  118. }
  119. if (data[i].points) {
  120. // console.log('data[i].points',data[i].points);
  121. //绘制行政区划
  122. this.polygon(data[i].points);
  123. }
  124. //解释下级行政区划
  125. if (data[i].child) {
  126. this.showMsg(data[i].child);
  127. console.log(data[i].child.points);
  128. if (data[i].child.points) {
  129. //绘制行政区划
  130. this.polygon(data[i].child.points);
  131. }
  132. }
  133. }
  134. },
  135. polygon(points) {
  136. let that = this;
  137. let pointsArr = [];
  138. for (let i = 0; i < points.length; i++) {
  139. let regionLngLats = [];
  140. let regionArr = points[i].region.split(",");
  141. for (let m = 0; m < regionArr.length; m++) {
  142. let lnglatArr = regionArr[m].split(" ");
  143. let lnglat = new T.LngLat(lnglatArr[0], lnglatArr[1]);
  144. regionLngLats.push(lnglat);
  145. pointsArr.push(lnglat);
  146. }
  147. //创建面对象,样式
  148. this.polygonData = new T.Polygon(regionLngLats, {
  149. color: "#fd737a",
  150. weight: 3,
  151. opacity: 1,
  152. fillColor: "#FFFFFF", //填充颜色。
  153. fillOpacity: 0.3 //填充透明度
  154. });
  155. //向地图上添加行政区划面
  156. that.map.addOverLay(this.polygonData);
  157. }
  158. // this.map.centerAndZoom(new T.LngLat('116.236','40.117'), 12);
  159. //显示最佳比例尺
  160. that.map.setViewport(pointsArr);
  161. this.addPolygonClick()
  162. // alert(
  163. // "当前地图中心点:" +
  164. // that.map.getCenter().getLng() +
  165. // "," +
  166. // that.map.getCenter().getLat()
  167. // );
  168. },
  169. removePolygonClick() {
  170. //移除面的点击事件
  171. this.polygonData.removeEventListener("click", this.PolygonClick);
  172. },
  173. addPolygonClick() {
  174. //移除面的点击事件,防止多次注册
  175. this.removePolygonClick();
  176. //注册面的点击事件
  177. this.polygonData.addEventListener("click", this.PolygonClick);
  178. },
  179. PolygonClick(e) {
  180. console.log('PolygonClick',e.target);
  181. alert("您点击了面中的:"+e.lnglat.lng+','+e.lnglat.lat);
  182. }
  183. },
  184. };
  185. </script>
  186. <style lang='scss' scoped>
  187. #map{
  188. width: 100%;
  189. height: 100vh;
  190. /deep/ .tdt-pane{
  191. z-index: auto;
  192. }
  193. }
  194. #mask{
  195. width: 100%;
  196. height: 100vh;
  197. box-shadow:inset 0px 0px 10vw 8vw rgba(38,80,179,0.54);
  198. position: fixed;
  199. left: 0;
  200. right: 0;
  201. bottom: 0;
  202. pointer-events: none;
  203. }
  204. @keyframes imageAnimation_32630606 {
  205. 0% {
  206. // opacity: 0;
  207. transform: none;
  208. }
  209. 34% {
  210. // opacity: 1;
  211. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1) translate3d(34vw,0px, 0px);
  212. }
  213. 67% {
  214. // opacity: 1;
  215. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1) translate3d(67vw,0px, 0px);
  216. }
  217. 100% {
  218. // opacity: 0;
  219. transform: rotateX(0deg) rotateY(0deg) rotateZ(0deg) scaleX(1) scaleY(1) translate3d(160vw,0px, 0px);
  220. }
  221. }
  222. .yun-wrap{
  223. position: fixed;
  224. left: 0;
  225. top: 350px;
  226. width: 100vw;
  227. pointer-events: none;
  228. }
  229. .yun{
  230. position: fixed;
  231. left: -500px;
  232. animation-name: imageAnimation_32630606;
  233. animation-iteration-count: infinite;
  234. animation-timing-function: linear;
  235. animation-duration: 110s;
  236. animation-delay: 0s;
  237. -webkit-user-drag: none;
  238. filter: none;
  239. pointer-events: none;
  240. }
  241. .yun2{
  242. bottom: 20px;
  243. animation-duration: 90s;
  244. animation-delay: 10s;
  245. }
  246. .yun3{
  247. top: 100px;
  248. animation-duration: 120s;
  249. animation-delay: 15s;
  250. }
  251. </style>