map.nvue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <template>
  2. <view class="content">
  3. <map class="map" id="map1" ref="map1" :controls="controls" :scale="scale" :longitude="location.longitude"
  4. :latitude="location.latitude" :show-location="showLocation" :enable-3D="enable3D" :rotate="rotate" :skew="skew"
  5. :show-compass="showCompass" :enable-overlooking="enableOverlooking" :enable-zoom="enableZoom"
  6. :enable-scroll="enableScroll" :enable-rotate="enableRotate" :enable-satellite="enableSatellite"
  7. :enable-traffic="enableTraffic" :markers="markers" :polyline="polyline" :circles="circles" :polygons="polygons"
  8. :include-points="includePoints" @tap="maptap" @controltap="oncontroltap" @markertap="onmarkertap"
  9. @callouttap="oncallouttap" @poitap="onpoitap" @updated="onupdated" @regionchange="onregionchange"></map>
  10. <scroll-view class="scrollview" scroll-y="true">
  11. <!-- <view class="list-item">
  12. <text class="list-text">显示3D楼块</text>
  13. <switch :checked="enable3D" @change="enableThreeD" />
  14. </view>
  15. <view class="list-item">
  16. <text class="list-text">显示指南针</text>
  17. <switch :checked="showCompass" @change="changeShowCompass" />
  18. </view>
  19. <view class="list-item">
  20. <text class="list-text">开启俯视</text>
  21. <switch :checked="enableOverlooking" @change="changeEnableOverlooking" />
  22. </view>
  23. <view class="list-item">
  24. <text class="list-text">是否支持缩放</text>
  25. <switch :checked="enableZoom" @change="changeEnableZoom" />
  26. </view>
  27. <view class="list-item">
  28. <text class="list-text">是否支持拖动</text>
  29. <switch :checked="enableScroll" @change="changeEnableScroll" />
  30. </view>
  31. <view class="list-item">
  32. <text class="list-text">是否支持旋转</text>
  33. <switch :checked="enableRotate" @change="changeEnableRotate" />
  34. </view>
  35. <view class="list-item">
  36. <text class="list-text">是否开启卫星图</text>
  37. <switch :checked="enableSatellite" @change="changeEnableSatellite" />
  38. </view>
  39. <view class="list-item">
  40. <text class="list-text">是否开启实时路况</text>
  41. <switch :checked="enableTraffic" @change="changeEnableTraffic" />
  42. </view> -->
  43. <button class="button" @click="changeScale">changeScale</button>
  44. <button class="button" @click="changeRotate">changeRotate</button>
  45. <button class="button" @click="changeSkew">skew</button>
  46. <button class="button" @click="addMarkers">addMarkers</button>
  47. <button class="button" @click="addPolyline">addPolyline</button>
  48. <button class="button" @click="addPolygons">addPolygons</button>
  49. <button class="button" @click="addCircles">addCircles</button>
  50. <button class="button" @click="includePoint">includePoints</button>
  51. <button class="button" @click="handleGetCenterLocation">getCenterLocation</button>
  52. <button class="button" @click="handleGetRegion">getRegion</button>
  53. <button class="button" @click="handleTranslateMarker">translateMarker</button>
  54. </scroll-view>
  55. </view>
  56. </template>
  57. <script>
  58. const testMarkers = [{
  59. id: 0,
  60. latitude: 39.989631,
  61. longitude: 116.481018,
  62. title: '方恒国际 阜通东大街6号',
  63. zIndex: '1',
  64. rotate: 0,
  65. width: 20,
  66. height: 20,
  67. anchor: {
  68. x: 0.5,
  69. y: 1
  70. },
  71. callout: {
  72. content: '方恒国际 阜通东大街6号',
  73. color: '#00BFFF',
  74. fontSize: 10,
  75. borderRadius: 4,
  76. borderWidth: 1,
  77. borderColor: '#333300',
  78. bgColor: '#CCFF99',
  79. padding: '5',
  80. display: 'ALWAYS'
  81. }
  82. },
  83. {
  84. id: 1,
  85. latitude: 39.9086920000,
  86. longitude: 116.3974770000,
  87. title: '天安门',
  88. zIndex: '1',
  89. iconPath: '/static/location.png',
  90. width: 40,
  91. height: 40,
  92. anchor: {
  93. x: 0.5,
  94. y: 1
  95. },
  96. callout: {
  97. content: '首都北京\n天安门',
  98. color: '#00BFFF',
  99. fontSize: 12,
  100. borderRadius: 2,
  101. borderWidth: 0,
  102. borderColor: '#333300',
  103. bgColor: '#CCFF11',
  104. padding: '1',
  105. display: 'ALWAYS'
  106. }
  107. }
  108. ];
  109. const testPolyline = [{
  110. points: [{
  111. latitude: 39.925539,
  112. longitude: 116.279037
  113. },
  114. {
  115. latitude: 39.925539,
  116. longitude: 116.520285
  117. }
  118. ],
  119. color: '#FFCCFF',
  120. width: 7,
  121. dottedLine: true,
  122. arrowLine: true,
  123. borderColor: '#000000',
  124. borderWidth: 2
  125. },
  126. {
  127. points: [{
  128. latitude: 39.938698,
  129. longitude: 116.275177
  130. },
  131. {
  132. latitude: 39.966069,
  133. longitude: 116.289253
  134. },
  135. {
  136. latitude: 39.944226,
  137. longitude: 116.306076
  138. },
  139. {
  140. latitude: 39.966069,
  141. longitude: 116.322899
  142. },
  143. {
  144. latitude: 39.938698,
  145. longitude: 116.336975
  146. }
  147. ],
  148. color: '#CCFFFF',
  149. width: 5,
  150. dottedLine: true,
  151. arrowLine: true,
  152. borderColor: '#CC0000',
  153. borderWidth: 3
  154. }
  155. ];
  156. const testPolygons = [{
  157. points: [{
  158. latitude: 39.781892,
  159. longitude: 116.293413
  160. },
  161. {
  162. latitude: 39.787600,
  163. longitude: 116.391842
  164. },
  165. {
  166. latitude: 39.733187,
  167. longitude: 116.417932
  168. },
  169. {
  170. latitude: 39.704653,
  171. longitude: 116.338255
  172. }
  173. ],
  174. fillColor: '#FFCCFF',
  175. strokeWidth: 3,
  176. strokeColor: '#CC99CC',
  177. zIndex: 11
  178. },
  179. {
  180. points: [{
  181. latitude: 39.887600,
  182. longitude: 116.518932
  183. },
  184. {
  185. latitude: 39.781892,
  186. longitude: 116.518932
  187. },
  188. {
  189. latitude: 39.781892,
  190. longitude: 116.428932
  191. },
  192. {
  193. latitude: 39.887600,
  194. longitude: 116.428932
  195. }
  196. ],
  197. fillColor: '#CCFFFF',
  198. strokeWidth: 5,
  199. strokeColor: '#CC0000',
  200. zIndex: 3
  201. }
  202. ];
  203. const testCircles = [{
  204. latitude: 39.996441,
  205. longitude: 116.411146,
  206. radius: 15000,
  207. strokeWidth: 5,
  208. color: '#CCFFFF',
  209. fillColor: '#CC0000'
  210. },
  211. {
  212. latitude: 40.096441,
  213. longitude: 116.511146,
  214. radius: 12000,
  215. strokeWidth: 3,
  216. color: '#CCFFFF',
  217. fillColor: '#FFCCFF'
  218. },
  219. {
  220. latitude: 39.896441,
  221. longitude: 116.311146,
  222. radius: 9000,
  223. strokeWidth: 1,
  224. color: '#CCFFFF',
  225. fillColor: '#CC0000'
  226. }
  227. ];
  228. const testIncludePoints = [{
  229. latitude: 39.989631,
  230. longitude: 116.481018,
  231. },
  232. {
  233. latitude: 39.9086920000,
  234. longitude: 116.3974770000,
  235. }
  236. ];
  237. module.exports = {
  238. data() {
  239. return {
  240. location: {
  241. longitude: 116.3974770000,
  242. latitude: 39.9086920000
  243. },
  244. controls: [{
  245. id: 1,
  246. position: {
  247. left: 5,
  248. top: 180,
  249. width: 30,
  250. height: 30
  251. },
  252. iconPath: '/static/logo.png',
  253. clickable: true
  254. }],
  255. showLocation: false,
  256. scale: 13,
  257. showCompass: true,
  258. enable3D: true,
  259. enableOverlooking: true,
  260. enableOverlooking: true,
  261. enableZoom: true,
  262. enableScroll: true,
  263. enableRotate: true,
  264. enableSatellite: false,
  265. enableTraffic: false,
  266. polyline: [],
  267. markers: [],
  268. polygons: [],
  269. circles: [],
  270. includePoints: [],
  271. rotate: 0,
  272. skew: 0
  273. }
  274. },
  275. onLoad() {},
  276. onReady() {
  277. this.map = uni.createMapContext("map1", this);
  278. },
  279. methods: {
  280. changeScale() {
  281. this.scale = this.scale == 9 ? 15 : 9;
  282. },
  283. changeRotate() {
  284. this.rotate = this.rotate == 90 ? 0 : 90;
  285. },
  286. changeSkew() {
  287. this.skew = this.skew == 30 ? 0 : 30;
  288. },
  289. enableThreeD(e) {
  290. this.enable3D = e.detail.value;
  291. },
  292. changeShowCompass(e) {
  293. this.showCompass = e.detail.value;
  294. },
  295. changeEnableOverlooking(e) {
  296. this.enableOverlooking = e.detail.value;
  297. },
  298. changeEnableZoom(e) {
  299. this.enableZoom = e.detail.value;
  300. },
  301. changeEnableScroll(e) {
  302. this.enableScroll = e.detail.value;
  303. },
  304. changeEnableRotate(e) {
  305. this.enableRotate = e.detail.value;
  306. },
  307. changeEnableSatellite(e) {
  308. this.enableSatellite = e.detail.value;
  309. },
  310. changeEnableTraffic(e) {
  311. this.enableTraffic = e.detail.value;
  312. },
  313. addMarkers() {
  314. this.markers = testMarkers;
  315. },
  316. addPolyline() {
  317. this.polyline = testPolyline;
  318. },
  319. addPolygons() {
  320. this.polygons = testPolygons;
  321. },
  322. addCircles() {
  323. this.circles = testCircles;
  324. },
  325. includePoint() {
  326. this.includePoints = testIncludePoints;
  327. },
  328. handleGetCenterLocation() {
  329. this.map.getCenterLocation({
  330. success: ret => {
  331. console.log(JSON.stringify(ret));
  332. uni.showModal({
  333. content: JSON.stringify(ret)
  334. })
  335. }
  336. })
  337. },
  338. handleGetRegion() {
  339. this.map.getRegion({
  340. success: ret => {
  341. console.log(JSON.stringify(ret));
  342. uni.showModal({
  343. content: JSON.stringify(ret)
  344. })
  345. }
  346. })
  347. },
  348. handleTranslateMarker() {
  349. this.map.translateMarker({
  350. markerId: 1,
  351. destination: {
  352. latitude: 39.989631,
  353. longitude: 116.481018
  354. },
  355. duration: 2000
  356. }, ret => {
  357. console.log(JSON.stringify(ret));
  358. uni.showModal({
  359. content: JSON.stringify(ret)
  360. })
  361. });
  362. },
  363. maptap(e) {
  364. uni.showModal({
  365. content: JSON.stringify(e)
  366. })
  367. },
  368. onmarkertap(e) {
  369. uni.showModal({
  370. content: JSON.stringify(e)
  371. })
  372. },
  373. oncontroltap(e) {
  374. uni.showModal({
  375. content: JSON.stringify(e)
  376. })
  377. },
  378. oncallouttap(e) {
  379. uni.showModal({
  380. content: JSON.stringify(e)
  381. })
  382. },
  383. onupdated(e) {
  384. console.log(JSON.stringify(e))
  385. },
  386. onregionchange(e) {
  387. console.log(JSON.stringify(e));
  388. },
  389. onpoitap(e) {
  390. uni.showModal({
  391. content: JSON.stringify(e)
  392. })
  393. }
  394. }
  395. }
  396. </script>
  397. <style>
  398. .content {
  399. flex: 1;
  400. ;
  401. }
  402. .map {
  403. width: 750rpx;
  404. height: 250px;
  405. background-color: #f0f0f0;
  406. }
  407. .scrollview {
  408. flex: 1;
  409. padding: 10px;
  410. }
  411. .list-item {
  412. flex-direction: row;
  413. flex-wrap: nowrap;
  414. align-items: center;
  415. padding: 5px 0px;
  416. }
  417. .list-text {
  418. flex: 1;
  419. }
  420. .button {
  421. margin-top: 5px;
  422. margin-bottom: 5px;
  423. }
  424. </style>