How to use the @ideditor/country-coder.iso1A2Code function in @ideditor/country-coder

To help you get started, weโ€™ve selected a few @ideditor/country-coder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openstreetmap / iD / modules / ui / fields / address.js View on Github external
wrap = selection.selectAll('.form-field-input-wrap')
            .data([0]);

        wrap = wrap.enter()
            .append('div')
            .attr('class', 'form-field-input-wrap form-field-input-' + field.type)
            .merge(wrap);

        if (_entity) {
            var countryCode;
            if (context.inIntro()) {
                // localize the address format for the walkthrough
                countryCode = t('intro.graph.countrycode');
            } else {
                var center = _entity.extent(context.graph()).center();
                countryCode = countryCoder.iso1A2Code(center);
            }
            if (countryCode) updateForCountryCode(countryCode);
        }
    }
github openstreetmap / iD / modules / validations / outdated_tags.js View on Github external
newTags['brand:wikipedia'] = newTags.wikipedia;
                delete newTags.wikipedia;
            }
            // I considered setting `name` and other tags here, but they aren't unique per wikidata
            // (Q2759586 -> in USA "Papa John's", in Russia "ะŸะฐะฟะฐ ะ”ะถะพะฝั")
            // So users will really need to use a preset or assign `name` themselves.
        }

        // try key/value|name match against name-suggestion-index
        if (newTags.name) {
            for (var i = 0; i < nsiKeys.length; i++) {
                var k = nsiKeys[i];
                if (!newTags[k]) continue;

                var center = entity.extent(graph).center();
                var countryCode = countryCoder.iso1A2Code(center);
                var match = nsiMatcher.matchKVN(k, newTags[k], newTags.name, countryCode && countryCode.toLowerCase());
                if (!match) continue;

                // for now skip ambiguous matches (like Target~(USA) vs Target~(Australia))
                if (match.d) continue;

                var brand = brands.brands[match.kvnd];
                if (brand && brand.tags['brand:wikidata'] &&
                    brand.tags['brand:wikidata'] !== entity.tags['not:brand:wikidata']) {
                    subtype = 'noncanonical_brand';

                    var keepTags = ['takeaway'].reduce(function(acc, k) {
                        if (newTags[k]) {
                            acc[k] = newTags[k];
                        }
                        return acc;
github openstreetmap / iD / modules / ui / fields / combo.js View on Github external
} else {
            input = container.selectAll('input')
                .data([0]);
        }

        input = input.enter()
            .append('input')
            .attr('type', 'text')
            .attr('id', 'preset-input-' + field.safeid)
            .call(utilNoAuto)
            .call(initCombo, selection)
            .merge(input);

        if (isNetwork && _entity) {
            var center = _entity.extent(context.graph()).center();
            var countryCode = countryCoder.iso1A2Code(center);
            _countryCode = countryCode && countryCode.toLowerCase();
        }

        input
            .on('change', change)
            .on('blur', change);

        input
            .on('keydown.field', function() {
                switch (d3_event.keyCode) {
                    case 13: // โ†ฉ Return
                        input.node().blur(); // blurring also enters the value
                        d3_event.stopPropagation();
                        break;
                }
            });
github openstreetmap / iD / modules / ui / fields / localized.js View on Github external
function loadCountryCode() {
        var center = _entity.extent(context.graph()).center();
        var countryCode = countryCoder.iso1A2Code(center);
        _countryCode = countryCode && countryCode.toLowerCase();
    }
github openstreetmap / iD / modules / ui / fields / input.js View on Github external
.attr('placeholder', field.placeholder() || t('inspector.unknown'))
            .classed(field.type, true)
            .call(utilNoAuto)
            .merge(input);

        input
            .classed('disabled', !!isLocked)
            .attr('readonly', isLocked || null)
            .on('input', change(true))
            .on('blur', change())
            .on('change', change());


        if (field.type === 'tel' && _entity) {
            var center = _entity.extent(context.graph()).center();
            var countryCode = countryCoder.iso1A2Code(center);
            var format = countryCode && dataPhoneFormats[countryCode.toLowerCase()];
            if (format) {
                wrap.selectAll('#' + fieldID)
                    .attr('placeholder', format);
            }

        } else if (field.type === 'number') {
            var rtl = (textDirection === 'rtl');

            input.attr('type', 'text');

            var buttons = wrap.selectAll('.increment, .decrement')
                .data(rtl ? [1, -1] : [-1, 1]);

            buttons.enter()
                .append('button')
github openstreetmap / iD / modules / ui / preset_list.js View on Github external
function inputevent() {
            var value = search.property('value');
            list.classed('filtered', value.length);
            var entity = context.entity(_entityID);
            var results, messageText;
            if (value.length && entity) {
                var center = entity.extent(context.graph()).center();
                var countryCode = countryCoder.iso1A2Code(center);

                results = presets.search(value, geometry, countryCode && countryCode.toLowerCase());
                messageText = t('inspector.results', {
                    n: results.collection.length,
                    search: value
                });
            } else {
                results = context.presets().defaults(geometry, 36);
                messageText = t('inspector.choose');
            }
            list.call(drawList, results);
            message.text(messageText);
        }

@ideditor/country-coder

Convert longitude-latitude pairs to ISO 3166-1 codes quickly and locally

ISC
Latest version published 2 years ago

Package Health Score

45 / 100
Full package analysis