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

Fix missing map pins on rtl site #917

Merged
merged 2 commits into from
Aug 16, 2021
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
2 changes: 1 addition & 1 deletion static/js/theme-map/Maps/Providers/Google.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class GoogleMap extends ProviderMap {
constructor(options) {
super(options);

const zoomControlPosition = isRTL(options.language)
const zoomControlPosition = isRTL(options.locale)
? google.maps.ControlPosition.LEFT_TOP
: google.maps.ControlPosition.RIGHT_TOP;

Expand Down
2 changes: 1 addition & 1 deletion static/js/theme-map/Maps/Providers/Mapbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class MapboxMap extends ProviderMap {
// Add the zoom control
if (options.controlEnabled) {
const zoomControl = new mapboxgl.NavigationControl({showCompass: false})
isRTL(options.language)
isRTL(options.locale)
? this.map.addControl(zoomControl, 'top-left')
: this.map.addControl(zoomControl);
}
Expand Down
14 changes: 9 additions & 5 deletions static/js/theme-map/ThemeMapConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PinImages } from './PinImages.js';
import { ClusterPinImages } from './ClusterPinImages.js';
import { getLanguageForProvider } from './Util/helpers.js';
import { defaultCenterCoordinate } from './constants.js';
import isRTL from '../../common/rtl';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: line break after


/**
* The configuration for the ThemeMap component.
Expand Down Expand Up @@ -100,8 +101,8 @@ export default class ThemeMapConfig {
this.padding = {
top: () => window.innerWidth <= this.mobileBreakpointMax ? 150 : 50,
bottom: () => 50,
right: () => 50,
left: () => this.getLeftVisibleBoundary(),
right: () => isRTL(this.language) ? this.getVisibleBoundary() : 50,
left: () => !isRTL(this.language) ? this.getVisibleBoundary() : 50
};

/**
Expand Down Expand Up @@ -238,11 +239,14 @@ export default class ThemeMapConfig {
}

/**
* Get the leftmost point on the map, such that pins will still be visible
* Get the leftmost point on the map, or rightmost point for RTL locales, such that pins
* will still be visible.
*
* @return {Number} The boundary (in pixels) for the visible area of the map, from the left
* hand side of the viewport
* or right hand side of the viewport depending on if the language displayed
* is left-to-right or right-to-left
*/
getLeftVisibleBoundary () {
getVisibleBoundary () {
if (window.innerWidth <= this.mobileBreakpointMax) {
return 50;
}
Expand Down
2 changes: 1 addition & 1 deletion templates/vertical-full-page-map/markup/map.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div id="js-answersMap" class="Answers-map js-answersMap"></div>
<div id="js-answersMap" class="Answers-map js-answersMap" dir="ltr"></div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to flip the map for rtl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it mess with and pin placement (specifically the coordinate to css styling translation) on the map

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this cause the map to not be oriented correctly, for either google/mapbox? Like disregarding pin stuff, does anything else change if you add dir="ltr" on a rtl page

Copy link
Contributor Author

@yen-tt yen-tt Aug 16, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the map is oriented the same way for both ltr and rtl, only the pins are affected. the div that I added dir='ltr' only contains map related things like the canvas for the map and the pin clusters which we don't want rtl on. There's also the map control html elements but the position for those are specify for ltr and rtl in the map provider construction code. everything else on the page would follow ltr. tldr: nothing else change when I tested google and mapbox on the map pages

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it awesome!!

2 changes: 1 addition & 1 deletion templates/vertical-map/markup/map.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="Answers-map js-answersMap" id="js-answersMap"></div>
<div class="Answers-map js-answersMap" id="js-answersMap" dir="ltr"></div>