Skip to content

Commit 0146dfe

Browse files
tordansjake-low
authored andcommitted
Add Mapillary and Panoramax to "OpenIn" Dropdown
1 parent f87d058 commit 0146dfe

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/components/element_info.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ function ElementInfo({ changeset, action, token, setHighlight }) {
3333
actionPhrase = 'deleted';
3434
}
3535

36+
const getCoord = key => {
37+
return (
38+
action.new?.[key] || // point
39+
action.new?.nodes?.at(0)?.[key] || // added, modified line/area
40+
action.old?.nodes?.at(0)?.[key] || // deleted line/area
41+
action.new?.members?.at(0)?.[key] || // relation point, then line/area
42+
action.new?.members?.at(0)?.nodes?.at(0)?.[key] ||
43+
action.old?.members?.at(0)?.[key] ||
44+
action.old?.members?.at(0)?.nodes?.at(0)?.[key]
45+
);
46+
};
47+
3648
return (
3749
<div className="element-info">
3850
<h2>
@@ -42,7 +54,7 @@ function ElementInfo({ changeset, action, token, setHighlight }) {
4254
</h2>
4355
<menu>
4456
<HistoryDropdown id={id} />
45-
<OpenInDropdown id={id} />
57+
<OpenInDropdown id={id} lat={getCoord('lat')} lng={getCoord('lon')} />
4658
<FlagButton changeset={changeset} featureId={id} token={token} />
4759
</menu>
4860
<MetadataTable changesetId={changeset.get('id')} action={action} />
@@ -93,7 +105,7 @@ function idToMinimalForm(id) {
93105
return `${type[0]}${num}`;
94106
}
95107

96-
function OpenInDropdown({ id }) {
108+
function OpenInDropdown({ id, lat, lng }) {
97109
let options = [
98110
{
99111
label: 'OSM',
@@ -122,6 +134,26 @@ function OpenInDropdown({ id }) {
122134
}
123135
];
124136

137+
if (lat && lng) {
138+
options = [
139+
...options,
140+
{
141+
label: 'Mapillary',
142+
href: `https://www.mapillary.com/app/?lat=${lat}&lng=${lng}&z=16`
143+
},
144+
{
145+
label: 'Panoramax',
146+
href: `https://api.panoramax.xyz/?focus=map&map=16/${lat}/${lng}`
147+
}
148+
];
149+
} else {
150+
console.info(
151+
'OpenInDropdown: lat, lng missing; cannot add Mapillary link',
152+
lat,
153+
lng
154+
);
155+
}
156+
125157
return <Dropdown display="Open in" options={options} />;
126158
}
127159

0 commit comments

Comments
 (0)