aboutsummaryrefslogtreecommitdiff
path: root/lib/valueLimits.js
blob: 797d16dac59cbb2e004ef8dbedae35f83eb05996 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * In OSM tag values are limited to 255 characters.
 * Search for addr:flats beyond that limit and wrap into addr:flats2 addr:flats3 etc.
 * 
 * @param {Object} feature 
 * @returns {boolean}
 */
module.exports = (feature) => {
  if ('addr:flats' in feature.properties && feature.properties['addr:flats'] !== null && feature.properties['addr:flats'].length > 255) {
  // TODO need to work out why nulls are appearing when using
  //if ('addr:flats' in feature.properties && feature.properties['addr:flats'].length > 255) {
    // need to wrap
    const value = feature.properties['addr:flats']
    for (let i = 0; i < value.length; i += 255) {
      feature.properties[`addr:flats${i === 0 ? '' : i / 255 + 1}`] = value.slice(i, i + 255)
    }
  }
  return feature
}