From 3d9009725e89ada1194bc760952be0773fae3c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=22Natsuyasumi=22=20Kuranowski?= Date: Fri, 9 Dec 2016 13:33:15 +0100 Subject: [PATCH 1/2] Address customization --- data/address-formats.json | 10 +++++++++- data/presets.yaml | 17 ++++++++++++++++- data/presets/fields.json | 21 ++++++++++++++++++++- data/presets/fields/address.json | 21 ++++++++++++++++++++- dist/locales/en.json | 17 ++++++++++++++++- modules/ui/fields/address.js | 26 ++++++++++++-------------- 6 files changed, 93 insertions(+), 19 deletions(-) diff --git a/data/address-formats.json b/data/address-formats.json index 973535963e..2e8d164e30 100644 --- a/data/address-formats.json +++ b/data/address-formats.json @@ -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"], @@ -38,6 +39,13 @@ { "countryCodes": ["tw"], "format": [["postcode", "city", "district"], ["place", "street"], ["housenumber", "floor"]] + }, + { + "countryCodes": ["jp"], + "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} } ] } diff --git a/data/presets.yaml b/data/presets.yaml index d536bc5528..ab8460d10a 100644 --- a/data/presets.yaml +++ b/data/presets.yaml @@ -78,24 +78,39 @@ en: # access=* label: Access address: - # 'addr:city=*, addr:conscriptionnumber=*, addr:country=*, addr:district=*, addr:floor=*, addr:hamlet=*, addr:housename=*, addr:housenumber=*, addr:place=*, addr:postcode=*, addr:province=*, addr:state=*, addr:street=*, addr:subdistrict=*, addr:suburb=*' + # 'addr:city=*, addr:block_number=*, addr:conscriptionnumber=*, addr:country=*, addr:county=*, 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!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/Machi state: State street: Street subdistrict: Subdistrict + subdistrict!vn: Ward/Commune/Townlet suburb: Suburb + suburb!jp: Ward admin_level: # admin_level=* label: Admin Level diff --git a/data/presets/fields.json b/data/presets/fields.json index d7b964d762..50a340c849 100644 --- a/data/presets/fields.json +++ b/data/presets/fields.json @@ -80,16 +80,20 @@ "type": "address", "keys": [ "addr:city", + "addr:block_number", "addr:conscriptionnumber", "addr:country", + "addr:county", "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", @@ -104,20 +108,35 @@ "strings": { "placeholders": { "city": "City", + "block_number": "Block Number", "conscriptionnumber": "123", "country": "Country", + "county": "County", "district": "District", "floor": "Floor", "hamlet": "Hamlet", "housename": "Housename", "housenumber": "123", + "neighbourhood": "Neighbourhood", "place": "Place", "postcode": "Postcode", "province": "Province", + "quarter": "Quarter", "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." } } }, diff --git a/data/presets/fields/address.json b/data/presets/fields/address.json index 9d223b7442..4f001c05dd 100644 --- a/data/presets/fields/address.json +++ b/data/presets/fields/address.json @@ -2,16 +2,20 @@ "type": "address", "keys": [ "addr:city", + "addr:block_number", "addr:conscriptionnumber", "addr:country", + "addr:county", "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", @@ -24,20 +28,35 @@ "strings": { "placeholders": { "city": "City", + "block_number": "Block Number", "conscriptionnumber": "123", "country": "Country", + "county": "County", "district": "District", "floor": "Floor", "hamlet": "Hamlet", "housename": "Housename", "housenumber": "123", + "neighbourhood": "Neighbourhood", "place": "Place", "postcode": "Postcode", "province": "Province", + "quarter": "Quarter", "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." } } } diff --git a/dist/locales/en.json b/dist/locales/en.json index 44949de8fa..e99dc0220b 100644 --- a/dist/locales/en.json +++ b/dist/locales/en.json @@ -704,20 +704,35 @@ "label": "Address", "placeholders": { "city": "City", + "block_number": "Block Number", "conscriptionnumber": "123", "country": "Country", + "county": "County", "district": "District", "floor": "Floor", "hamlet": "Hamlet", "housename": "Housename", "housenumber": "123", + "neighbourhood": "Neighbourhood", "place": "Place", "postcode": "Postcode", "province": "Province", + "quarter": "Quarter", "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": { diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 76f6fcd3d7..5fcb4aacb4 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -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(), @@ -98,7 +91,6 @@ export function uiFieldAddress(field, context) { } } - function getNearValues(key) { var extent = entity.extent(context.graph()), l = extent.center(), @@ -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) { @@ -154,16 +149,19 @@ 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 // setup dropdowns for common address tags - var addrTags = [ + if (typeof addressFormat.dropdowns != "undefined") { addrTags = addressFormat.dropdowns; } + else { addrTags = [ 'street', 'city', 'state', 'province', 'district', - 'subdistrict', 'suburb', 'place', 'postcode' - ]; + 'subdistrict', 'suburb', 'place', 'postcode']; } addrTags.forEach(function(tag) { var nearValues = (tag === 'street') ? getNearStreets From aafb77c7ecec8a59e5ca6e11e874dd5867fe9c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20=22Natsuyasumi=22=20Kuranowski?= Date: Fri, 9 Dec 2016 15:08:16 +0100 Subject: [PATCH 2/2] Small fixes --- modules/ui/fields/address.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index 5fcb4aacb4..b3a90c7e6a 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -122,7 +122,7 @@ export function uiFieldAddress(field, context) { return a && a.countryCodes && _.includes(a.countryCodes, countryCode); }) || _.first(dataAddressFormats); - if (typeof addressFormat.widths != 'undefined') { widths = addressFormat.widths; } + 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) { @@ -158,7 +158,7 @@ export function uiFieldAddress(field, context) { // Update // setup dropdowns for common address tags - if (typeof addressFormat.dropdowns != "undefined") { addrTags = addressFormat.dropdowns; } + if (typeof addressFormat.dropdowns !== 'undefined') { addrTags = addressFormat.dropdowns; } else { addrTags = [ 'street', 'city', 'state', 'province', 'district', 'subdistrict', 'suburb', 'place', 'postcode']; }