Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide alternative strategy for padding map around markers with settings #106

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions assets/javascripts/discourse/lib/map-utilities.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,25 @@ const setupMap = function (
[b[1], b[3]],
]);
} else if (markers) {
const maxZoom = siteSettings.location_map_marker_zoom;
map.fitBounds(markers.getBounds().pad(0.1), { maxZoom });
if (siteSettings.location_alternative_marker_map_padding_strategy) {
let bounds = markers.getBounds();
let fitZoom = map.getBoundsZoom(bounds);

map.setView(
bounds.getCenter(),
fitZoom -
siteSettings.location_alternative_marker_map_padding_zoom_out_extent
);
} else {
const maxZoom = siteSettings.location_map_marker_zoom;

map.fitBounds(
markers
.getBounds()
.pad(siteSettings.location_marker_map_padding_extent),
{ maxZoom }
);
}
} else {
const defaultLat = Number(siteSettings.location_map_center_lat);
const defaultLon = Number(siteSettings.location_map_center_lon);
Expand Down
3 changes: 3 additions & 0 deletions config/locales/server.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ en:
location_map_marker_category_color: "Set marker color as the category color of the marker topic."
location_map_maker_cluster_enabled: "Enable marker clustering"
location_map_zoom: "Default zoom level for maps."
location_marker_map_padding_extent: "Amount of padding around markers"
location_alternative_marker_map_padding_strategy: "Alternative strategy for padding a view of markers by zooming out x levels"
location_alternative_marker_map_padding_zoom_out_extent: "Level of zoom out (x) for alternative marker padding strategy"
location_map_expanded_zoom: "Default zoom level for expanded maps."
location_map_center_lat: "Default center latitude for maps."
location_map_center_lon: "Default center longitude for maps."
Expand Down
9 changes: 9 additions & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ plugins:
location_map_marker_zoom:
default: 16
client: true
location_marker_map_padding_extent:
default: 0.1
client: true
location_alternative_marker_map_padding_strategy:
default: false
client: true
location_alternative_marker_map_padding_zoom_out_extent:
default: 0.5
client: true
location_map_marker_cluster_multiplier:
default: 6
client: true
Expand Down
2 changes: 1 addition & 1 deletion plugin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
# name: discourse-locations
# about: Tools for handling locations in Discourse
# version: 6.5.1
# version: 6.5.2
# authors: Angus McLeod, Robert Barrow
# contact_emails: [email protected]
# url: https://github.com/angusmcleod/discourse-locations
Expand Down
Loading