MapInit.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div class="map-content-div">
  3. <input type="hidden" v-model="searchPointInfo" />
  4. <div id="viewDiv"></div>
  5. </div>
  6. </template>
  7. <script>
  8. import initMap from '@utils/initMap.js';
  9. import location from '@/assets/img/mapdeviceimg/location.png';
  10. export default {
  11. name: 'map-init',
  12. mixins: [initMap],
  13. props: {
  14. deviceinfo: {
  15. type: Array,
  16. default: null
  17. }
  18. },
  19. data() {
  20. return {
  21. thislayerView: '',
  22. map: {},
  23. // lesseeId: JSON.parse(sessionStorage.getItem("loginInfo")).lesseeId,
  24. deviceObjData: '',
  25. addpointGraphic: '',
  26. addGraphic: '',
  27. count: 0,
  28. allserviceType: [],
  29. graphicsLayer: [],
  30. selectGislist: '',
  31. setcenterpoint: '', //中心点
  32. cityName: '', //城市名称
  33. };
  34. },
  35. computed: {
  36. searchPointInfo() {
  37. return this.$store.getters['getSearchPointInfo'].XY;
  38. }
  39. },
  40. created(){
  41. this.getzoom=2;
  42. },
  43. methods: {
  44. mapviewHandle(){
  45. this.view.on(['click'], (event) => {
  46. let point = event.mapPoint;
  47. // console.log(point.x, point.y);
  48. let item = {
  49. XY: [point.x, point.y],
  50. address: '',
  51. id: '',
  52. text: ''
  53. };
  54. this.$store.commit('setSearchPointInfo', item);
  55. this.centerAtByPoint();
  56. this.view.hitTest(event).then((response) => {
  57. if (response.results.length) {
  58. } else {
  59. }
  60. });
  61. });
  62. this.centerAtByPoint();
  63. },
  64. centerAtByPointXY(x, y) {
  65. if(!x||!y){
  66. // this.$message.error("坐标错误")
  67. return
  68. }
  69. var point = new this.gisConstructor.Point({
  70. type: 'point',
  71. x: x,
  72. y: y,
  73. spatialReference: this.wkidval
  74. });
  75. this.view.center = point;
  76. this.view.zoom = 2;
  77. },
  78. centerAtByPoint() {
  79. if(this.map.findLayerById('linshiLayer')){
  80. this.map.remove(this.map.findLayerById('linshiLayer'));
  81. }
  82. this.graphicsLayer = new this.gisConstructor.GraphicsLayer({
  83. id: 'linshiLayer',
  84. name: '临时图层',
  85. opacity: 1,
  86. visible: true
  87. });
  88. this.map.add(this.graphicsLayer);
  89. this.graphicsLayer.removeAll();
  90. let pointXY = this.searchPointInfo;
  91. if(!this.searchPointInfo)return
  92. var point = new this.gisConstructor.Point({
  93. type: 'point',
  94. x: pointXY[0],
  95. y: pointXY[1],
  96. spatialReference: this.wkidval
  97. });
  98. this.view.center = point;
  99. this.view.zoom = 18;
  100. // var graphicsLayer = new this.gisConstructor.GraphicsLayer({
  101. // id: 'linshiLayer',
  102. // name: '临时图层',
  103. // opacity: 1,
  104. // visible: true
  105. // });
  106. // this.map.add(graphicsLayer);
  107. var tempAData = {
  108. 名称: '定位点',
  109. // "json": string2Array(item.json),
  110. id: '1111'
  111. // value: valueval
  112. // alarm: "",
  113. // areaName: "",
  114. };
  115. // 设置点的样式
  116. var pictureMarkerSymbol = {
  117. type: 'picture-marker',
  118. url: location,
  119. width: '16px',
  120. height: '24px'
  121. // yoffset: '-20px'
  122. };
  123. var pointGraphic = new this.gisConstructor.Graphic({
  124. geometry: point,
  125. symbol: pictureMarkerSymbol,
  126. // popupTemplate: popupTemplate,
  127. attributes: tempAData
  128. });
  129. this.graphicsLayer.add(pointGraphic);
  130. },
  131. // 模糊查询定位
  132. fuzzyQueryLocation(queryString,cb){
  133. var findTask = new this.gisConstructor.FindTask(this.baseUrl);
  134. // FindTask的参数
  135. var findParams = new this.gisConstructor.FindParameters();
  136. // 返回Geometry
  137. findParams.returnGeometry = true;
  138. // 查询的图层id
  139. findParams.layerIds = [1,2,3,4,5,6,7];
  140. // 查询字段
  141. findParams.searchFields = "TEXTSTRING";
  142. findParams.searchText = queryString;
  143. findTask.execute(findParams).then(res=>{
  144. cb(res.results)
  145. });
  146. // findTask.on("complete", lang.hitch(this, function(evt) {
  147. // gisCommonFunction.excuteCallBack(successCallBack, evt.result);
  148. // }));
  149. }
  150. }
  151. };
  152. </script>