Skip to content

Commit

Permalink
Merge branch 'chore/vector_tiles' into 'main'
Browse files Browse the repository at this point in the history
feat: add support for maptiler

See merge request decidim/decidim-module-geo!158
  • Loading branch information
Hadrien Froger committed Oct 20, 2024
2 parents 2ba0551 + 54069cd commit d07b70f
Show file tree
Hide file tree
Showing 11 changed files with 466 additions and 32 deletions.
2 changes: 2 additions & 0 deletions app/cells/decidim/geo/content_blocks/geo_maps_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ def map_config
lat: model.try(:latitude).nil? ? config.latitude : model.latitude,
lng: model.try(:longitude).nil? ? config.longitude : model.longitude,
tile_layer: config.tile,
maptiler_api_key: config.maptiler_api_key,
maptiler_style_id: config.maptiler_style_id,
zoom: config.zoom,
focus_zoom_level: config.focus_zoom_level,
force_geo_filter: config.default_geoencoded_filter
Expand Down
2 changes: 2 additions & 0 deletions app/commands/decidim/geo/admin/update_geo_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def attributes
latitude: form.latitude,
zoom: form.zoom,
tile: form.tile,
maptiler_api_key: form.maptiler_api_key,
maptiler_style_id: form.maptiler_style_id,
only_assemblies: form.only_assemblies,
only_processes: form.only_processes,
focus_zoom_level: form.focus_zoom_level,
Expand Down
2 changes: 2 additions & 0 deletions app/forms/decidim/geo/admin/geo_config_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class GeoConfigForm < Form
attribute :latitude, Float
attribute :zoom, Integer
attribute :tile, String
attribute :maptiler_api_key, String
attribute :maptiler_style_id, String
attribute :only_assemblies, Boolean
attribute :only_processes, Boolean
attribute :default_geoencoded_filter, Integer
Expand Down
2 changes: 2 additions & 0 deletions app/models/decidim/geo/geo_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def self.geo_config_default
longitude: 0,
zoom: 13,
tile: tile_layer_default,
maptiler_api_key: "",
maptiler_style_id: "",
default_geoencoded_filter: 1)
end

Expand Down
3 changes: 1 addition & 2 deletions app/packs/src/decidim/geo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import bootstrap from "./bootstrap";
import registerMobile from "./ui/mobile/registerMobile";
import FilterControl from "./ui/FilterControl";
import PageNameControl from "./ui/PageNameControl";

window.debug = window.debug || {};
window.debug.stores = () => ({
config: configStore.getState(),
Expand All @@ -29,7 +28,7 @@ async function prepareLeaflet(isSmallScreen) {
bootstrap();
// Parse and save server-side information.
const { map, tile } = await initMap();
configStore.setState(() => ({ map, tile, isSmallScreen }));
configStore.setState(() => ({ map, isSmallScreen }));
}
async function fetchData() {
const { addProcess, removeProcess, fetchAll, pointsForFilters } = pointStore.getState();
Expand Down
28 changes: 19 additions & 9 deletions app/packs/src/decidim/geo/ui/initMap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import L from "leaflet";
import configStore from "../stores/configStore";
import "leaflet.fullscreen";

import {init as initMapTiler} from "@maptiler/leaflet-maptilersdk";
const initMap = async () => {
const {
mapID,
map_config: { lat, lng, zoom, tile_layer },
map_config: { lat, lng, zoom, tile_layer, maptiler_api_key, maptiler_style_id },
i18n
} = configStore.getState();
const map = L.map(mapID, {
Expand All @@ -13,15 +14,24 @@ const initMap = async () => {
scrollWheelZoom: false,
fullscreenControl: false
});

map.zoomControl.setPosition("bottomright");

const tile = L.tileLayer(tile_layer, {
maxZoom: 19,
attribution:
'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
if(maptiler_api_key.length > 0){
initMapTiler()
new L.MaptilerLayer({
style: maptiler_style_id,
apiKey: maptiler_api_key}
).addTo(map)

}else{
L.tileLayer(tile_layer, {
maxZoom: 19,
attribution:
'&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);

}
L.control
.fullscreen({
position: "topright",
Expand All @@ -32,6 +42,6 @@ const initMap = async () => {
})
.addTo(map);

return { map, tile };
return { map };
};
export default initMap;
11 changes: 11 additions & 0 deletions app/views/decidim/geo/admin/geo_configs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@
<%= form.text_field :tile %>
</div>
</div>
<div class="row">
<div class="columns xlarge-6">
<%= form.text_field :maptiler_api_key %>
</div>
</div>
<div class="row"></div>
<div class="columns xlarge-6">
<%= form.text_field :maptiler_style_id %>
</div>
</div>

</div>

<div class="card-divider">
Expand Down
1 change: 1 addition & 0 deletions config/locales/decidim-geo.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ en:
longitude: Longitude
latitude: Latitude
tile: Tile
maptiler_api_key: Map tiler API Key (Optional)
actions:
update:
success: Configurations Updated
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20241019233857_add_vector_layer_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddVectorLayerConfig < ActiveRecord::Migration[6.1]
def change
add_column :decidim_geo_configs, :maptiler_api_key, :string, default: ""
add_column :decidim_geo_configs, :maptiler_style_id, :string, default: ""
end
end
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"@maptiler/leaflet-maptilersdk": "^2.0.0",
"buffer": "^6.0.3",
"date-fns": "^3.0.0",
"graphql": "16.6.0",
Expand Down
Loading

0 comments on commit d07b70f

Please sign in to comment.