[英]Android GoogleMaps: GeoJsonLayer.features change the order of geojson file
我有一個location
geojson 文件,如下所示:
{
"type":"FeatureCollection",
"features":[
{"type":"Feature","properties":{"name":"West"}},
{"type":"Feature","properties":{"name":"East"}},
{"type":"Feature","properties":{"name":"North"}}
]}
var geoJsonLayer = GeoJsonLayer(googleMap, R.raw.location, this)
geoJsonLayer.features.forEach {
print(it.properties)
}
我發現geoJsonLayer.features
的順序變成了:
{
"East",
"West",
"North"
}
官方文檔沒有說明它是否隨機返回特征元素。
我想迭代geoJsonLayer.features
以按照location
文件中顯示的順序獲取properties
。
有什么解決方法嗎?
這是因為geoJsonLayer.features
是一個HashMap
並且迭代順序取決於鍵。 理論上你可以用LinkedHashMap
替換HashMap
in BiMultiMap.java
class of utils library
//public class BiMultiMap<K> extends HashMap<K, Object> {
public class BiMultiMap<K> extends LinkedHashMap<K, Object> {
但似乎最簡單的方法是通過自定義比較器對geoJsonLayer.features
的值進行排序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.