diff --git a/.eslintrc b/.eslintrc index d84a3043d..16335b2c8 100644 --- a/.eslintrc +++ b/.eslintrc @@ -50,7 +50,7 @@ "no-shadow": "off", "no-shadow-restricted-names": "error", "no-throw-literal": "error", - "no-undef": "warn", // To catch uses of iD global - TODO remove + "no-undef": "error", "no-unneeded-ternary": "error", "no-unused-expressions": "error", "no-unexpected-multiline": "error", diff --git a/build.js b/build.js index e9c17a693..0f8920824 100644 --- a/build.js +++ b/build.js @@ -96,8 +96,8 @@ function suggestionsToPresets(presets) { delete existing[name]; } if (!existing[name]) { - tags = _.extend({name: name}, suggestions[key][value][name].tags); - addSuggestion(item, tags, name, count); + tags = _.extend({name: name.replace(/"/g, '')}, suggestions[key][value][name].tags); + addSuggestion(item, tags, name.replace(/"/g, ''), count); } } } @@ -112,7 +112,7 @@ function suggestionsToPresets(presets) { return; } - presets[category] = { + presets[category.replace(/"/g, '')] = { tags: parent.tags ? _.merge(tags, parent.tags) : tags, name: name, icon: parent.icon, diff --git a/data/presets/presets.json b/data/presets/presets.json index 876aa0c34..5a1963b53 100644 --- a/data/presets/presets.json +++ b/data/presets/presets.json @@ -66267,4 +66267,4 @@ ], "suggestion": true } -} +} \ No newline at end of file diff --git a/modules/actions/deprecate_tags.js b/modules/actions/deprecate_tags.js index f35003201..f05ffc80c 100644 --- a/modules/actions/deprecate_tags.js +++ b/modules/actions/deprecate_tags.js @@ -1,4 +1,6 @@ import _ from 'lodash'; +import { deprecated } from '../../data/index'; + export function DeprecateTags(entityId) { return function(graph) { var entity = graph.entity(entityId), @@ -7,9 +9,9 @@ export function DeprecateTags(entityId) { rule; // This handles deprecated tags with a single condition - for (var i = 0; i < iD.data.deprecated.length; i++) { + for (var i = 0; i < deprecated.length; i++) { - rule = iD.data.deprecated[i]; + rule = deprecated[i]; var match = _.toPairs(rule.old)[0], replacements = rule.replace ? _.toPairs(rule.replace) : null; diff --git a/modules/actions/discard_tags.js b/modules/actions/discard_tags.js index 4efb113a0..76b6e93eb 100644 --- a/modules/actions/discard_tags.js +++ b/modules/actions/discard_tags.js @@ -1,4 +1,6 @@ import _ from 'lodash'; +import { discarded } from '../../data/index'; + export function DiscardTags(difference) { return function(graph) { function discardTags(entity) { @@ -9,7 +11,7 @@ export function DiscardTags(difference) { }); graph = graph.replace(entity.update({ - tags: _.omit(tags, iD.data.discarded) + tags: _.omit(tags, discarded) })); } } diff --git a/modules/actions/merge_remote_changes.js b/modules/actions/merge_remote_changes.js index 211db8143..aa725417c 100644 --- a/modules/actions/merge_remote_changes.js +++ b/modules/actions/merge_remote_changes.js @@ -3,6 +3,7 @@ import _ from 'lodash'; import { DeleteMultiple } from './delete_multiple'; import { Entity } from '../core/index'; import { diff3_merge } from '../util/diff3'; +import { discarded } from '../../data/index'; export function MergeRemoteChanges(id, localGraph, remoteGraph, formatUser) { var option = 'safe', // 'safe', 'force_local', 'force_remote' @@ -149,7 +150,7 @@ export function MergeRemoteChanges(id, localGraph, remoteGraph, formatUser) { function mergeTags(base, remote, target) { function ignoreKey(k) { - return _.includes(iD.data.discarded, k); + return _.includes(discarded, k); } if (option === 'force_local' || _.isEqual(target.tags, remote.tags)) { diff --git a/modules/core/context.js b/modules/core/context.js index 8ff3b761b..d8ede141b 100644 --- a/modules/core/context.js +++ b/modules/core/context.js @@ -6,9 +6,12 @@ import { Detect } from '../util/detect'; import { Features } from '../renderer/features'; import { History } from './history'; import { Map } from '../renderer/map'; +import { Select } from '../modes/select'; import { RawMercator } from '../geo/raw_mercator'; import { presets as presetsInit } from '../presets/presets'; import { init as uiInit } from '../ui/init'; +import { locales, en } from '../../data/index'; +import * as services from '../services/index'; export var areaKeys = {}; @@ -18,7 +21,7 @@ export function Context(root) { current: function(_) { this._current = _; } }; } - addTranslation('en', iD.data.en); + addTranslation('en', en); setLocale('en'); var dispatch = d3.dispatch('enter', 'exit', 'change'), @@ -97,7 +100,7 @@ export function Context(root) { if (!context.hasEntity(id)) return; map.on('drawn.zoomToEntity', null); context.on('enter.zoomToEntity', null); - context.enter(iD.modes.Select(context, [id])); + context.enter(Select(context, [id])); }); context.on('enter.zoomToEntity', function() { @@ -136,7 +139,7 @@ export function Context(root) { connection.flush(); features.reset(); history.reset(); - _.each(iD.services, function(service) { + _.each(services, function(service) { var reset = service().reset; if (reset) reset(context); }); @@ -330,7 +333,7 @@ export function Context(root) { }; context.loadLocale = function(cb) { - if (locale && locale !== 'en' && iD.data.locales.indexOf(locale) !== -1) { + if (locale && locale !== 'en' && locales.indexOf(locale) !== -1) { localePath = localePath || context.asset('locales/' + locale + '.json'); d3.json(localePath, function(err, result) { addTranslation(locale, result); @@ -349,7 +352,7 @@ export function Context(root) { context.projection = RawMercator(); locale = Detect().locale; - if (locale && iD.data.locales.indexOf(locale) === -1) { + if (locale && locales.indexOf(locale) === -1) { locale = locale.split('-')[0]; } diff --git a/modules/core/entity.js b/modules/core/entity.js index 9a51f2696..5fc2253d4 100644 --- a/modules/core/entity.js +++ b/modules/core/entity.js @@ -1,5 +1,7 @@ import _ from 'lodash'; +import { debug } from '../index'; import { interestingTag } from './tags'; +import { deprecated as deprecatedData } from '../../data/index'; export function Entity(attrs) { // For prototypal inheritance. @@ -63,7 +65,7 @@ Entity.prototype = { this.visible = true; } - if (iD.debug) { + if (debug) { Object.freeze(this); Object.freeze(this.tags); @@ -134,7 +136,7 @@ Entity.prototype = { var tags = _.toPairs(this.tags); var deprecated = {}; - iD.data.deprecated.forEach(function(d) { + deprecatedData.forEach(function(d) { var match = _.toPairs(d.old)[0]; tags.forEach(function(t) { if (t[0] === match[0] && diff --git a/modules/core/graph.js b/modules/core/graph.js index 01642a40e..2b7bb9224 100644 --- a/modules/core/graph.js +++ b/modules/core/graph.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import { getPrototypeOf } from '../util/index'; +import { debug } from '../index'; export function Graph(other, mutable) { if (!(this instanceof Graph)) return new Graph(other, mutable); @@ -92,7 +93,7 @@ Graph.prototype = { nodes[i] = this.entity(entity.nodes[i]); } - if (iD.debug) Object.freeze(nodes); + if (debug) Object.freeze(nodes); this._childNodes[entity.id] = nodes; return this._childNodes[entity.id]; diff --git a/modules/index.js b/modules/index.js index 4672ed4ab..046e40d95 100644 --- a/modules/index.js +++ b/modules/index.js @@ -35,6 +35,8 @@ export { TileLayer } from './renderer/tile_layer'; import * as data from '../data/index.js'; +export var debug = false; + export { data, actions, diff --git a/modules/services/taginfo.js b/modules/services/taginfo.js index 2cb12fbfc..d5653ea13 100644 --- a/modules/services/taginfo.js +++ b/modules/services/taginfo.js @@ -21,7 +21,7 @@ var taginfo = {}, vertex: 'nodes', area: 'ways', line: 'ways' - }; + }, tag_members_fractions = { point: 'count_node_members_fraction', vertex: 'count_node_members_fraction', @@ -30,7 +30,6 @@ var taginfo = {}, relation: 'count_relation_members_fraction' }; - function sets(parameters, n, o) { if (parameters.geometry && o[parameters.geometry]) { parameters[n] = o[parameters.geometry]; diff --git a/modules/svg/debug.js b/modules/svg/debug.js index fae081f7c..00d586085 100644 --- a/modules/svg/debug.js +++ b/modules/svg/debug.js @@ -1,4 +1,9 @@ import { polygonIntersectsPolygon } from '../geo/index'; +import { + imperial as imperialData, + driveLeft as driveLeftData, + imagery as imageryData +} from '../../data/index'; export function Debug(projection, context) { @@ -74,7 +79,7 @@ export function Debug(projection, context) { var extent = context.map().extent(), - availableImagery = showsImagery && multipolygons(iD.data.imagery.filter(function(source) { + availableImagery = showsImagery && multipolygons(imageryData.filter(function(source) { if (!source.polygon) return false; return source.polygon.some(function(polygon) { return polygonIntersectsPolygon(polygon, extent, true); @@ -94,7 +99,7 @@ export function Debug(projection, context) { var imperial = layer .selectAll('path.debug-imperial') - .data(showsImperial ? [iD.data.imperial] : []); + .data(showsImperial ? [imperialData] : []); imperial.enter() .append('path') @@ -106,7 +111,7 @@ export function Debug(projection, context) { var driveLeft = layer .selectAll('path.debug-drive-left') - .data(showsDriveLeft ? [iD.data.driveLeft] : []); + .data(showsDriveLeft ? [driveLeftData] : []); driveLeft.enter() .append('path') diff --git a/modules/svg/mapillary_images.js b/modules/svg/mapillary_images.js index 452aef09f..77b466b41 100644 --- a/modules/svg/mapillary_images.js +++ b/modules/svg/mapillary_images.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import { PointTransform } from './point_transform'; +import { mapillary as mapillaryService } from '../services/index'; export function MapillaryImages(projection, context, dispatch) { var debouncedRedraw = _.debounce(function () { dispatch.change(); }, 1000), @@ -15,10 +16,10 @@ export function MapillaryImages(projection, context, dispatch) { } function getMapillary() { - if (iD.services.mapillary && !_mapillary) { - _mapillary = iD.services.mapillary.init(); + if (mapillaryService && !_mapillary) { + _mapillary = mapillaryService.init(); _mapillary.event.on('loadedImages', debouncedRedraw); - } else if (!iD.services.mapillary && _mapillary) { + } else if (!mapillaryService && _mapillary) { _mapillary = null; } diff --git a/modules/svg/mapillary_signs.js b/modules/svg/mapillary_signs.js index 3553d8977..a6a19b37d 100644 --- a/modules/svg/mapillary_signs.js +++ b/modules/svg/mapillary_signs.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import { PointTransform } from './point_transform'; +import { mapillary as mapillaryService } from '../services/index'; export function MapillarySigns(projection, context, dispatch) { var debouncedRedraw = _.debounce(function () { dispatch.change(); }, 1000), @@ -14,10 +15,10 @@ export function MapillarySigns(projection, context, dispatch) { } function getMapillary() { - if (iD.services.mapillary && !_mapillary) { - _mapillary = iD.services.mapillary.init(); + if (mapillaryService && !_mapillary) { + _mapillary = mapillaryService.init(); _mapillary.event.on('loadedSigns', debouncedRedraw); - } else if (!iD.services.mapillary && _mapillary) { + } else if (!mapillaryService && _mapillary) { _mapillary = null; } return _mapillary; diff --git a/modules/svg/tag_classes.js b/modules/svg/tag_classes.js index 714f5dff1..09eeb0cfc 100644 --- a/modules/svg/tag_classes.js +++ b/modules/svg/tag_classes.js @@ -1,3 +1,5 @@ +import { pavedTags } from '../core/tags'; + export function TagClasses() { var primaries = [ 'building', 'highway', 'railway', 'waterway', 'aeroway', @@ -85,8 +87,8 @@ export function TagClasses() { var paved = (t.highway !== 'track'); for (k in t) { v = t[k]; - if (k in iD.pavedTags) { - paved = !!iD.pavedTags[k][v]; + if (k in pavedTags) { + paved = !!pavedTags[k][v]; break; } } diff --git a/modules/ui/fields/address.js b/modules/ui/fields/address.js index ba7956e36..1a72df367 100644 --- a/modules/ui/fields/address.js +++ b/modules/ui/fields/address.js @@ -1,5 +1,7 @@ import _ from 'lodash'; import { Extent, chooseEdge, sphericalDistance } from '../../geo/index'; +import { nominatim } from '../../services/index'; +import { addressFormats } from '../../../data/index'; export function address(field, context) { var dispatch = d3.dispatch('init', 'change'), @@ -111,11 +113,11 @@ export function address(field, context) { var center = entity.extent(context.graph()).center(), addressFormat; - iD.services.nominatim.init(); - iD.services.nominatim.countryCode(center, function (err, countryCode) { - addressFormat = _.find(iD.data.addressFormats, function (a) { + nominatim.init(); + nominatim.countryCode(center, function (err, countryCode) { + addressFormat = _.find(addressFormats, function (a) { return a && a.countryCodes && _.includes(a.countryCodes, countryCode); - }) || _.first(iD.data.addressFormats); + }) || _.first(addressFormats); function row(r) { // Normalize widths. diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index fe5bcb903..fffdd5a1d 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -1,6 +1,8 @@ -import { t } from '../../util/locale'; import _ from 'lodash'; +import { t } from '../../util/locale'; +import { nominatim } from '../../services/index'; + export { combo as typeCombo, combo as multiCombo, @@ -240,8 +242,8 @@ export function combo(field, context) { if (isNetwork) { var center = entity.extent(context.graph()).center(); - iD.services.nominatim.init(); - iD.services.nominatim.countryCode(center, function (err, code) { + nominatim.init(); + nominatim.countryCode(center, function (err, code) { countryCode = code; }); } diff --git a/modules/ui/fields/input.js b/modules/ui/fields/input.js index e0c4af18c..64cbf4bcb 100644 --- a/modules/ui/fields/input.js +++ b/modules/ui/fields/input.js @@ -1,4 +1,6 @@ import { t } from '../../util/locale'; +import { nominatim as nominatimService } from '../../services/index'; +import { phoneFormats } from '../../../data/index'; export { url as text, @@ -30,11 +32,11 @@ export function url(field, context) { if (field.type === 'tel') { var center = entity.extent(context.graph()).center(); - iD.services.nominatim.init(); - iD.services.nominatim.countryCode(center, function (err, countryCode) { - if (err || !iD.data.phoneFormats[countryCode]) return; + nominatimService.init(); + nominatimService.countryCode(center, function (err, countryCode) { + if (err || !phoneFormats[countryCode]) return; selection.selectAll('#' + fieldId) - .attr('placeholder', iD.data.phoneFormats[countryCode]); + .attr('placeholder', phoneFormats[countryCode]); }); } else if (field.type === 'number') { diff --git a/modules/ui/fields/localized.js b/modules/ui/fields/localized.js index 22a5946fd..6b5dcf56b 100644 --- a/modules/ui/fields/localized.js +++ b/modules/ui/fields/localized.js @@ -4,10 +4,12 @@ import _ from 'lodash'; import { Detect } from '../../util/detect'; import { Icon } from '../../svg/index'; import { SuggestNames } from '../../util/index'; +import { wikipedia as wikipediaService } from '../../services/index'; +import { suggestions, wikipedia as wikipediaData } from '../../../data/index'; export function localized(field, context) { var dispatch = d3.dispatch('change', 'input'), - wikipedia = iD.services.wikipedia.init(), + wikipedia = wikipediaService.init(), input, localizedInputs, wikiTitles, entity; @@ -24,7 +26,7 @@ export function localized(field, context) { if (field.id === 'name') { var preset = context.presets().match(entity, context.graph()); input.call(d3.combobox().fetcher( - SuggestNames(preset, iD.data.suggestions) + SuggestNames(preset, suggestions) )); } @@ -81,7 +83,7 @@ export function localized(field, context) { function changeLang(d) { var lang = d3.select(this).value(), t = {}, - language = _.find(iD.data.wikipedia, function(d) { + language = _.find(wikipediaData, function(d) { return d[0].toLowerCase() === lang.toLowerCase() || d[1].toLowerCase() === lang.toLowerCase(); }); @@ -116,7 +118,7 @@ export function localized(field, context) { function fetcher(value, cb) { var v = value.toLowerCase(); - cb(iD.data.wikipedia.filter(function(d) { + cb(wikipediaData.filter(function(d) { return d[0].toLowerCase().indexOf(v) >= 0 || d[1].toLowerCase().indexOf(v) >= 0 || d[2].toLowerCase().indexOf(v) >= 0; @@ -202,7 +204,7 @@ export function localized(field, context) { entry.select('.localized-lang') .value(function(d) { - var lang = _.find(iD.data.wikipedia, function(lang) { return lang[2] === d.lang; }); + var lang = _.find(wikipediaData, function(lang) { return lang[2] === d.lang; }); return lang ? lang[1] : d.lang; }); diff --git a/modules/ui/fields/maxspeed.js b/modules/ui/fields/maxspeed.js index b8c57258a..e7850863e 100644 --- a/modules/ui/fields/maxspeed.js +++ b/modules/ui/fields/maxspeed.js @@ -1,5 +1,6 @@ import _ from 'lodash'; import { pointInPolygon } from '../../geo/index'; +import { imperial as imperialData } from '../../../data/index'; export function maxspeed(field, context) { var dispatch = d3.dispatch('change'), @@ -32,7 +33,7 @@ export function maxspeed(field, context) { var childNodes = context.graph().childNodes(context.entity(entity.id)), loc = childNodes[~~(childNodes.length/2)].loc; - imperial = _.some(iD.data.imperial.features, function(f) { + imperial = _.some(imperialData.features, function(f) { return _.some(f.geometry.coordinates, function(d) { return pointInPolygon(loc, d); }); diff --git a/modules/ui/fields/wikipedia.js b/modules/ui/fields/wikipedia.js index a3d3ce113..9265f0098 100644 --- a/modules/ui/fields/wikipedia.js +++ b/modules/ui/fields/wikipedia.js @@ -3,11 +3,16 @@ import _ from 'lodash'; import { ChangeTags } from '../../actions/index'; import { Detect } from '../../util/detect'; import { Icon } from '../../svg/index'; +import { wikipedia as wikipediaData } from '../../../data/index'; +import { + wikipedia as wikipediaService, + wikidata as wikidataService +} from '../../services/index'; export function wikipedia(field, context) { var dispatch = d3.dispatch('change'), - wikipedia = iD.services.wikipedia.init(), - wikidata = iD.services.wikidata.init(), + wikipedia = wikipediaService.init(), + wikidata = wikidataService.init(), link, entity, lang, title; function wiki(selection) { @@ -15,7 +20,7 @@ export function wikipedia(field, context) { .fetcher(function(value, cb) { var v = value.toLowerCase(); - cb(iD.data.wikipedia.filter(function(d) { + cb(wikipediaData.filter(function(d) { return d[0].toLowerCase().indexOf(v) >= 0 || d[1].toLowerCase().indexOf(v) >= 0 || d[2].toLowerCase().indexOf(v) >= 0; @@ -78,7 +83,7 @@ export function wikipedia(field, context) { var value = lang.value().toLowerCase(); var locale = Detect().locale.toLowerCase(); var localeLanguage; - return _.find(iD.data.wikipedia, function(d) { + return _.find(wikipediaData, function(d) { if (d[2] === locale) localeLanguage = d; return d[0].toLowerCase() === value || d[1].toLowerCase() === value || @@ -98,7 +103,7 @@ export function wikipedia(field, context) { function change(skipWikidata) { var value = title.value(), m = value.match(/https?:\/\/([-a-z]+)\.wikipedia\.org\/(?:wiki|\1-[-a-z]+)\/([^#]+)(?:#(.+))?/), - l = m && _.find(iD.data.wikipedia, function(d) { return m[1] === d[2]; }), + l = m && _.find(wikipediaData, function(d) { return m[1] === d[2]; }), anchor, syncTags = {}; @@ -162,7 +167,7 @@ export function wikipedia(field, context) { wiki.tags = function(tags) { var value = tags[field.key] || '', m = value.match(/([^:]+):([^#]+)(?:#(.+))?/), - l = m && _.find(iD.data.wikipedia, function(d) { return m[1] === d[2]; }), + l = m && _.find(wikipediaData, function(d) { return m[1] === d[2]; }), anchor = m && m[3]; // value in correct format diff --git a/modules/ui/preset_icon.js b/modules/ui/preset_icon.js index 2b7310477..6eb3fac5f 100644 --- a/modules/ui/preset_icon.js +++ b/modules/ui/preset_icon.js @@ -1,4 +1,6 @@ import { Icon } from '../svg/index'; +import { featureIcons } from '../../data/index'; + export function PresetIcon() { var preset, geometry; @@ -11,7 +13,7 @@ export function PresetIcon() { p = preset.apply(this, arguments), geom = geometry.apply(this, arguments), icon = p.icon || (geom === 'line' ? 'other-line' : 'marker-stroked'), - maki = iD.data.featureIcons.hasOwnProperty(icon + '-24'); + maki = featureIcons.hasOwnProperty(icon + '-24'); if (icon === 'dentist') maki = true; // workaround for dentist icon missing in `maki-sprite.json` diff --git a/package.json b/package.json index 77a815ee4..246d02d68 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "test": "npm run lint && make && phantomjs node_modules/mocha-phantomjs-core/mocha-phantomjs-core.js test/index.html dot", "start": "rollup --config=./rollup.config.js -w --input ./modules/id.js --output dist/iD.js", + "build": "rollup --config=./rollup.config.js -f iife --input ./modules/id.js --output dist/iD.js && uglifyjs dist/iD.js -c -m -o dist/iD.min.js", "lint": "eslint js/id test/spec modules" }, "repository": {