Google Map迭代所有对象 [英] Google Map Iterate through all the objects
问题描述
我动态加载json地图数据。数据加载完成后,我想遍历地图上的所有项目(特征)。然后我想添加一个'侦听器',当用户点击该功能。
map.data.forEach(function(feature ){
console.log(功能);
map.data.addListener(功能,'点击',功能(事件){
console.log('点击')) ;
});
});
当我在console.log(feature)中存在对象时。 (见图)
其他示例显示map.data.addListener(多边形,'click',函数(event){////}
Loggin显示'feature.getGeometry()。getType()。toLowerCase()'=多边形,所以我知道我有很好的对象。
如何遍历所有对象并监听点击?
您可以在数据层中添加点击侦听器,例如这个谷歌示例,用点击(在.forEach之外)替换mouseover。
//设置每个功能的点击事件
map.data.addListener('click',function(event){
console.log('click');
});
I am dynamically loading json map data. Once the data is loaded, I wanted to iterate over all items (Features) on the map. Then I want to add a 'listener' when a user clicks on the feature.
map.data.forEach(function(feature) {
console.log(feature);
map.data.addListener(feature, 'click', function(event) {
console.log('click');
});
});
When I console.log(feature) there are objects. (see image)
Other examples show map.data.addListener(polygon, 'click', function(event) {////}
Loggin shows 'feature.getGeometry().getType().toLowerCase()' = polygon so I know I have good objects.
How do I iterate through all the objects and listen for the click?
You can add a click listener to the data layer like this google example, replacing the "mouseover" with "click" (outside of the .forEach).
// Set click event for each feature.
map.data.addListener('click', function(event) {
console.log('click');
});
这篇关于Google Map迭代所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!