-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix dependencies * Remove useless method * Fist version * improve lib and repair existing data * Change destination format * Fix readme * Fix tests * Add more tests * Add convert to commands * Remove unused js * Add dep to module * Fix offenses * Install proj * Add debugger * Add dep * Add new config * Pristine dep * Clean workflow * Update config * Remove unused test * Update apt cache * Pin dep * Add dep * Add readme * Setup cache action * Update readme * Debug * Setup concurrency level * reconstruct shared object cache after build * Add custom matcher * remove debug * Remove useless file * Add debug * Recompile with cache * Use env var * Fix missing require * Symbolize keys * Complete readme
- Loading branch information
1 parent
3710b53
commit 0e80a82
Showing
20 changed files
with
631 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
sudo apt-get update && sudo apt install cmake sqlite libtiff-dev curl libcurl4-openssl-dev libssl-dev -y | ||
|
||
if [ ! -d "$PROJ_VERSION" ]; then | ||
curl https://download.osgeo.org/proj/"${PROJ_VERSION}".tar.gz -o "${PROJ_VERSION}".tar.gz | ||
tar -xzf "${PROJ_VERSION}".tar.gz | ||
fi | ||
|
||
cd "$PROJ_VERSION" || exit | ||
|
||
if [ ! -d "build" ]; then | ||
mkdir build | ||
fi | ||
|
||
cd build || exit | ||
cmake .. | ||
sudo cmake --build . -j "$(nproc)" --target install | ||
sudo ldconfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,2 @@ | ||
import "proj4leaflet" | ||
import "leaflet" | ||
import "leaflet-tilelayer-here" | ||
import "leaflet-svgicon" | ||
import "leaflet.markercluster" | ||
import "src/decidim/homepage_interactive_map/interactive_map" | ||
import "src/decidim/homepage_interactive_map/scope" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
lib/decidim/homepage_interactive_map/coordinates_swapper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rgeo" | ||
require "rgeo/proj4" | ||
|
||
module Decidim | ||
module HomepageInteractiveMap | ||
# This class swaps the coordinates of a feature | ||
module CoordinatesSwapper | ||
def self.convert_geojson(geojson, opts = {}) | ||
return nil if geojson.nil? | ||
|
||
from = opts[:from] || detect_crs(geojson) || "EPSG:3857" | ||
to = opts[:to] || "EPSG:4326" | ||
|
||
geojson_clone = geojson.dup.deep_symbolize_keys | ||
new_coordinates = transform(geojson_clone[:parsed_geometry][:geometry][:coordinates], from, to) | ||
new_geometry = geojson_clone[:parsed_geometry][:geometry].merge( | ||
{ | ||
coordinates: new_coordinates, | ||
crs: to | ||
} | ||
) | ||
new_parsed_geometry = geojson_clone[:parsed_geometry].merge(geometry: new_geometry) | ||
|
||
geojson_clone.merge(parsed_geometry: new_parsed_geometry) | ||
end | ||
|
||
def self.transform(coordinates, from, to) | ||
return coordinates if from == to | ||
|
||
coord_sys_from = coord_sys(from) | ||
coord_sys_to = coord_sys(to) | ||
|
||
return transform_coords(coord_sys_from, coord_sys_to, coordinates.first, coordinates.last, nil) if coordinates.length == 2 | ||
|
||
coordinates.map do |coord| | ||
if coord.first.is_a?(Array) | ||
transform(coord, from, to) | ||
else | ||
lat, lon = coord | ||
transform_coords(coord_sys_from, coord_sys_to, lat, lon, nil) | ||
end | ||
end | ||
end | ||
|
||
def self.transform_coords(projection, geography, lat, lon, alt) | ||
RGeo::CoordSys::Proj4.transform_coords(projection, geography, lat, lon, alt) | ||
end | ||
|
||
def self.coord_sys(coord_sys) | ||
RGeo::CoordSys::Proj4.create(coord_sys) | ||
end | ||
|
||
def self.detect_crs(geojson) | ||
geojson.dup.deep_symbolize_keys.dig(:parsed_geometry, :geometry, :crs) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
require "decidim/homepage_interactive_map/coordinates_swapper" | ||
|
||
namespace :decidim_homepage_interactive_map do | ||
desc "Repair the interactive map data to ensure the geojson has a EPSG:3857 format" | ||
task repair_data: :environment do | ||
Decidim::Scope.where.not(geojson: nil).find_each do |scope| | ||
scope.update!(geojson: Decidim::HomepageInteractiveMap::CoordinatesSwapper.convert_geojson(scope.geojson)) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.