diff --git a/CHANGELOG.md b/CHANGELOG.md index ccece28ed..0adfd4324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +### 4.8.14 +- Added global statistics download +- Fixed PAME file downloads +- Limited map zoom on global WMS layer +- Updated external API calls to work after API changes +- Stopped trying to load geom into memory and use extent to determine whether PA is point or polygon +- Fixed region links on search results +- Minor text changes +- ### 4.8.13 - Removed MPA download option - Changed Mapbox basemap to most recent version diff --git a/app/assets/stylesheets/components/cards/cards/_cards-squares.scss b/app/assets/stylesheets/components/cards/cards/_cards-squares.scss index 3bc232a33..3e5fabfdb 100644 --- a/app/assets/stylesheets/components/cards/cards/_cards-squares.scss +++ b/app/assets/stylesheets/components/cards/cards/_cards-squares.scss @@ -60,5 +60,10 @@ $cards-squares-width-tablet: 48%; &:before { @include border-radius; } } + + &__title { + overflow-wrap: break-word; + text-align: center; + } } } \ No newline at end of file diff --git a/app/controllers/global_statistics_controller.rb b/app/controllers/global_statistics_controller.rb new file mode 100644 index 000000000..f065b2594 --- /dev/null +++ b/app/controllers/global_statistics_controller.rb @@ -0,0 +1,5 @@ +class GlobalStatisticsController < ApplicationController + def download + send_file GlobalStatistic.latest_csv, type: 'text/csv', disposition: 'attachment' + end +end diff --git a/app/controllers/pame_controller.rb b/app/controllers/pame_controller.rb index f2fa7ff90..3358f21e8 100644 --- a/app/controllers/pame_controller.rb +++ b/app/controllers/pame_controller.rb @@ -7,9 +7,6 @@ class PameController < ApplicationController filters: [] }.to_json - # Format for this date is: Year-MON (4 digits-3 chars) - UPDATED_AT = "2020-DEC".freeze - def index @table_attributes = PameEvaluation::TABLE_ATTRIBUTES.to_json @filters = PameEvaluation.filters_to_json @@ -26,10 +23,11 @@ def list end def download + last_update = PameEvaluation.last_csv_update_date.strftime('%Y-%^b') send_data PameEvaluation.to_csv(params.to_json), { type: "text/csv; charset=utf-8; header=present", disposition: "attachment", - filename: "protectedplanet-pame-#{UPDATED_AT}.csv" } + filename: "protectedplanet-pame-#{last_update}.csv" } end end diff --git a/app/controllers/protected_areas_controller.rb b/app/controllers/protected_areas_controller.rb index 8d830f8b6..164cb66aa 100644 --- a/app/controllers/protected_areas_controller.rb +++ b/app/controllers/protected_areas_controller.rb @@ -43,7 +43,8 @@ def show @map_options = { map: { - boundsUrl: @protected_area.extent_url + boundsUrl: @protected_area.extent_url, + maxZoom: 0 } } diff --git a/app/helpers/map_helper.rb b/app/helpers/map_helper.rb index 693e673bc..c1c3215eb 100644 --- a/app/helpers/map_helper.rb +++ b/app/helpers/map_helper.rb @@ -104,7 +104,7 @@ 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+#{iso3}&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson", padding: 5 } end diff --git a/app/javascript/components/map/default-options.js b/app/javascript/components/map/default-options.js index ed1d1bd39..8078d0178 100644 --- a/app/javascript/components/map/default-options.js +++ b/app/javascript/components/map/default-options.js @@ -17,6 +17,7 @@ export const MAP_OPTIONS_DEFAULT = { attributionControl: false, preserveDrawingBuffer: true, // needed for PDF rendering zoom: 1.3, + maxZoom: 10 // Maximum zoom where tiles are cached for the web-map service //bounds: [[-180, -90], [180, 90]], //boundingISO: ISO3, //boundingRegion; Name e.g. Europe, diff --git a/app/models/global_statistic.rb b/app/models/global_statistic.rb index a39045e8d..4922cbef4 100644 --- a/app/models/global_statistic.rb +++ b/app/models/global_statistic.rb @@ -39,4 +39,9 @@ def self.green_list_stats self.instance.send(column_name) end end + + def self.latest_csv + global_statistics_csvs = Dir.glob("#{Rails.root}/lib/data/seeds/global_statistics*") + global_statistics_csvs.sort.last + end end \ No newline at end of file diff --git a/app/models/pame_evaluation.rb b/app/models/pame_evaluation.rb index c7399de5e..46d3fcb78 100644 --- a/app/models/pame_evaluation.rb +++ b/app/models/pame_evaluation.rb @@ -336,6 +336,12 @@ def self.to_csv(json = nil) generate_csv(where_statement, restricted_where_statement) end + + def self.last_csv_update_date + pame_data_csvs = Dir.glob("#{Rails.root}/lib/data/seeds/pame_data*") + latest_pame_csv = pame_data_csvs.sort.last.split('_').last + latest_pame_csv.split('.').first.to_date + end end diff --git a/app/models/protected_area.rb b/app/models/protected_area.rb index f5f3b833f..3cb2b717b 100644 --- a/app/models/protected_area.rb +++ b/app/models/protected_area.rb @@ -237,12 +237,12 @@ def arcgis_layer end def arcgis_query_string - "/query?where=wdpaid+%3D+%27#{wdpa_id}%27&geometryType=esriGeometryEnvelope&returnGeometry=true&f=geojson" + "/query?where=wdpaid+%3D+#{wdpa_id}&geometryType=esriGeometryEnvelope&returnGeometry=true&f=geojson" end def extent_url { - url: "#{arcgis_layer}/query?where=wdpaid+%3D+%27#{wdpa_id}%27&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson", + url: "#{arcgis_layer}/query?where=wdpaid+%3D+#{wdpa_id}&returnGeometry=false&returnExtentOnly=true&outSR=4326&f=pjson", padding: 0.2 } end @@ -254,7 +254,10 @@ def is_whs? private def is_point? - the_geom.geometry_type.type_name.match('Point').present? + @is_point ||= begin + extent = bounds + extent[0][0] == extent[1][0] && extent[0][1] == extent[1][1] + end end def bounding_box_query diff --git a/app/serializers/search/areas_serializer.rb b/app/serializers/search/areas_serializer.rb index c0a6864e3..2b65c9639 100644 --- a/app/serializers/search/areas_serializer.rb +++ b/app/serializers/search/areas_serializer.rb @@ -34,7 +34,7 @@ def sites def geo_hash(geo_type, areas, total=0) areas = areas.present? ? areas.first(9) : [] - geo_type_locale = geo_type == 'site' ? 'area-types.wdpa' : "geo-types.#{geo_type.pluralize}" + geo_type_locale = "geo-types.#{geo_type.pluralize}" { geoType: geo_type, title: I18n.t("global.#{geo_type_locale}"), diff --git a/app/serializers/search/base_serializer.rb b/app/serializers/search/base_serializer.rb index 5560a1112..9901355ea 100644 --- a/app/serializers/search/base_serializer.rb +++ b/app/serializers/search/base_serializer.rb @@ -39,6 +39,8 @@ def url(obj) protected_area_path(obj.wdpa_id) elsif obj.is_a?(Country) country_path(iso: obj.iso_3) + elsif obj.is_a?(Region) + region_path(iso: obj.iso) else '#' end diff --git a/app/views/home/index.html.erb b/app/views/home/index.html.erb index 1b058dc58..fc08755db 100644 --- a/app/views/home/index.html.erb +++ b/app/views/home/index.html.erb @@ -8,6 +8,7 @@
<%= render partial: "partials/cards/facts", locals: { cards: @site_facts } %>

Statistics updated: <%= @update_date %>

+ <%= link_to('Download latest global statistics', global_statistics_download_path) %>
<%= render partial: "partials/search/protected-areas", locals: { config: @config_search_areas } %> diff --git a/app/views/partials/messages/_message-citation.html.erb b/app/views/partials/messages/_message-citation.html.erb index 917fef16b..f8a54720e 100644 --- a/app/views/partials/messages/_message-citation.html.erb +++ b/app/views/partials/messages/_message-citation.html.erb @@ -1,4 +1,4 @@

citation

-

UNEP-WCMC (<%= Date.today.year %>). Protected Area Profile for <%= title %> from the World Database of Protected Areas, <%= Date.today.strftime("%B %Y") %>. Available at: www.protectedplanet.net

+

UNEP-WCMC (<%= Date.today.year %>). Protected Area Profile for <%= title %> from the World Database on Protected Areas, <%= Date.today.strftime("%B %Y") %>. Available at: www.protectedplanet.net

\ No newline at end of file diff --git a/config/locales/global/en.yml b/config/locales/global/en.yml index 5ab55c60b..be9528f3e 100644 --- a/config/locales/global/en.yml +++ b/config/locales/global/en.yml @@ -20,6 +20,7 @@ en: geo-types: countries: Countries regions: Regions + sites: Protected Areas and OECMs logos: iucn: IUCN logo pp: Protected Planet logo diff --git a/config/locales/home/en.yml b/config/locales/home/en.yml index 020ca0069..0fe6cd389 100644 --- a/config/locales/home/en.yml +++ b/config/locales/home/en.yml @@ -3,13 +3,13 @@ en: facts: - theme: terrestrial - title: Terrestrial protected area coverage + title: Terrestrial and inland waters protected area coverage - theme: marine title: Marine protected area coverage - theme: oecm - title: Terrestrial protected area & OECM coverage + title: Terrestrial and inland waters protected area & OECM coverage - theme: oecm title: Marine protected area & OECM coverage @@ -34,14 +34,14 @@ en: icon: area categories: - - title: Marine Protected Areas + title: Marine Protected Areas and OECMs slug: /marine-protected-areas filter: 'marine' - - title: Terrestrial Protected Areas + title: Terrestrial and Inland Waters Protected Areas and OECMs slug: filter: 'terrestrial' - - title: Green Listed Protected Areas + title: Green Listed Protected Areas and OECMs slug: /green-list filter: 'is_green_list' diff --git a/config/locales/map/en.yml b/config/locales/map/en.yml index 2e699f3b3..e95cb9b88 100644 --- a/config/locales/map/en.yml +++ b/config/locales/map/en.yml @@ -6,14 +6,14 @@ en: greenlist_marine: title: Marine Green Listed Protected Areas terrestrial_wdpa: - title: Terrestrial Protected Areas + title: Terrestrial and Inland Waters Protected Areas marine_wdpa: title: Marine Protected Areas oecm_marine: title: Other effective area-based conservation measures oecm: title: Other effective area-based conservation measures - title: Discover Protected Areas + title: Discover Protected Areas and OECMs title_oecm: Discover OECMs disclaimer: heading: Map Disclaimer diff --git a/config/locales/search/en.yml b/config/locales/search/en.yml index 141cce959..cda29a089 100644 --- a/config/locales/search/en.yml +++ b/config/locales/search/en.yml @@ -40,7 +40,7 @@ en: filter-group-type: title: Type options: - terrestrial: Terrestrial + terrestrial: Terrestrial and inland waters marine: Marine geo-types: region: Regions diff --git a/config/locales/stats/en.yml b/config/locales/stats/en.yml index 5a5556757..9106b1470 100644 --- a/config/locales/stats/en.yml +++ b/config/locales/stats/en.yml @@ -13,8 +13,8 @@ en: total: Total marine and coastal area coverage_terrestrial: covered: Land area covered - title_wdpa: Terrestrial protected area coverage - title_wdpa_oecm: Terrestrial protected area & OECM coverage + title_wdpa: Terrestrial and inland waters protected area coverage + title_wdpa_oecm: Terrestrial and inland waters protected area & OECM coverage total: Total land area coverage-chart-smallprint: The graph excludes status years with no information reported (STATUS_YR = 0). countries: Number of countries diff --git a/config/routes.rb b/config/routes.rb index 5ed45e8c8..693959fac 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -34,6 +34,8 @@ get '/country/:iso/compare(/:iso_to_compare)', to: 'country#compare', as: 'compare_countries' get '/country/:iso/protected_areas', to: 'country#protected_areas', as: 'country_protected_areas' + get '/global_statistics_download', to: 'global_statistics#download' + # JSON endpoints get '/downloads/poll', to: 'downloads#poll', as: 'download_poll' resources :downloads, only: [:show, :create, :update] diff --git a/lib/modules/download/queries.rb b/lib/modules/download/queries.rb index 113ce3c07..3b89fa364 100644 --- a/lib/modules/download/queries.rb +++ b/lib/modules/download/queries.rb @@ -20,7 +20,8 @@ module Queries :metadataid, :data_title, :resp_party, :year, :update_yr, :char_set, :ref_system, :scale, :lineage, - :citation, :disclaimer, :language + :citation, :disclaimer, :language, + :verifier ] def self.for_points extra_columns={} diff --git a/lib/modules/wdpa/global_stats_importer.rb b/lib/modules/wdpa/global_stats_importer.rb index 1ba093e71..07fff3fc0 100644 --- a/lib/modules/wdpa/global_stats_importer.rb +++ b/lib/modules/wdpa/global_stats_importer.rb @@ -10,7 +10,10 @@ def self.import CSV.foreach(latest_global_statistics_csv, headers: true) do |row| field = row['type'] value = parse_value(row['value']) - attrs.merge!("#{field}": value) + + # The global_statistics csv can now be downloaded so a methodology url has been added + # to the end of the spreadsheet. We need to not add this line to the attributes. + attrs.merge!("#{field}": value) if field.present? end stats = GlobalStatistic.first_or_initialize(attrs)