map.nvue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="content">
  3. <map class="map" ref="map1" :controls="controls" :scale="scale" :longitude="location.longitude" :latitude="location.latitude"
  4. :show-location="showLocation" :enable-3D="enable3D" :rotate="rotate" :skew="skew" :show-compass="showCompass"
  5. :enable-overlooking="enableOverlooking" :enable-zoom="enableZoom" :enable-scroll="enableScroll"
  6. :enable-rotate="enableRotate" :enable-satellite="enableSatellite" :enable-traffic="enableTraffic" :markers="markers"
  7. :polyline="polyline" :circles="circles" :polygons="polygons" :include-points="includePoints"></map>
  8. <view class="line"></view>
  9. <uni-list class="scrollview">
  10. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enable3D" title="显示3D楼块" @switchChange="enableThreeD" />
  11. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="showCompass" title="显示指南针" @switchChange="changeShowCompass" />
  12. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableOverlooking" title="开启俯视" @switchChange="changeEnableOverlooking" />
  13. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableZoom" title="是否支持缩放" @switchChange="changeEnableZoom" />
  14. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableScroll" title="是否支持拖动" @switchChange="changeEnableScroll" />
  15. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableRotate" title="是否支持旋转" @switchChange="changeEnableRotate" />
  16. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableSatellite" title="是否开启卫星图" @switchChange="changeEnableSatellite" />
  17. <uni-list-item :show-arrow="false" :show-switch="true" :switch-checked="enableTraffic" title="是否开启实时路况" @switchChange="changeEnableTraffic" />
  18. </uni-list>
  19. </view>
  20. </template>
  21. <script>
  22. const testMarkers = [{
  23. id: 0,
  24. latitude: 39.989631,
  25. longitude: 116.481018,
  26. title: '方恒国际 阜通东大街6号',
  27. zIndex: '1',
  28. rotate: 0,
  29. width: 20,
  30. height: 20,
  31. anchor: {
  32. x: 0.5,
  33. y: 1
  34. },
  35. callout: {
  36. content: '方恒国际 阜通东大街6号',
  37. color: '#00BFFF',
  38. fontSize: 10,
  39. borderRadius: 4,
  40. borderWidth: 1,
  41. borderColor: '#333300',
  42. bgColor: '#CCFF99',
  43. padding: '5',
  44. display: 'ALWAYS'
  45. }
  46. },
  47. {
  48. id: 1,
  49. latitude: 39.9086920000,
  50. longitude: 116.3974770000,
  51. title: '天安门',
  52. zIndex: '1',
  53. iconPath: '/static/location.png',
  54. width: 40,
  55. height: 40,
  56. anchor: {
  57. x: 0.5,
  58. y: 1
  59. },
  60. callout: {
  61. content: '首都北京\n天安门',
  62. color: '#00BFFF',
  63. fontSize: 12,
  64. borderRadius: 2,
  65. borderWidth: 0,
  66. borderColor: '#333300',
  67. bgColor: '#CCFF11',
  68. padding: '1',
  69. display: 'ALWAYS'
  70. }
  71. }
  72. ];
  73. const testPolyline = [{
  74. points: [{
  75. latitude: 39.925539,
  76. longitude: 116.279037
  77. },
  78. {
  79. latitude: 39.925539,
  80. longitude: 116.520285
  81. }
  82. ],
  83. color: '#FFCCFF',
  84. width: 7,
  85. dottedLine: true,
  86. arrowLine: true,
  87. borderColor: '#000000',
  88. borderWidth: 2
  89. },
  90. {
  91. points: [{
  92. latitude: 39.938698,
  93. longitude: 116.275177
  94. },
  95. {
  96. latitude: 39.966069,
  97. longitude: 116.289253
  98. },
  99. {
  100. latitude: 39.944226,
  101. longitude: 116.306076
  102. },
  103. {
  104. latitude: 39.966069,
  105. longitude: 116.322899
  106. },
  107. {
  108. latitude: 39.938698,
  109. longitude: 116.336975
  110. }
  111. ],
  112. color: '#CCFFFF',
  113. width: 5,
  114. dottedLine: true,
  115. arrowLine: true,
  116. borderColor: '#CC0000',
  117. borderWidth: 3
  118. }
  119. ];
  120. const testPolygons = [{
  121. points: [{
  122. latitude: 39.781892,
  123. longitude: 116.293413
  124. },
  125. {
  126. latitude: 39.787600,
  127. longitude: 116.391842
  128. },
  129. {
  130. latitude: 39.733187,
  131. longitude: 116.417932
  132. },
  133. {
  134. latitude: 39.704653,
  135. longitude: 116.338255
  136. }
  137. ],
  138. fillColor: '#FFCCFF',
  139. strokeWidth: 3,
  140. strokeColor: '#CC99CC',
  141. zIndex: 11
  142. },
  143. {
  144. points: [{
  145. latitude: 39.887600,
  146. longitude: 116.518932
  147. },
  148. {
  149. latitude: 39.781892,
  150. longitude: 116.518932
  151. },
  152. {
  153. latitude: 39.781892,
  154. longitude: 116.428932
  155. },
  156. {
  157. latitude: 39.887600,
  158. longitude: 116.428932
  159. }
  160. ],
  161. fillColor: '#CCFFFF',
  162. strokeWidth: 5,
  163. strokeColor: '#CC0000',
  164. zIndex: 3
  165. }
  166. ];
  167. const testCircles = [{
  168. latitude: 39.996441,
  169. longitude: 116.411146,
  170. radius: 15000,
  171. strokeWidth: 5,
  172. color: '#CCFFFF',
  173. fillColor: '#CC0000'
  174. },
  175. {
  176. latitude: 40.096441,
  177. longitude: 116.511146,
  178. radius: 12000,
  179. strokeWidth: 3,
  180. color: '#CCFFFF',
  181. fillColor: '#FFCCFF'
  182. },
  183. {
  184. latitude: 39.896441,
  185. longitude: 116.311146,
  186. radius: 9000,
  187. strokeWidth: 1,
  188. color: '#CCFFFF',
  189. fillColor: '#CC0000'
  190. }
  191. ];
  192. const testIncludePoints = [{
  193. latitude: 39.989631,
  194. longitude: 116.481018,
  195. },
  196. {
  197. latitude: 39.9086920000,
  198. longitude: 116.3974770000,
  199. }
  200. ];
  201. export default {
  202. data() {
  203. return {
  204. location: {
  205. longitude: 116.3974770000,
  206. latitude: 39.9086920000
  207. },
  208. controls: [{
  209. id: 1,
  210. position: {
  211. left: 5,
  212. top: 180,
  213. width: 30,
  214. height: 30
  215. },
  216. iconPath: '/static/logo.png',
  217. clickable: true
  218. }],
  219. showLocation: false,
  220. scale: 13,
  221. showCompass: true,
  222. enable3D: true,
  223. enableOverlooking: true,
  224. enableOverlooking: true,
  225. enableZoom: true,
  226. enableScroll: true,
  227. enableRotate: true,
  228. enableSatellite: false,
  229. enableTraffic: false,
  230. polyline: [],
  231. markers: [],
  232. polygons: [],
  233. circles: [],
  234. includePoints: [],
  235. rotate: 0,
  236. skew: 0
  237. }
  238. },
  239. onLoad() {},
  240. methods: {
  241. changeScale() {
  242. this.scale = this.scale == 9 ? 15 : 9;
  243. },
  244. changeRotate() {
  245. this.rotate = this.rotate == 90 ? 0 : 90;
  246. },
  247. changeSkew() {
  248. this.skew = this.skew == 30 ? 0 : 30;
  249. },
  250. enableThreeD(e) {
  251. this.enable3D = e.value;
  252. },
  253. changeShowCompass(e) {
  254. this.showCompass = e.value;
  255. },
  256. changeEnableOverlooking(e) {
  257. this.enableOverlooking = e.value;
  258. },
  259. changeEnableZoom(e) {
  260. this.enableZoom = e.value;
  261. },
  262. changeEnableScroll(e) {
  263. this.enableScroll = e.value;
  264. },
  265. changeEnableRotate(e) {
  266. this.enableRotate = e.value;
  267. },
  268. changeEnableSatellite(e) {
  269. this.enableSatellite = e.value;
  270. },
  271. changeEnableTraffic(e) {
  272. this.enableTraffic = e.value;
  273. }
  274. }
  275. }
  276. </script>
  277. <style>
  278. .content {
  279. flex: 1;
  280. }
  281. .map {
  282. width: 750rpx;
  283. height: 250px;
  284. background-color: #f0f0f0;
  285. }
  286. .line {
  287. height: 4px;
  288. }
  289. .scrollview {
  290. flex: 1;
  291. }
  292. </style>