gpt4 book ai didi

javascript - 在 data.feature 对象上添加工具提示,就像我们可以为标记做的那样

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:34:18 24 4
gpt4 key购买 nike

我在 Google map API 项目上工作,我想在指针悬停在 map 项上时显示工具提示。使用标记时非常容易:您只需要在标记的选项 ( see this exemple ) 中输入“标题”,但我使用 data.feature 对象,但我不知道该怎么做?

我会继续研究为什么使用 data.feature 对象,因为它更容易管理不同的层。

function elemOver(event){
console.log(event.feature.getProperty("Libelle")); // I put a console.log to test the listener but I don't know how to do to add a tooltip
};

function elemOut(event){
console.log (event.feature.getProperty("Libelle")," out"); // I put a console.log to test the listener but I don't know how to do to add a tooltip
};

data = new google.maps.Data();
data.loadGeoJson('layer.geojson');
data.setMap(map);
data.addListener('mouseover',elemOver);
data.addListener('mouseout',elemOut);

你可以在这里看到我的作品:http://bescu.github.io/GoogleMapsApiTest/

谢谢,

马克西姆

最佳答案

使用 setStyle 并将函数作为参数:

当您将它与函数一起用作参数时,您可以根据功能的属性(例如 Libelle)设置样式(例如 title)

   map.data.setStyle(function(feature){
return {
title:feature.getProperty('Libelle')||null
//more styles
};
});

演示: http://jsfiddle.net/doktormolle/L58aprhf/

关于javascript - 在 data.feature 对象上添加工具提示,就像我们可以为标记做的那样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25787502/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com