如何在 ngx-mapbox-gl 中的标记上鼠标悬停时显示弹出窗口

发布于 2025-01-18 10:00:44 字数 984 浏览 3 评论 0原文

我目前正在单击标记时显示标记和弹出窗口。现在,我们需要在悬停上显示弹出窗口。

我的模板如下:

<mgl-map #map1 
    [style]="'mapbox://styles/mapbox/streets-v11'" 
    [zoom]="[4]"
    [maxZoom]="maxZoom"
    [center]="[-95.7129, 37.0902]"
    [fitBounds]="bounds"
    [fitBoundsOptions]="boundsOptions">
    <mgl-control mglNavigation [showCompass]="false"></mgl-control>
    <ngContainer *ngFor="let deal of unlockedDeals">
        <mgl-marker #myMarker [lngLat]="lngLat[deal.deal_id]">
            <div class="marker"></div>
            <span><b>{{ deal.deal_name }}</b></span>
        </mgl-marker>
        <mgl-popup [marker]="myMarker" class="" [closeButton]="true" [closeOnClick]="false"
            [anchor]="'top'">
            <div class="marker-popup-details">
             custom popup
            </div>
        </mgl-popup>
    </ngContainer>
</mgl-map>

与组件中的映射无关。

I am currently showing markers and popups on click of markers. We have a requirement now to show popups on hover.

my template is like below :

<mgl-map #map1 
    [style]="'mapbox://styles/mapbox/streets-v11'" 
    [zoom]="[4]"
    [maxZoom]="maxZoom"
    [center]="[-95.7129, 37.0902]"
    [fitBounds]="bounds"
    [fitBoundsOptions]="boundsOptions">
    <mgl-control mglNavigation [showCompass]="false"></mgl-control>
    <ngContainer *ngFor="let deal of unlockedDeals">
        <mgl-marker #myMarker [lngLat]="lngLat[deal.deal_id]">
            <div class="marker"></div>
            <span><b>{{ deal.deal_name }}</b></span>
        </mgl-marker>
        <mgl-popup [marker]="myMarker" class="" [closeButton]="true" [closeOnClick]="false"
            [anchor]="'top'">
            <div class="marker-popup-details">
             custom popup
            </div>
        </mgl-popup>
    </ngContainer>
</mgl-map>

no code relevant to map in component.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

路还长,别太狂 2025-01-25 10:00:44

您需要一个带有MOUSETOUT鼠标>事件的标记和一个弹出窗口:

<mgl-popup *ngIf="hoverFeature" [lngLat]="hoverFeature.geometry.coordinates" [closeButton]="false">
    <span>{{hoverFeature.properties.title}}</span>
</mgl-popup>
<mgl-marker [lngLat]="otherFeature.geometry.coordinates" anchor="bottom">
    <div (mouseover)="hoverFeature = otherFeature" (mouseout)="hoverFeature = null">
        {{otherFeature.properties.title}}
    </div>
</mgl-marker>

You need a marker with mouseout and mouseover events and a popup as such:

<mgl-popup *ngIf="hoverFeature" [lngLat]="hoverFeature.geometry.coordinates" [closeButton]="false">
    <span>{{hoverFeature.properties.title}}</span>
</mgl-popup>
<mgl-marker [lngLat]="otherFeature.geometry.coordinates" anchor="bottom">
    <div (mouseover)="hoverFeature = otherFeature" (mouseout)="hoverFeature = null">
        {{otherFeature.properties.title}}
    </div>
</mgl-marker>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文