From: Adam Hoyle Date: Wed, 11 Aug 2021 22:45:44 +0000 (+0100) Subject: add osm-community-index and parse in communities X-Git-Tag: live~1469^2~47 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/59e6cdebdc84b408b51a870eab9ff83209074da5?hp=26aecfb2bf75c68ab7e396011662bf6c55057f77 add osm-community-index and parse in communities --- diff --git a/app/models/communities.rb b/app/models/communities.rb index 89a09cf05..d09d62d6a 100644 --- a/app/models/communities.rb +++ b/app/models/communities.rb @@ -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 diff --git a/package.json b/package.json index 8e4ac857e..89c0a83a5 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/yarn.lock b/yarn.lock index 15b11abd4..d95a1b317 100644 --- 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"