Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapbox聚合图,click和mousemove获取到组成此聚合点要素信息 #38

Open
gangxuexue opened this issue Dec 26, 2019 · 1 comment

Comments

@gangxuexue
Copy link

问题:如题,mapbox的聚合demo是用三层layer合起来的,如果我添加点击事件,点击聚合点,如何获取其中的组成的聚合点其中各个要素信息?
image
我要知道其中7个要素信息,如果过滤出来

@goldenlimit
Copy link

hello @gangxuexue
我是來自iOS频道的佈道助手,看到你問到這個問題,试着先帮你解答下。
你可以嘗試用一下方法來獲取feature elements

 // Change the cursor style as a UI indicator.
            map.getCanvas().style.cursor = 'pointer';
            var feat = features[0]
            
            //LOOKUP THE HOVERED CLUSTER FEATURES UNDERLYING DATA POINTS
            var cluster_id = features[0].properties.cluster_id;
            var all_features = cluster.getLeaves(cluster_id, Math.floor(map.getZoom()), limit = Infinity);
            
            //DISPLAY THE HOVERED FEATURES IN THE POPUP
            var features_to_display = []
            all_features.forEach(function(f) {
                features_to_display.push(f.properties["Primary ID"])
            })
            // Populate the popup and set its coordinates
            // based on the feature found.

搜索到一個相關的issue 關於features in cluster,里面有一个哥们回复的一个demo你可以参考下
mapbox/mapbox-gl-js#3318 (comment)

他的这个Get features under a cluster应该是token过期了, 建议你根据现在有的cluster demo 然后参考我上面的那段代码就应该能access到features

希望对你有所帮助

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants