Skip to content

Commit

Permalink
hotfix: allow oecm polygons to be displayed on the map
Browse files Browse the repository at this point in the history
  • Loading branch information
lucacug committed Apr 8, 2022
1 parent ef01212 commit d363c9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
13 changes: 7 additions & 6 deletions app/helpers/map_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
OECM_FEATURE_SERVER_LAYER_URL = 'https://data-gis.unep-wcmc.org/server/rest/services/ProtectedSites/The_World_Database_on_other_effective_area_based_conservation_measures/FeatureServer/0'
OECM_MAP_SERVER_URL = 'https://data-gis.unep-wcmc.org/server/rest/services/ProtectedSites/The_World_Database_on_other_effective_area_based_conservation_measures/MapServer'
OECM_LAYER_URL = OECM_MAP_SERVER_URL + '/0'
OECM_POINT_LAYER_URL = OECM_MAP_SERVER_URL + '/0'
OECM_POLY_LAYER_URL = OECM_MAP_SERVER_URL + '/1'
WDPA_FEATURE_SERVER_URL = 'https://data-gis.unep-wcmc.org/server/rest/services/ProtectedSites/The_World_Database_of_Protected_Areas/FeatureServer'
WDPA_MAP_SERVER_URL = 'https://data-gis.unep-wcmc.org/server/rest/services/ProtectedSites/The_World_Database_of_Protected_Areas/MapServer'
WDPA_POINT_LAYER_URL = WDPA_MAP_SERVER_URL + '/0'
Expand Down Expand Up @@ -86,13 +87,13 @@
module MapHelper
def overlays (ids, options={})
includedOverlays = OVERLAYS.select {|o| ids.include?(o[:id])}

includedOverlays.map do |defaultOptions|
customOptions = options[defaultOptions[:id].to_sym]
defaultOptions.merge(customOptions || {})
end
end

def map_yml
I18n.t('map')
end
Expand All @@ -103,11 +104,11 @@ def all_services_for_point_query

def country_extent_url (iso3)
{
url: "https://data-gis.unep-wcmc.org/server/rest/services/GADM_EEZ_Layer/FeatureServer/0/query?where=iso_ter+%3D+%27#{iso3}%27&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
url: "https://data-gis.unep-wcmc.org/server/rest/services/GADM_EEZ_Layer/FeatureServer/0/query?where=iso_ter+%3D+%27#{iso3}%27&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson",
padding: 5
}
end

def region_extent_url (name)
{
url: "https://data-gis.unep-wcmc.org/server/rest/services/EEZ_WVS/MapServer/0/query?where=geoandunep+%3D%27#{CGI.escape(name)}%27&text=&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&outFields=&returnGeometry=true&returnTrueCurves=false&maxAllowableOffset=&geometryPrecision=&outSR=4326&having=&returnIdsOnly=false&returnCountOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&gdbVersion=&historicMoment=&returnDistinctValues=false&resultOffset=&resultRecordCount=&queryByDistance=&returnExtentOnly=true&datumTransformation=&parameterValues=&rangeValues=&quantizationParameters=&featureEncoding=esriDefault&f=pjson",
Expand Down Expand Up @@ -140,4 +141,4 @@ def map_legend
{ theme: 'theme--oecm', title: I18n.t('map.overlays.oecm.title') }
]
end
end
end
12 changes: 6 additions & 6 deletions app/models/protected_area.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def self.greenlist_coverage_growth(start_year = 0)
) t
WHERE EXTRACT(YEAR FROM t.year) >= ?
SQL

result = ActiveRecord::Base.connection.execute(
ActiveRecord::Base.send(:sanitize_sql_array, [
growth, start_year
Expand All @@ -114,9 +114,9 @@ def self.greenlist_coverage_growth(start_year = 0)

def sources_per_pa
sources = ActiveRecord::Base.connection.execute("""
SELECT sources.title, EXTRACT(YEAR FROM sources.update_year) AS year, sources.responsible_party
SELECT sources.title, EXTRACT(YEAR FROM sources.update_year) AS year, sources.responsible_party
FROM sources
INNER JOIN protected_areas_sources
INNER JOIN protected_areas_sources
ON protected_areas_sources.protected_area_id = #{self.id}
AND protected_areas_sources.source_id = sources.id
""")
Expand Down Expand Up @@ -200,7 +200,7 @@ def self.sum_of_most_protected_marine_areas
reported_areas.inject(0){ |sum, area| sum + area.to_i }
end

def self.transboundary_sites
def self.transboundary_sites
ProtectedArea.joins(:countries)
.group('protected_areas.id')
.having('COUNT(countries_protected_areas.country_id) > 1')
Expand All @@ -209,7 +209,7 @@ def self.transboundary_sites
def is_transboundary
countries.count > 1
end

def arcgis_layer_config
{
layers: [{url: arcgis_layer, isPoint: is_point?}],
Expand All @@ -230,7 +230,7 @@ def layer_color

def arcgis_layer
if is_oecm
OECM_LAYER_URL
is point? ? OECM_POINT_LAYER_URL : OECM_POLY_LAYER_URL
else
is_point? ? WDPA_POINT_LAYER_URL : WDPA_POLY_LAYER_URL
end
Expand Down

0 comments on commit d363c9b

Please sign in to comment.