1 import PropTypes from 'prop-types';
2 import React from 'react';
3 import { Link, useNavigate } from 'react-router-dom';
5 import { useOpenSeadragon } from './OpenSeadragon';
6 import Overlay from './Overlay';
7 import Popover from './Popover';
8 import Icon from '../common/Icon';
9 import ZeldaIcon from '../common/ZeldaIcon';
10 import { getLink, getTranslation } from '../../helpers/Technique';
11 import i18n from '../../i18n';
13 const Pin = ({ pin }) => {
14 const { storePosition } = useOpenSeadragon();
15 const [showPopover, setShowPopover] = React.useState(false);
16 const ref = React.useRef();
18 const navigate = useNavigate();
20 const onClick = React.useCallback((e) => {
21 if (ref.current && ref.current.contains(e.originalTarget)) {
22 if (e.originalTarget.tagName === 'A') {
24 navigate(new URL(e.originalTarget.href).pathname);
27 if (pin.technique.type === 'location') {
28 setShowPopover(s => !s);
31 navigate(getLink(pin.technique));
36 const title = React.useMemo(() => {
37 return getTranslation(pin.technique, 'title', i18n.language);
38 }, [pin, i18n.language]);
40 return <Overlay onClick={onClick} x={pin.x} y={pin.y}>
41 <div className="map-pin">
42 <Link to={getLink(pin.technique)}>
44 <ZeldaIcon title={title} name={pin.marker} />
46 <Icon.PIN title={title} />
49 {pin.technique.type === 'location' ?
51 <Popover show={showPopover} technique={pin.technique} />
59 pin: PropTypes.shape({
60 marker: PropTypes.string,
61 technique: PropTypes.shape({
62 type: PropTypes.string,