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

Further address customization #3643

Merged
merged 4 commits into from
Jan 17, 2017
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
8 changes: 6 additions & 2 deletions data/address-formats.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
},
{
"countryCodes": ["vn"],
"format": [["housenumber", "street"], ["subdistrict"], ["district"], ["city"], ["province", "postcode"]]
"format": [["housenumber", "street"], ["subdistrict"], ["district"], ["city"], ["province", "postcode"]],
"customPlaceholders": ["subdistrict", "district", "city"]
},
{
"countryCodes": ["us"],
Expand All @@ -41,7 +42,10 @@
},
{
"countryCodes": ["jp"],
"format": [["postcode", "province", "county"], ["city", "suburb", "quarter"], ["neighbourhood", "block_number", "housenumber"]]
"format": [["postcode", "province", "county"], ["city", "suburb"], ["quarter", "neighbourhood"], ["block_number", "housenumber"]],
"customPlaceholders": ["province", "county", "city", "suburb", "quarter", "neighbourhood", "block_number", "housenumber"],
"dropdowns": ["postcode", "province", "county", "city", "suburb", "quarter", "neighbourhood", "block_number"],
"widths": {"postcode": 0.3, "province": 0.35, "county": 0.35, "city": 0.65, "suburb": 0.35, "quarter": 0.5, "neighbourhood": 0.5, "block_number": 0.5}
}
]
}
18 changes: 17 additions & 1 deletion data/presets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,25 +81,41 @@ en:
# 'addr:block_number=*, addr:city=*, addr:conscriptionnumber=*, addr:county=*, addr:country=*, addr:district=*, addr:floor=*, addr:hamlet=*, addr:housename=*, addr:housenumber=*, addr:neighbourhood=*, addr:place=*, addr:postcode=*, addr:province=*, addr:quarter=*, addr:state=*, addr:street=*, addr:subdistrict=*, addr:suburb=*'
label: Address
placeholders:
block_number: Block number
block_number: Block Number
block_number!jp: Block No.
city: City
city!jp: City/Town/Village/Tokyo Special Ward
city!vn: City/Town
conscriptionnumber: '123'
country: Country
county: County
county!jp: District
district: District
district!vn: Arrondissement/Town/District
floor: Floor
hamlet: Hamlet
housename: Housename
housenumber: '123'
housenumber!jp: Building No./Lot No.
neighbourhood: Neighbourhood
neighbourhood!jp: Chōme/Aza/Koaza
place: Place
postcode: Postcode
province: Province
province!jp: Prefecture
quarter: Quarter
quarter!jp: Ōaza/Mach
neighbourhood: Neighbourhood
place: Place
postcode: Postcode
province: Province
quarter: Quarte
state: State
street: Street
subdistrict: Subdistrict
subdistrict!vn: Ward/Commune/Townlet
suburb: Suburb
suburb!jp: Ward
admin_level:
# admin_level=*
label: Admin Level
Expand Down
17 changes: 16 additions & 1 deletion data/presets/fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@
"keys": [
"addr:block_number",
"addr:city",
"addr:block_number",
"addr:conscriptionnumber",
"addr:county",
"addr:country",
"addr:county",
"addr:district",
"addr:floor",
"addr:hamlet",
Expand All @@ -109,9 +111,11 @@
"placeholders": {
"block_number": "Block number",
"city": "City",
"block_number": "Block Number",
"conscriptionnumber": "123",
"county": "County",
"country": "Country",
"county": "County",
"district": "District",
"floor": "Floor",
"hamlet": "Hamlet",
Expand All @@ -125,7 +129,18 @@
"state": "State",
"street": "Street",
"subdistrict": "Subdistrict",
"suburb": "Suburb"
"suburb": "Suburb",
"subdistrict!vn": "Ward/Commune/Townlet",
"district!vn": "Arrondissement/Town/District",
"city!vn": "City/Town",
"province!jp": "Prefecture",
"county!jp": "District",
"city!jp": "City/Town/Village/Tokyo Special Ward",
"suburb!jp": "Ward",
"quarter!jp": "Ōaza/Machi",
"neighbourhood!jp": "Chōme/Aza/Koaza",
"block_number!jp": "Block No.",
"housenumber!jp": "Building No./Lot No."
}
}
},
Expand Down
17 changes: 16 additions & 1 deletion data/presets/fields/address.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"keys": [
"addr:block_number",
"addr:city",
"addr:block_number",
"addr:conscriptionnumber",
"addr:county",
"addr:country",
"addr:county",
"addr:district",
"addr:floor",
"addr:hamlet",
Expand All @@ -29,9 +31,11 @@
"placeholders": {
"block_number": "Block number",
"city": "City",
"block_number": "Block Number",
"conscriptionnumber": "123",
"county": "County",
"country": "Country",
"county": "County",
"district": "District",
"floor": "Floor",
"hamlet": "Hamlet",
Expand All @@ -45,7 +49,18 @@
"state": "State",
"street": "Street",
"subdistrict": "Subdistrict",
"suburb": "Suburb"
"suburb": "Suburb",
"subdistrict!vn": "Ward/Commune/Townlet",
"district!vn": "Arrondissement/Town/District",
"city!vn": "City/Town",
"province!jp": "Prefecture",
"county!jp": "District",
"city!jp": "City/Town/Village/Tokyo Special Ward",
"suburb!jp": "Ward",
"quarter!jp": "Ōaza/Machi",
"neighbourhood!jp": "Chōme/Aza/Koaza",
"block_number!jp": "Block No.",
"housenumber!jp": "Building No./Lot No."
}
}
}
15 changes: 14 additions & 1 deletion dist/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -782,9 +782,11 @@
"placeholders": {
"block_number": "Block number",
"city": "City",
"block_number": "Block Number",
"conscriptionnumber": "123",
"county": "County",
"country": "Country",
"county": "County",
"district": "District",
"floor": "Floor",
"hamlet": "Hamlet",
Expand All @@ -798,7 +800,18 @@
"state": "State",
"street": "Street",
"subdistrict": "Subdistrict",
"suburb": "Suburb"
"suburb": "Suburb",
"subdistrict!vn": "Ward/Commune/Townlet",
"district!vn": "Arrondissement/Town/District",
"city!vn": "City/Town",
"province!jp": "Prefecture",
"county!jp": "District",
"city!jp": "City/Town/Village/Tokyo Special Ward",
"suburb!jp": "Ward",
"quarter!jp": "Ōaza/Machi",
"neighbourhood!jp": "Chōme/Aza/Koaza",
"block_number!jp": "Block No.",
"housenumber!jp": "Building No./Lot No."
}
},
"admin_level": {
Expand Down
26 changes: 13 additions & 13 deletions modules/ui/fields/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,10 @@ export function uiFieldAddress(field, context) {
nominatim = services.nominatim,
wrap = d3.select(null),
isInitialized = false,
widths,
addrTags,
entity;

var widths = {
housenumber: 1/3,
street: 2/3,
city: 2/3,
state: 1/4,
postcode: 1/3
};


function getNearStreets() {
var extent = entity.extent(context.graph()),
l = extent.center(),
Expand Down Expand Up @@ -98,7 +91,6 @@ export function uiFieldAddress(field, context) {
}
}


function getNearValues(key) {
var extent = entity.extent(context.graph()),
l = extent.center(),
Expand Down Expand Up @@ -130,6 +122,9 @@ export function uiFieldAddress(field, context) {
return a && a.countryCodes && _.includes(a.countryCodes, countryCode);
}) || _.first(dataAddressFormats);

if (typeof addressFormat.widths !== 'undefined') { widths = addressFormat.widths; }
else { widths = {housenumber: 1/3, street: 2/3, city: 2/3, state: 1/4, postcode: 1/3}; }

function row(r) {
// Normalize widths.
var total = _.reduce(r, function(sum, field) {
Expand All @@ -154,16 +149,21 @@ export function uiFieldAddress(field, context) {
.enter()
.append('input')
.property('type', 'text')
.attr('placeholder', function (d) { return field.t('placeholders.' + d.id); })
.attr('placeholder', function (d) {
var countryInserter = '';
if (addressFormat.customPlaceholders.indexOf(d.id) !== -1) { countryInserter = '!' + countryCode; }
return field.t('placeholders.' + d.id + countryInserter); })
.attr('class', function (d) { return 'addr-' + d.id; })
.style('width', function (d) { return d.width * 100 + '%'; });

// Update
var addrTags = [
// setup dropdowns for common address tags
if (typeof addressFormat.dropdowns !== 'undefined') { addrTags = addressFormat.dropdowns; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @natsuyasumi I'd like to get this code merged this week, so I'm taking a look through it now..

Is the reason for addressFormat.dropdowns so that you can turn block_number ("Building No.") and housenumber ("Lot No.") into dropdown fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created the addressFormat.dropdowns for simplicty, so that you don't have to add this fields-that-should-have-dropdowns in address,js. The housenumber field doesn't have dropdown.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natsuyasumi Ok, makes sense, thanks!

else { addrTags = [
'city', 'county', 'country', 'district', 'hamlet',
'neighbourhood', 'place', 'postcode', 'province',
'quarter', 'state', 'street', 'subdistrict', 'suburb'
];
]; }

// If fields exist for any of these tags, create dropdowns to pick nearby values..
addrTags.forEach(function(tag) {
Expand Down