Skip to content

Commit

Permalink
Explicitly specify font (fix #1281)
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Oct 11, 2024
1 parent a4caf0c commit 4428348
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/map/MapGeofence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useId, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { useTheme } from '@mui/styles';
import { map } from './core/MapView';
import { geofenceToFeature } from './core/mapUtil';
import { findFonts, geofenceToFeature } from './core/mapUtil';
import { useAttributePreference } from '../common/util/preferences';

const MapGeofence = () => {
Expand Down Expand Up @@ -52,6 +52,7 @@ const MapGeofence = () => {
type: 'symbol',
layout: {
'text-field': '{name}',
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
Expand Down
2 changes: 2 additions & 0 deletions src/map/MapMarkers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTheme } from '@mui/styles';
import { useMediaQuery } from '@mui/material';
import { map } from './core/MapView';
import { useAttributePreference } from '../common/util/preferences';
import { findFonts } from './core/mapUtil';

const MapMarkers = ({ markers, showTitles }) => {
const id = useId();
Expand Down Expand Up @@ -34,6 +35,7 @@ const MapMarkers = ({ markers, showTitles }) => {
'text-allow-overlap': true,
'text-anchor': 'bottom',
'text-offset': [0, -2 * iconScale],
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
Expand Down
3 changes: 3 additions & 0 deletions src/map/MapPositions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { formatTime, getStatusColor } from '../common/util/formatter';
import { mapIconKey } from './core/preloadImages';
import { useAttributePreference } from '../common/util/preferences';
import { useCatchCallback } from '../reactHelper';
import { findFonts } from './core/mapUtil';

const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleField }) => {
const id = useId();
Expand Down Expand Up @@ -111,6 +112,7 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF
'text-allow-overlap': true,
'text-anchor': 'bottom',
'text-offset': [0, -2 * iconScale],
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
Expand Down Expand Up @@ -149,6 +151,7 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF
'icon-image': 'background',
'icon-size': iconScale,
'text-field': '{point_count_abbreviated}',
'text-font': findFonts(map),
'text-size': 14,
},
});
Expand Down
2 changes: 2 additions & 0 deletions src/map/MapRouteCoordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useTheme } from '@mui/styles';
import { useId, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { map } from './core/MapView';
import { findFonts } from './core/mapUtil';

const MapRouteCoordinates = ({ name, coordinates, deviceId }) => {
const id = useId();
Expand Down Expand Up @@ -49,6 +50,7 @@ const MapRouteCoordinates = ({ name, coordinates, deviceId }) => {
type: 'symbol',
layout: {
'text-field': '{name}',
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
Expand Down
8 changes: 8 additions & 0 deletions src/map/core/mapUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,11 @@ export const geofenceToFeature = (theme, item) => {
};

export const geometryToArea = (geometry) => stringify(reverseCoordinates(geometry));

export const findFonts = (map) => {
const glyphs = map.getStyle().glyphs;

Check failure on line 90 in src/map/core/mapUtil.js

View workflow job for this annotation

GitHub Actions / build

Use object destructuring
if (glyphs.startsWith('https://tiles.openfreemap.org')) {
return ['Noto Sans Regular'];
}
return ['Open Sans Regular', 'Arial Unicode MS Regular'];
};
51 changes: 26 additions & 25 deletions src/map/draw/MapGeofenceEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'mapbox-gl/dist/mapbox-gl.css';
import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css';
import maplibregl from 'maplibre-gl';
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import { useEffect } from 'react';
import { useEffect, useMemo } from 'react';

import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import { useTheme } from '@mui/styles';
import { map } from '../core/MapView';
import { geofenceToFeature, geometryToArea } from '../core/mapUtil';
import { findFonts, geofenceToFeature, geometryToArea } from '../core/mapUtil';
import { errorsActions, geofencesActions } from '../../store';
import { useCatchCallback } from '../../reactHelper';
import theme from './theme';

Check failure on line 14 in src/map/draw/MapGeofenceEdit.js

View workflow job for this annotation

GitHub Actions / build

'theme' is defined but never used
Expand All @@ -18,35 +18,36 @@ MapboxDraw.constants.classes.CONTROL_BASE = 'maplibregl-ctrl';
MapboxDraw.constants.classes.CONTROL_PREFIX = 'maplibregl-ctrl-';
MapboxDraw.constants.classes.CONTROL_GROUP = 'maplibregl-ctrl-group';

const draw = new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
line_string: true,
trash: true,
},
userProperties: true,
styles: [...theme, {
id: 'gl-draw-title',
type: 'symbol',
filter: ['all'],
layout: {
'text-field': '{user_name}',
'text-size': 12,
},
paint: {
'text-halo-color': 'white',
'text-halo-width': 1,
},
}],
});

const MapGeofenceEdit = ({ selectedGeofenceId }) => {
const theme = useTheme();
const dispatch = useDispatch();
const navigate = useNavigate();
const t = useTranslation();

const draw = useMemo(() => new MapboxDraw({
displayControlsDefault: false,
controls: {
polygon: true,
line_string: true,
trash: true,
},
userProperties: true,
styles: [...theme, {
id: 'gl-draw-title',
type: 'symbol',
filter: ['all'],
layout: {
'text-field': '{user_name}',
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
'text-halo-color': 'white',
'text-halo-width': 1,
},
}],
}), []);

Check failure on line 50 in src/map/draw/MapGeofenceEdit.js

View workflow job for this annotation

GitHub Actions / build

Trailing spaces not allowed
const geofences = useSelector((state) => state.geofences.items);

const refreshGeofences = useCatchCallback(async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/map/main/PoiMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useTheme } from '@mui/styles';
import { map } from '../core/MapView';
import { useEffectAsync } from '../../reactHelper';
import { usePreference } from '../../common/util/preferences';
import { findFonts } from '../core/mapUtil';

const PoiMap = () => {
const id = useId();
Expand Down Expand Up @@ -54,6 +55,7 @@ const PoiMap = () => {
'text-field': '{name}',
'text-anchor': 'bottom',
'text-offset': [0, -0.5],
'text-font': findFonts(map),
'text-size': 12,
},
paint: {
Expand Down

0 comments on commit 4428348

Please sign in to comment.