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

FeaturePanel: Add apple maps to the dropdown #697

Merged
merged 3 commits into from
Oct 18, 2024
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
22 changes: 19 additions & 3 deletions src/components/FeaturePanel/Coordinates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { useMapStateContext } from '../utils/MapStateContext';
import { isMobileDevice, useBoolState } from '../helpers';
import { useFeatureContext } from '../utils/FeatureContext';
import { getIdEditorLink, positionToDeg, positionToDM } from '../../utils';
import { positionToDeg, positionToDM } from '../../utils';
import { PositionBoth } from '../../services/types';
import { getFullOsmappLink, getShortLink } from '../../services/helpers';
import { t } from '../../services/intl';
import { isIOS } from '../../helpers/platforms';
import { getAppleMapsLink, getIdEditorLink } from './helpers/externalLinks';

const StyledMenuItem = styled(MenuItem)`
svg {
Expand Down Expand Up @@ -64,10 +66,16 @@ const LinkItem = ({ href, label }) => (
// https://wiki.openstreetmap.org/wiki/Zoom_levels#Mapbox_GL
const MAPLIBREGL_ZOOM_DIFFERENCE = 1;

const useGetItems = ([lon, lat]: PositionBoth) => {
type ExternalMapLink = {
label: string;
href: string;
};

const useGetItems = (position: PositionBoth): ExternalMapLink[] => {
const { feature } = useFeatureContext();
const { view } = useMapStateContext();
const { view, activeLayers } = useMapStateContext();
const [ourZoom] = view;
const [lon, lat] = position;

const zoom = parseFloat(ourZoom) + MAPLIBREGL_ZOOM_DIFFERENCE;
const zoomInt = Math.round(zoom);
Expand Down Expand Up @@ -96,6 +104,14 @@ const useGetItems = ([lon, lat]: PositionBoth) => {
label: 'iD editor',
href: getIdEditorLink(feature, view), // TODO coordsFeature has random id which gets forwarded LOL
},
...(isIOS()
? [
{
label: 'Apple maps',
href: getAppleMapsLink(feature, position, activeLayers),
},
]
: []),
...(isMobileDevice()
? [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DialogHeading } from '../components';
import { t, Translation } from '../../../../services/intl';
import { useOsmAuthContext } from '../../../utils/OsmAuthContext';
import { useToggleState } from '../../../helpers';
import { getIdEditorLink } from '../../../../utils';
import { getIdEditorLink } from '../../helpers/externalLinks';

export const PlaceCancelledToggle = () => {
const {
Expand Down
27 changes: 27 additions & 0 deletions src/components/FeaturePanel/helpers/externalLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { getLabel } from '../../../helpers/featureLabel';
import { Feature, PositionBoth } from '../../../services/types';
import { View } from '../../utils/MapStateContext';

export const getIdEditorLink = (feature: Feature, view?: View) => {
const query = feature?.osmMeta?.id
? `?${feature.osmMeta.type}=${feature.osmMeta.id}`
: '';
const hash = view ? `#map=${view.join('/')}` : '';
return `https://www.openstreetmap.org/edit${query}${hash}`;
};

export const getAppleMapsLink = (
feature: Feature,
position: PositionBoth,
activeLayers: string[],
) => {
// TODO: satelite detection on userLayers
const layer = activeLayers.some((layer) =>
['sat', 'bingSat', 'cuzkSat'].includes(layer),
)
? 'h' // satelite
: 'm'; // normal

const markerLabel = getLabel(feature);
return `https://maps.apple.com/?ll=${position[1]},${position[0]}&t=${layer}&q=${markerLabel}`;
};
2 changes: 1 addition & 1 deletion src/components/Map/TopMenu/HamburgerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useBoolState } from '../../helpers';
import { t } from '../../../services/intl';
import { useFeatureContext } from '../../utils/FeatureContext';
import { useMapStateContext } from '../../utils/MapStateContext';
import { getIdEditorLink } from '../../../utils';
import { getIdEditorLink } from '../../FeaturePanel/helpers/externalLinks';
import { UserTheme, useUserThemeContext } from '../../../helpers/theme';
import GithubIcon from '../../../assets/GithubIcon';
import { LangSwitcher } from './LangSwitcher';
Expand Down
11 changes: 7 additions & 4 deletions src/helpers/platforms.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { isBrowser } from '../components/helpers';

export const isIOS = () =>
[
isBrowser() &&
([
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod',
].includes(navigator.platform) ||
// iPad on iOS 13 detection
(navigator.userAgent.includes('Mac') && 'ontouchend' in document);
// iPad on iOS 13 detection
(navigator.userAgent.includes('Mac') && 'ontouchend' in document));

export const isAndroid = () =>
navigator.userAgent.toLowerCase().indexOf('android') > -1;
isBrowser() && navigator.userAgent.toLowerCase().indexOf('android') > -1;

export const getPlatform = () => {
if (isIOS()) return 'ios';
Expand Down
11 changes: 1 addition & 10 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Position,
PositionBoth,
} from './services/types';
import type { View } from './components/utils/MapStateContext';

// Accuracy = 1m, see https://gis.stackexchange.com/questions/8650/measuring-accuracy-of-latitude-and-longitude
export const roundDeg = (deg) => (deg.toFixed ? deg.toFixed(5) : deg);
Expand Down Expand Up @@ -38,15 +37,7 @@ export const getRoundedPosition = (
export const roundedToDegUrl = ([lon, lat]: LonLatRounded) => `${lat},${lon}`;
export const roundedToDeg = ([lon, lat]: LonLatRounded) => `${lat}° ${lon}°`;

export const getIdEditorLink = (feature: Feature, view?: View) => {
const query = feature?.osmMeta?.id
? `?${feature.osmMeta.type}=${feature.osmMeta.id}`
: '';
const hash = view ? `#map=${view.join('/')}` : '';
return `https://www.openstreetmap.org/edit${query}${hash}`;
};

export const getUtfStrikethrough = (text) =>
export const getUtfStrikethrough = (text: string) =>
text
.split('')
.map((char) => `${char}\u0336`)
Expand Down
Loading