-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
iD Tagging scheme exploration #131
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
f726704
iD Tagging scheme exploration
zbycz ac4a5e4
fix build
zbycz 4303f91
fix build2
zbycz c256952
show only unique fields
zbycz d2879df
add typescript types
zbycz 6d6c93e
y lintfix
zbycz 904a6f8
find Field for rest of tags
zbycz 8753c1f
move schema to Feature + add UI
zbycz 9dde0c5
translate values in semiCombo
zbycz c23dd38
titles
zbycz 657714f
hack address:* in
zbycz d022a75
remove tags which are already covered by Preset name
zbycz 8d8421d
experiment - clear sessionstorage
zbycz fd84d97
typeCombo is usually cleared by preset.tags
zbycz 5a6837b
We need typeCombo after all, eg node/7002486683
zbycz e4a4d18
move units from label to value
zbycz fc584ef
finalize first prototype
zbycz 093f867
allow language switching
zbycz 4ff8899
fix buildAddress a little
zbycz f5aefe4
Merge remote-tracking branch 'origin/master' into tagging
zbycz c826aeb
extract PoiDescription.tsx
zbycz 4c08c4d
extract field helpers to fields.ts
zbycz 112bb41
refactoring restKeys->keysTodo, added publishDbgObject(), added test
zbycz afc696c
fix access key - covers multiple tags
zbycz d962b8a
Use `@openstreetmap/id-tagging-schema` pkg
zbycz 7c05661
fix keysTodo (never commit 30k ft above ground)
zbycz d67ca25
Merge branch 'master' into tagging
zbycz 6e55aa8
y lintfix
zbycz a99ecc7
fix [object object] in `subject:wikidata`
zbycz 9fb9c1f
update osmApi.test.ts
zbycz e601d7f
hide under advanced mode
zbycz fe28dd7
add Details above TagsTable
zbycz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import React, { ReactNode } from 'react'; | ||
import styled from 'styled-components'; | ||
import Typography from '@material-ui/core/Typography'; | ||
import { Field } from '../../services/tagging/types/Fields'; | ||
import { getUrlForTag } from './helpers/getUrlForTag'; | ||
import { slashToOptionalBr } from '../helpers'; | ||
import { buildAddress } from '../../services/helpers'; | ||
import { Feature } from '../../services/types'; | ||
import { t } from '../../services/intl'; | ||
|
||
// taken from src/components/FeaturePanel/TagsTable.tsx | ||
const Table = styled.table` | ||
font-size: 1rem; | ||
width: 100%; | ||
|
||
th, | ||
td { | ||
padding: 0.1em; | ||
overflow: hidden; | ||
|
||
&:hover .show-on-hover { | ||
display: block !important; | ||
} | ||
} | ||
|
||
th { | ||
width: 140px; | ||
max-width: 140px; | ||
color: rgba(0, 0, 0, 0.54); | ||
text-align: left; | ||
font-weight: normal; | ||
vertical-align: baseline; | ||
padding-left: 0; | ||
} | ||
|
||
table { | ||
padding-left: 1em; | ||
padding-bottom: 1em; | ||
} | ||
`; | ||
|
||
// TODO move to helpers | ||
const getEllipsisHumanUrl = (humanUrl) => { | ||
const MAX_LENGTH = 40; | ||
return humanUrl.replace(/^([^/]+.{0,5})(.*)$/, (full, hostname, rest) => { | ||
const charsLeft = MAX_LENGTH - 10 - hostname.length; | ||
return ( | ||
hostname + | ||
(full.length > MAX_LENGTH | ||
? `…${rest.substring(rest.length - charsLeft)}` | ||
: rest) | ||
); | ||
}); | ||
}; | ||
|
||
// taken from src/components/FeaturePanel/TagsTable.tsx | ||
const renderValue = (k, v): string | ReactNode => { | ||
const url = getUrlForTag(k, v); | ||
if (url) { | ||
let humanUrl = v.replace(/^https?:\/\//, '').replace(/^([^/]+)\/$/, '$1'); | ||
if (k === 'image') { | ||
humanUrl = getEllipsisHumanUrl(humanUrl); | ||
} | ||
return <a href={url}>{slashToOptionalBr(humanUrl)}</a>; | ||
} | ||
return v; | ||
}; | ||
|
||
const render = (field: Field, feature: Feature, k, v): string | ReactNode => { | ||
if (field.type === 'address') { | ||
return buildAddress(feature.tags, feature.center); | ||
} | ||
return renderValue(k, v); | ||
}; | ||
|
||
const getTitle = (type: string, field: Field) => | ||
`${type}: ${JSON.stringify(field, null, 2)}`; | ||
|
||
// TODO some fields eg. oneway/bicycle doesnt have units in brackets | ||
const unitRegExp = / \((.+)\)$/i; | ||
const removeUnits = (label) => label.replace(unitRegExp, ''); | ||
const addUnits = (label, value: string | ReactNode) => { | ||
if (typeof value !== 'string') return value; | ||
const unit = label.match(unitRegExp); | ||
return `${value}${unit ? ` (${unit[1]})` : ''}`; | ||
}; | ||
|
||
export const IdSchemeFields = ({ feature, featuredTags }) => { | ||
const { schema } = feature; | ||
if (!schema) return null; | ||
if (!Object.keys(schema).length) return null; | ||
|
||
return ( | ||
<> | ||
{featuredTags.length && | ||
(schema.matchedFields.length || | ||
schema.tagsWithFields.length || | ||
schema.restKeys.length) ? ( | ||
<Typography variant="overline" display="block" color="textSecondary"> | ||
{t('featurepanel.other_info_heading')} | ||
</Typography> | ||
) : null} | ||
|
||
<Table> | ||
<tbody> | ||
{schema.matchedFields.map(({ key, value, label, field }) => ( | ||
<tr key={key}> | ||
<th title={getTitle('from preset', field)}> | ||
{removeUnits(label)} | ||
</th> | ||
<td>{addUnits(label, render(field, feature, key, value))}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
<tbody> | ||
{schema.tagsWithFields.map(({ key, value, label, field }) => ( | ||
<tr key={key}> | ||
<th title={getTitle('standalone field', field)}> | ||
{removeUnits(label)} | ||
</th> | ||
<td>{render(field, feature, key, addUnits(label, value))}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
<tbody> | ||
{schema.keysTodo.map((key) => ( | ||
<tr key={key}> | ||
<th>{key}</th> | ||
<td>{renderValue(key, feature.tags[key])}</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/components/FeaturePanel/ImageSection/PoiDescription.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { hasName } from '../../../helpers/featureLabel'; | ||
import { useFeatureContext } from '../../utils/FeatureContext'; | ||
import { t } from '../../../services/intl'; | ||
import Maki from '../../utils/Maki'; | ||
import { Feature } from '../../../services/types'; | ||
|
||
const PoiType = styled.div` | ||
color: #fff; | ||
margin: 0 auto 0 15px; | ||
font-size: 13px; | ||
position: relative; | ||
width: 100%; | ||
|
||
svg { | ||
vertical-align: bottom; | ||
} | ||
|
||
span { | ||
position: absolute; | ||
left: 20px; | ||
} | ||
`; | ||
|
||
const getSubclass = ({ layer, osmMeta, properties, schema }: Feature) => | ||
schema?.label || | ||
properties.subclass?.replace(/_/g, ' ') || | ||
(layer && layer.id) || // layer.id specified only when maplibre-gl skeleton displayed | ||
osmMeta.type; | ||
|
||
export const PoiDescription = () => { | ||
const { feature } = useFeatureContext(); | ||
const { properties } = feature; | ||
|
||
const poiType = hasName(feature) | ||
? getSubclass(feature) | ||
: t('featurepanel.no_name'); | ||
|
||
return ( | ||
<PoiType> | ||
<Maki ico={properties.class} invert middle /> | ||
<span>{poiType}</span> | ||
</PoiType> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✅