簡體   English   中英

Android GoogleMaps:GeoJsonLayer.features 更改 geojson 文件的順序

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM