xianshiLJ.nvue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view>
  3. <view >
  4. <web-view ref="webview" :style="{ height: statusBarHeight + 'px'}" :src="mapUrl" @onPostMessage="getMessage"></web-view>
  5. </view>
  6. <view style="margin-top: 40rpx;background-color: burlywood;height: 60rpx;" @click="xianshilj">显示路径</view>
  7. </view>
  8. </template>
  9. <script>
  10. import {getOSMAround,geoByName} from "@/pages/api/mapAPI.js"
  11. var wv=null;//计划创建的webview
  12. export default {
  13. data() {
  14. return {
  15. mapUrl: '',// 你保存的 HTML
  16. statusBarHeight:0,
  17. screenWidth:0,
  18. }
  19. },
  20. onLoad() {
  21. console.log("onLoad");
  22. this.statusBarHeight = uni.getSystemInfoSync().screenHeight-240;
  23. this.screenWidth = uni.getSystemInfoSync().screenWidth+100;
  24. this.mapUrl='/hybrid/html/openMap/pathmap.html?shstate=0&dlat=22.822607&dlng=108.373454'
  25. },
  26. onShow() {
  27. console.log("onShow");
  28. var that = this;
  29. setTimeout(function() {
  30. that.showMark();
  31. }, 3600); //需要延时一下,防抖动
  32. },
  33. methods:{
  34. getMessage(e) {
  35. console.log("--getMessage--",e);
  36. },
  37. showMark(){
  38. getOSMAround(22.822607, 108.373454, 600)
  39. .then(data => {
  40. console.log("附近OSM对象:", data);
  41. var poiObj = data[0];
  42. var jwd = {
  43. lat:poiObj.lat,
  44. lon:poiObj.lon
  45. }
  46. var obj={
  47. payload:jwd,
  48. type:1
  49. };
  50. var str = JSON.stringify(obj);
  51. console.log(obj);
  52. this.$refs.webview.evalJs('showAddrMark('+str+')');
  53. })
  54. .catch(err => {
  55. console.error(err);
  56. });
  57. },
  58. }
  59. }
  60. </script>
  61. <style>
  62. .container { width: 100%; height: 100vh; }
  63. </style>