简体   繁体   English

如何在Mapbox Sdk中过滤标记

[英]How to filter markers in Mapbox Sdk

I'm creating an Android app using MapBox. 我正在使用MapBox创建一个Android应用程序。 I've already set up a simple map functionality with markers sourced from .json file. 我已经使用源自.json文件的标记设置了一个简单的地图功能。 Next step is filtering the markers on the map, just like in this gl-js example here: https://docs.mapbox.com/mapbox-gl-js/example/filter-markers/ 下一步是过滤地图上的标记,就像这里的gl-js示例一样: https//docs.mapbox.com/mapbox-gl-js/example/filter-markers/

I can't find any sdk examples anywhere, and since this is my first app I really can't figure it out on my own. 我无法在任何地方找到任何sdk示例,因为这是我的第一个应用程序,我真的无法自己弄明白。 Any help will be appreciated. 任何帮助将不胜感激。

You can check out this example https://docs.mapbox.com/android/maps/examples/multiple-expressions-temperature-change/ that features two layers that fetch a min or max temperature from the data source and display it. 您可以查看此示例https://docs.mapbox.com/android/maps/examples/multiple-expressions-temperature-change/ ,其中包含两个层,用于从数据源获取最小或最大温度并显示它。

The filtering part is done here : 过滤部分在这里完成:

      // Only display Maximum Temperature in this layer
      maxTempLayer.setFilter(eq(get("element"), literal("All-Time Maximum Temperature")));
      loadedMapStyle.addLayer(maxTempLayer);

Filters accept expressions as arguments, and here Expression.eq is used to compare "element" from the GeoJSON data source (referenced with the Expression.get ) with the "All-Time Maximum Temperature" value. 过滤器接受表达式作为参数,此处Expression.eq用于比较GeoJSON数据源(使用Expression.get引用)中的“element”和“All-Time Maximum Temperature”值。 If it resolves to true , the feature is going to be displayed, otherwise, it's going to be hidden. 如果它解析为true ,则会显示该功能,否则,它将被隐藏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM