]> git.openstreetmap.org Git - rails.git/commitdiff
add osm-community-index and parse in communities
authorAdam Hoyle <atomoil@gmail.com>
Wed, 11 Aug 2021 22:45:44 +0000 (23:45 +0100)
committerAdam Hoyle <atomoil@gmail.com>
Wed, 11 Aug 2021 22:45:44 +0000 (23:45 +0100)
app/models/communities.rb
package.json
yarn.lock

index 89a09cf051ce92cec5d628303e5d6b5cc08340fd..d09d62d6a54a6dd66aca67a3ca2b2ae26d1605e5 100644 (file)
@@ -1,9 +1,36 @@
 
-
+# require 'sprockets/railtie'
 
 class Communities
 
+  # include Sprockets::Helpers::RailsHelper
+
   def self.local_chapters
-    array_string_ = ["Local Chapter 1", "Local Chapter 2", "Local Chapter 3", "Another one", "And Another"]
+    self.load_local_chapters
   end
+
+  protected
+
+  def self.load_local_chapters
+    puts Dir.pwd
+    json_file = File.expand_path("node_modules/osm-community-index/dist/completeFeatureCollection.json", Dir.pwd);
+    # json_file = File.expand_path("./node_modules/osm-community-index", Dir.pwd);
+
+    path = File.exist?(json_file) # Dir.pwd # File.open(json_file, "r")
+    community_index = JSON.parse(File.read(json_file))
+
+    array_of_entries = []
+    community_index['features'].each do |feature|
+      feature['properties']['resources'].each do |id, data|
+        data.each do |key, value|
+          if key == "type" and value == "osm-lc"
+            array_of_entries.push(id);
+          end
+        end
+      end
+    end
+
+    return array_of_entries
+  end
+
 end
index 8e4ac857efd6cb66866a96d2e67a18389e57a013..89c0a83a5df9312a343fe59aa2ed31655b0813d8 100644 (file)
@@ -8,6 +8,7 @@
     "js-cookie": "^3.0.0",
     "leaflet": "^1.6.0",
     "leaflet.locatecontrol": "^0.74.0",
+    "osm-community-index": "^5.1.2",
     "qs": "^6.9.4"
   },
   "devDependencies": {
index 15b11abd46edd773744544178ba55ac25c89fdbe..d95a1b317c5158ba706268f8670682969a7bffce 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -229,6 +229,11 @@ deep-is@^0.1.3:
   resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34"
   integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=
 
+diacritics@^1.3.0:
+  version "1.3.0"
+  resolved "https://registry.yarnpkg.com/diacritics/-/diacritics-1.3.0.tgz#3efa87323ebb863e6696cebb0082d48ff3d6f7a1"
+  integrity sha1-PvqHMj67hj5mls67AILUj/PW96E=
+
 doctrine@^3.0.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-3.0.0.tgz#addebead72a6574db783639dc87a121773973961"
@@ -654,6 +659,13 @@ optionator@^0.9.1:
     type-check "^0.4.0"
     word-wrap "^1.2.3"
 
+osm-community-index@^5.1.2:
+  version "5.1.2"
+  resolved "https://registry.yarnpkg.com/osm-community-index/-/osm-community-index-5.1.2.tgz#dbae073ce3f10177bfc1749623b632e62b12eeaf"
+  integrity sha512-4kYj81tFZZwDBYY1Kl+JyACNuwYPBqNrwlmxWEK7+tFCqmIg/pYBKzSDP1M5z+NuNfyuAtLR4opwN3dpCUI/uQ==
+  dependencies:
+    diacritics "^1.3.0"
+
 parent-module@^1.0.0:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2"