快乐的琪宝贝
快乐的琪宝贝
  • 发布:2023-02-22 14:09
  • 更新:2023-03-29 10:46
  • 阅读:276

h5调用includePoints会报错

分类:uni-app
2023-02-22 14:09 负责人:无 分享
已邀请:
DCloud_UNI_WZF

DCloud_UNI_WZF

提供下测试工程

  • 快乐的琪宝贝 (作者)


    <template>

    <view>

    <view class="page-body">

    <view class="page-section page-section-gap">

    <map

    id="mapId"

    style="width: 100%; height: 300px"

    latitude="latitude"

    longitude="longitude"

    markers="covers"
    >

    </map>

    </view>

    </view>

    </view>

    </template>

    <script>

    export default {

    data() {

    return {

    id: 0, // 使用 marker点击事件 需要填写id

    title: "map",

    latitude: 39.909,

    longitude: 116.39742,

    covers: [

    {

    latitude: 39.909,

    longitude: 116.39742,

    iconPath:

    "https://activity-h5.starcharge.com/wechat/wechatImgs/map/mapAggBg.png",

    },

    {

    latitude: 39.9,

    longitude: 117.39,

    iconPath:

    "https://activity-h5.starcharge.com/wechat/wechatImgs/map/mapAggBg.png",

    },

    ],

    mapCtx: "",

    };

    },

    created() {

    this.$nextTick(() => {

    this.mapCtx = uni.createMapContext("mapId", this);

    console.log('this.mapCtx: ', this.mapCtx);

    this.mapCtx.includePoints({

    points: this.covers,

    });

    console.log("xaxsasx");

    });

    },

    methods: {},

    };

    </script>

    2023-02-22 15:38

DCloud_UNI_WZF

DCloud_UNI_WZF

map 组件 web端支持 include-points 属性
mapContext includePoints 方法并不支持 web端 文档

vishun

vishun

高德地图可以参考这个临时解决: H5 Map组件高德地图includePoints无效

  • map组件中增加监听mapready
    <map ref="map" class="map":latitude="latitude" :longitude="longitude" :markers="markers" :polyline="polyline"  
       @mapready="handleMapReady" >  
    </map>  
  • 调用高德的setFitView方法
    handleMapReady() {  
    this.$refs.map._map.setFitView()  
    }  

要回复问题请先登录注册