1***@qq.com
1***@qq.com
  • 发布:2022-08-14 23:30
  • 更新:2023-02-25 10:54
  • 阅读:2708

nvue 页面地图map组件app端循环markers显示自定义气泡( 用的 customCallout)不显示

分类:nvue

在app端 nvue页面,如何遍历markers才能显示自定义气泡窗口?
直接指定 marker-id="1" 可以对应的点显示自定义气泡,但是循环遍历就不行,这是什呢原因,
通过真机调试可以看到 slot="c1. allout"中 渲染出来的 节点上都有visibility="false" 是什么原因呢???
到底应该怎么写呢?

<template>  
    <view style="background-color: antiquewhite;width: 100%;" :style="{height:winHeight + 'px'}">  
        <map ref="map" id="map" :latitude="latitude" :longitude="longitude" :style="{height:winHeight + 'px'}"  
            scale='18' :circles="circles" :includePoints='includePoints' @regionchange="regionchange" :markers="markers" @callouttap='callouttap'  
            :polyline="polylineObj" @tap='tap'>  
            <cover-view slot="callout">  
                <!-- 循环遍历不显示 -->  
                <cover-view :marker-id="index" class="selfstyle" v-for="(item,index) in markers" :key="index">  
                    <cover-image :src="'/static/ren.png'" style="width: 14px;height: 14px;"></cover-image>  
                    <text class="font-sm text-danger">{{item.title}}</text>  
                </cover-view>  

                <!-- 直接指定marker-id 后页面上可以正常显示,循环遍历就不显示 -->  
                <cover-view :marker-id="1" class="selfstyle">  
                    <cover-image :src="'/static/ren.png'" style="width: 14px;height: 14px;"></cover-image>  
                    <text class="font-sm text-danger">1</text>  
                </cover-view>  

            </cover-view>  

        </map>  
    </view>  
</template>  

<script>  
    export default {  
        data() {  
            return {  
                winHeight: 0,  
                longitude: '',  
                latitude: '',  
                _mapContext: null, //地图对象  
                markers: [],  
                markerscat: [],  
                str: '',  
                includePoints: [],  
                circles: [],  
                polylineObj: [],  
                orgMarker: {  
                    id: 1,  
                    title: 'org',  
                    longitude: 112.55371065112875,  
                    latitude: 37.77265732468224,  
                    customCallout: {  
                        anchorY: 0,  
                        anchorX: 0,  
                        display: 'ALWAYS'  
                    }  
                },  
                disMarker: {  
                    id: 2,  
                    title: 'dis',  
                    longitude: 112.65371065112875,  
                    latitude: 37.77265732468224,  
                    customCallout: {  
                        anchorY: 0,  
                        anchorX: 0,  
                        display: 'ALWAYS'  
                    }  
                }  
            }  
        },  
        mounted() {  
            this.init();  
        },  
        onReady() {  
            this._mapContext = uni.createMapContext('map', this);  
        },  
        methods: {  
            callouttap(e){  
                uni.showToast({  
                    title:JSON.stringify(e),  
                    icon:"none",  
                    duration: 5000  
                })  
            },  
            init() {  
                uni.getSystemInfo({  
                    success: (e) => {  
                        this.winHeight = e.windowHeight  
                    }  
                })  
                let _this = this;  

                uni.showLoading({  
                    title: '定位中'  
                })  

                uni.getLocation({  
                    type: 'gcj02',  
                    geocode: true,  
                    // isHighAccuracy: true,  
                    success: function(res) {  
                        // 移动视野位置到当前人所在位置  
                        _this._mapContext.moveToLocation({  
                            longitude: res.longitude,  
                            latitude: res.latitude  
                        });  

                        // 当前位置标记  
                        _this.disMarker.longitude = res.longitude;  
                        _this.disMarker.latitude = res.latitude;  

                        let list = []  
                        list.push(_this.orgMarker);  
                        list.push(_this.disMarker);  

                        // 标记点  
                        _this.markers = list;  
                        _this.markerscat = list;  

                        console.log(_this.markerscat.length);  

                        // 圆范围  
                        _this.circles = [{  
                            latitude: _this.orgMarker.latitude,  
                            longitude: _this.orgMarker.longitude,  
                            radius: 100,  
                            strokeWidth: 0,  
                            color: '#00000',  
                            fillColor: '#a0a0a096'  
                        }]  
                        // 连线  
                        _this.polylineObj = [{  
                            points: [{  
                                    latitude: _this.disMarker.latitude,  
                                    longitude: _this.disMarker.longitude  
                                },  
                                {  
                                    latitude: _this.orgMarker.latitude,  
                                    longitude: _this.orgMarker.longitude  
                                }  
                            ],  
                            arrowLine: false, //配置项:带箭头的线  
                            dottedLine: true,  
                            color: '#000000',  
                            width: 2, //配置项:线的宽度  
                        }, ]  

                        uni.hideLoading()  
                    }  
                });  
            },  
        }  
    }  
</script>  

<style lang="scss">  
    .selfstyle {  
        display: flex;  
        justify-content: center;  
        align-items: center;  
        border: 1px;  
        width: 130rpx;  
        z-index: 999;  
    }  

</style>  
2022-08-14 23:30 负责人:无 分享
已邀请:
2***@qq.com

2***@qq.com

更新map 的key就可以刷新 但是地图还是会闪一下

  • 哈哈哈888

    你好请问下,自定义的气泡会正常显示吗

    2023-01-30 16:44

  • 2***@qq.com

    回复 哈哈哈888: 可以

    2023-01-30 19:55

  • 哈哈哈888

    回复 2***@qq.com: 怎么解决的,求指教

    2023-01-31 08:27

  • while

    咋弄的耶,刷新key感觉没啥变化呢,nvue页面,我看id对应上的,但是不显示

    2023-11-29 15:32

DCloud_UNI_Anne

DCloud_UNI_Anne

<cover-view class="selfstyle" v-for="(item,index) in markers" :key="item.id"  :marker-id="item.id">    
         <cover-image :src="'/static/ren.png'" style="width: 14px;height: 14px;"></cover-image>    
         <text class="font-sm text-danger">{{item.title}}</text>    
 </cover-view>
  • 1***@qq.com (作者)

    您好,这个写法也还是不能显示呢,还有没有别的办法呢?我用的vivos12,跟手机有关系么?

    2022-08-16 22:57

  • DCloud_UNI_Anne

    回复 1***@qq.com: 我这正常,你换其他手机试试呢

    2022-08-17 11:41

6***@qq.com

6***@qq.com - 我只是个打工仔

解决了吗兄弟!我也是遇见这种问题了! nvue写的页面 小程序就可以显示自定义的气泡,app端就不行!

DCloud_UNI_Anne

DCloud_UNI_Anne

用这个测试看下

<template>  
    <view class="content">  
        <map id="map" :markers="covers" class="map" :show-location="true" :latitude="latitude" :longitude="longitude" @callouttap="oncallouttap">  
            <cover-view slot="callout">  
                <template v-for="(item,index) in covers">  
                    <cover-view :marker-id="item.id" :key="item.id" class="customCallout">  
                        <cover-image class="icon" src="../../static/0.png"></cover-image>  
                        <cover-view>  
                            customCallout  
                        </cover-view>  
                    </cover-view>  
                </template>  
            </cover-view>  
        </map>  
    </view>  
</template>  
<script>  
    const img = '/static/logo.png';  
    export default {  
        data() {  
            return {  
                latitude: 39.9086920000,  
                longitude: 116.3974770000,  
                covers: [{  
                        id: 1,  
                        latitude: 39.9086920000,  
                        longitude: 116.3974770000,  
                        iconPath: '../../static/logo.png',  
                        width: 40,  
                        height: 40,  
                        customCallout: {  
                            display: "ALWAYS"  
                        }  
                    },  
                    {  
                        id: 2,  
                        latitude: 39.9096920000,  
                        longitude: 116.3984770000,  
                        iconPath: '../../static/logo.png',  
                        width: 40,  
                        height: 40,  
                        customCallout: {  
                            display: "ALWAYS"  
                        }  
                    }  
                ]  
            }  
        },  
        methods: {  
            oncallouttap(e) {  
                uni.showModal({  
                    content: JSON.stringify(e)  
                })  
            }  
        }  
    }  
</script>  
<style>  
    .content {  
        flex: 1;  
    }  
    .icon {  
        width: 20px;  
        height: 20px;  
    }  
    .map {  
        width: 750rpx;  
        height: 500px;  
    }  
    .customCallout {  
        background-color: #aaffff;  
        border: 1px solid #ff5500;  
        border-radius: 30px;  
        width: 200px;  
        height: 40px;  
        display: flex;  
        flex-direction: row;  
        justify-content: center;  
        align-items: center;  
    }  
    .test{  
        width: 200px;  
        background-color: aliceblue;  
    }  
</style>  
  • _Nora_

    你给的这个例子是OK的。但是如果改一下,把cover放到setTimeout中,就会出现题主说的问题:


    <template>  
    <view class="content">
    <map id="map" :markers="covers" class="map" :show-location="true" :latitude="latitude" :longitude="longitude"
    @callouttap="oncallouttap">
    <cover-view slot="callout">
    <template v-for="(item,index) in covers">
    <cover-view :marker-id="item.id" :key="item.id" class="customCallout">
    <cover-image class="icon" src="../../static/0.png"></cover-image>
    <cover-view>
    customCallout
    </cover-view>
    </cover-view>
    </template>
    </cover-view>
    </map>
    </view>
    </template>
    <script>
    const img = '/static/logo.png';
    export default {
    data() {
    return {
    latitude: 39.9086920000,
    longitude: 116.3974770000,
    covers: []
    }
    },
    onLoad() {
    setTimeout(() => {
    this.covers = [{
    id: 1,
    latitude: 39.9086920000,
    longitude: 116.3974770000,
    iconPath: '../../static/logo.png',
    width: 40,
    height: 40,
    customCallout: {
    display: "ALWAYS"
    }
    },
    {
    id: 2,
    latitude: 39.9096920000,
    longitude: 116.3984770000,
    iconPath: '../../static/logo.png',
    width: 40,
    height: 40,
    customCallout: {
    display: "ALWAYS"
    }
    }
    ]
    }, 1000)
    },
    methods: {
    oncallouttap(e) {
    uni.showModal({
    content: JSON.stringify(e)
    })
    }
    }
    }
    </script>
    <style>
    .content {
    flex: 1;
    }

    .icon {
    width: 20px;
    height: 20px;
    }

    .map {
    width: 750rpx;
    height: 500px;
    }

    .customCallout {
    background-color: #aaffff;
    border: 1px solid #ff5500;
    border-radius: 30px;
    width: 200px;
    height: 40px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    }

    .test {
    width: 200px;
    background-color: aliceblue;
    }
    </style>

    2022-09-16 15:39

  • 1***@qq.com (作者)

    回复 1***@qq.com: 这个也不行呢,自定义的部分没有出来

    2022-10-08 14:08

  • 111444

    想问下加了 joinCluster: true, 安卓所有的点信息都不显示了怎么回事啊

    2022-12-07 14:10

2***@qq.com

2***@qq.com

我的也出现这样的问题,气泡不显示,但运行hello-uniapp 示例工程 ,就可以显示,是什么问题?

_Nora_

_Nora_

感觉像是视图上的自定义气泡没有根据响应式数据,进行重新渲染。我在map组件上写了个v-if="markers",就可以渲染出来了,但只是一个临时的方法

Geewoo_c

Geewoo_c

所以...这个问题有解决方案了么

  • 1***@qq.com (作者)

    目前是没有

    2022-10-08 11:18

  • Geewoo_c

    回复 1***@qq.com: 好吧,谢谢

    2022-10-12 15:43

  • 红A

    可以像楼上那位兄弟一样,使用v-if,强制刷新map。我就是用的这个方法

    this.isUpdate = false;

    this.$nextTick(() => {

    this.isUpdate = true

    );

    2022-11-17 16:20

  • Geewoo_c

    回复 红A: 直接换renderjs写了。。。

    2022-11-18 09:39

  • 哈哈哈888

    回复 红A: 你好请问下这个问题,看到您这边用v-if判断的会出现闪屏吗

    2023-01-30 14:15

QCW

QCW

这个问题 好了嘛,有时候出来 有时候出不来,有时候部分出来,不知道啥原因了

StarSky

StarSky - 前端工程师

promise或ajax等异步影响的,把自定义气泡数据声明在他们之前就可以显示出来了

  • QCW

    如果在地图里面有动态根据条件塞选的数据的 还是有问题,新版本3.7.3.20230223 说更新解决这个问题了 但是我刚刚试了一下 感觉还是不行

    2023-02-25 10:22

  • while

    定义在异步之前做个静态的?你这个回答等于没回答

    2023-11-21 19:54

2***@qq.com

2***@qq.com

3.5.3版本的可以显示。后面的版本都显示不了。

要回复问题请先登录注册