Skip to content
Open
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
2 changes: 1 addition & 1 deletion modules/behavior/edit.js → modules/behavior/edit.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function behaviorEdit(context) {
export function behaviorEdit(context: iD.Context) {

function behavior() {
context.map()
Expand Down
1 change: 1 addition & 0 deletions modules/core/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ export function coreContext() {
dispatch.call('enter', this, _mode);
};

/** @returns {string[]} */
context.selectedIDs = () => (_mode && _mode.selectedIDs && _mode.selectedIDs()) || [];
context.activeID = () => _mode && _mode.activeID && _mode.activeID();

Expand Down
17 changes: 7 additions & 10 deletions modules/osm/deprecated.js → modules/osm/deprecated.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/** @typedef {{ old: Tags; replace?: Tags }[]} DataDeprecated */
export type DataDeprecated = { old: Tags; replace?: Tags }[];

/** @param {Tags} tags @param {DataDeprecated} dataDeprecated */
export function getDeprecatedTags(tags, dataDeprecated) {
export function getDeprecatedTags(tags: Tags, dataDeprecated: DataDeprecated) {
// if there are no tags, none can be deprecated
if (Object.keys(tags).length === 0) return [];

/** @type {DataDeprecated} */
var deprecated = [];
var deprecated: DataDeprecated = [];
dataDeprecated.forEach((d) => {
const oldKeys = Object.keys(d.old);
const transferKeys = oldKeys.filter(key => d.old[key] === '*');
if (d.replace) {
var hasExistingValues = Object.keys(d.replace).some((replaceKey) => {
if (!tags[replaceKey] || d.old[replaceKey]) return false;
var replaceValue = d.replace[replaceKey];
var replaceValue = d.replace![replaceKey];
if (replaceValue === '*') return false;
if (replaceValue.startsWith('$1') && tags[replaceKey] === tags[transferKeys[+replaceValue.substring(1) - 1]]) return false;
if (replaceValue === tags[replaceKey]) return false;
Expand All @@ -38,7 +37,7 @@ export function getDeprecatedTags(tags, dataDeprecated) {
if (d.replace && d.old[oldKey] === d.replace[oldKey]) {
var replaceKeys = Object.keys(d.replace);
return !replaceKeys.every((replaceKey) => {
return tags[replaceKey] === d.replace[replaceKey];
return tags[replaceKey] === d.replace![replaceKey];
});
} else {
return true;
Expand All @@ -57,11 +56,9 @@ export function getDeprecatedTags(tags, dataDeprecated) {
return deprecated;
}

/** @type {{ [key: string]: string[] }} */
var _deprecatedTagValuesByKey;
var _deprecatedTagValuesByKey: { [key: string]: string[] };

/** @param {DataDeprecated} dataDeprecated */
export function deprecatedTagValuesByKey(dataDeprecated) {
export function deprecatedTagValuesByKey(dataDeprecated: DataDeprecated) {
if (!_deprecatedTagValuesByKey) {
_deprecatedTagValuesByKey = {};
dataDeprecated.forEach((d) => {
Expand Down
File renamed without changes.
58 changes: 27 additions & 31 deletions modules/osm/tags.js → modules/osm/tags.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { merge } from 'es-toolkit/compat';
import type { TagDictionary } from '../util/object';
import { getLuma } from '../util/util';

const uninterestingKeys = new Set([
Expand All @@ -20,11 +21,8 @@ const uninterestingKeyRegex = /^(source(_ref)?|at_bev|geobase|hcpaogis|KSJ2|mvdg
* Returns whether the given OSM tag key is potentially "interesting".
* For example, some tags are deemed not interesting because the respective tag is
* considered "discardable".
*
* @param {string} key the key to test
* @returns {boolean}
*/
export function osmIsInterestingTag(key) {
export function osmIsInterestingTag(key: string): boolean {
if (uninterestingKeys.has(key)) return false;
if (uninterestingKeyRegex.test(key)) return false;
return true;
Expand All @@ -45,8 +43,7 @@ export const osmLifecyclePrefixes = {
intermittent: true
};

/** @param {string} key */
export function osmRemoveLifecyclePrefix(key) {
export function osmRemoveLifecyclePrefix(key: string) {
const keySegments = key.split(':');
if (keySegments.length === 1) return key;

Expand All @@ -57,8 +54,8 @@ export function osmRemoveLifecyclePrefix(key) {
return key;
}

export var osmAreaKeys = {};
export function osmSetAreaKeys(value) {
export var osmAreaKeys: TagDictionary<true> = {};
export function osmSetAreaKeys(value: TagDictionary<true>) {
osmAreaKeys = value;
}

Expand All @@ -67,7 +64,7 @@ export function osmSetAreaKeys(value) {
// absence of a proper `area=yes` or `areaKeys` tag.. see #4194
// similarly, some tags are both used as a primary key for area features,
// but also as an attribute tag for linear features (e.g. `emergency=yes`)
export var osmAreaKeysExceptions = {
export var osmAreaKeysExceptions: TagDictionary<boolean> = {
highway: {
elevator: true,
rest_area: true,
Expand Down Expand Up @@ -102,11 +99,11 @@ export var osmAreaKeysExceptions = {
};

// returns an object with the tag from `tags` that implies an area geometry, if any
export function osmTagSuggestingArea(tags) {
export function osmTagSuggestingArea(tags: Tags) {
if (tags.area === 'yes') return { area: 'yes' };
if (tags.area === 'no') return null;

var returnTags = {};
var returnTags: Tags = {};
for (var realKey in tags) {
const key = osmRemoveLifecyclePrefix(realKey);
if (key in osmAreaKeysExceptions && osmAreaKeysExceptions[key][tags[realKey]] === false) {
Expand All @@ -124,33 +121,33 @@ export function osmTagSuggestingArea(tags) {
return null;
}

export var osmLineTags = {};
export function osmSetLineTags(value) {
export var osmLineTags: TagDictionary<true> = {};
export function osmSetLineTags(value: TagDictionary<true>) {
osmLineTags = value;
}

// Tags that indicate a node can be a standalone point
// e.g. { amenity: { bar: true, parking: true, ... } ... }
export var osmPointTags = {};
export function osmSetPointTags(value) {
export var osmPointTags: TagDictionary<true> = {};
export function osmSetPointTags(value: TagDictionary<true>) {
osmPointTags = value;
}
// Tags that indicate a node can be part of a way
// e.g. { amenity: { parking: true, ... }, highway: { stop: true ... } ... }
export var osmVertexTags = {};
export function osmSetVertexTags(value) {
export var osmVertexTags: TagDictionary<true> = {};
export function osmSetVertexTags(value: TagDictionary<true>) {
osmVertexTags = value;
}

//These tags belong strictly on ways and should never be moved up to a relation
export const osmWayOnlyTags = {
export const osmWayOnlyTags: TagDictionary<true> = {
'natural': {
'coastline': true
}
};

export function osmNodeGeometriesForTags(nodeTags) {
var geometries = {};
export function osmNodeGeometriesForTags(nodeTags: Tags) {
const geometries: { point?: boolean; vertex?: boolean } = {};
for (var key in nodeTags) {
if (osmPointTags[key] &&
(osmPointTags[key]['*'] || osmPointTags[key][nodeTags[key]])) {
Expand Down Expand Up @@ -274,7 +271,7 @@ export var osmSemipavedTags = {
}
};

export var osmRightSideIsInsideTags = {
export var osmRightSideIsInsideTags: TagDictionary<true | string> = {
'natural': {
'cliff': true,
'coastline': 'coastline'
Expand All @@ -296,30 +293,30 @@ export var osmRightSideIsInsideTags = {

// "highway" tag values for pedestrian or vehicle right-of-ways that make up the routable network
// (does not include `raceway`)
export var osmRoutableHighwayTagValues = {
export var osmRoutableHighwayTagValues: Record<string, true> = {
motorway: true, trunk: true, primary: true, secondary: true, tertiary: true, residential: true,
motorway_link: true, trunk_link: true, primary_link: true, secondary_link: true, tertiary_link: true,
unclassified: true, road: true, service: true, track: true, living_street: true, bus_guideway: true, busway: true,
path: true, footway: true, cycleway: true, bridleway: true, pedestrian: true, corridor: true, steps: true, ladder: true
};
/** aeroway tags that are treated as routable for aircraft */
export const osmRoutableAerowayTags = {
export const osmRoutableAerowayTags: Record<string, true> = {
runway: true, taxiway: true
};
// "highway" tag values that generally do not allow motor vehicles
export var osmPathHighwayTagValues = {
export var osmPathHighwayTagValues: Record<string, true> = {
path: true, footway: true, cycleway: true, bridleway: true, pedestrian: true, corridor: true, steps: true, ladder: true
};

// "railway" tag values representing existing railroad tracks (purposely does not include 'abandoned')
export var osmRailwayTrackTagValues = {
export var osmRailwayTrackTagValues: Record<string, true> = {
rail: true, light_rail: true, tram: true, subway: true,
monorail: true, funicular: true, miniature: true, narrow_gauge: true,
disused: true, preserved: true
};

// "waterway" tag values for line features representing water flow
export var osmFlowingWaterwayTagValues = {
export var osmFlowingWaterwayTagValues: Record<string, true> = {
canal: true, ditch: true, drain: true, fish_pass: true, flowline: true, river: true, stream: true, tidal_channel: true
};

Expand Down Expand Up @@ -347,7 +344,7 @@ export var osmLanduseTags = {
export const allowUpperCaseTagValues = /network|taxon|genus|species|brand|grape_variety|royal_cypher|listed_status|booth|rating|stars|:output|_hours|_times|_ref|manufacturer|country|target|brewery|cai_scale|traffic_sign/;

// Returns whether a `colour` tag value looks like a valid color we can display
export function isColorValid(value) {
export function isColorValid(value: string) {
if (!value) return false;
if (!value.match(/^(#([0-9a-fA-F]{3}){1,2}|\w+)$/)) {
// OSM only supports hex or named colors
Expand All @@ -360,8 +357,8 @@ export function isColorValid(value) {
return true;
}

export function getRelationColor(tags, fallback) {
let color, textColor;
export function getRelationColor(tags: Tags, fallback: string) {
let color = '', textColor = '';
if (tags['ref:colour']) color = tags['ref:colour'];
else if (tags.colour) color = tags.colour;
const isValid = isColorValid(color);
Expand Down Expand Up @@ -389,11 +386,10 @@ export const osmMutuallyExclusiveTagPairs = [


/**
* @param {Tags} vertexTags @param {Tags} wayTags
* returns true if iD should render the `direction` tag for
* this vertex+way combination.
*/
export function osmShouldRenderDirection(vertexTags, wayTags) {
export function osmShouldRenderDirection(vertexTags: Tags, wayTags: Tags) {
if (vertexTags.highway || vertexTags.traffic_sign || vertexTags.traffic_calming || vertexTags.barrier) {
// allowed on roads and tramways
return !!(wayTags.highway || wayTags.railway);
Expand Down
2 changes: 2 additions & 0 deletions modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,7 @@ export function rendererMap(context) {
};


/** @type {GetSet<unknown, Vec2>} */
map.dimensions = function(val) {
if (!arguments.length) return _dimensions;

Expand Down Expand Up @@ -993,6 +994,7 @@ export function rendererMap(context) {
};


/** @type {GetSet<typeof map, geoExtent>} */
map.trimmedExtent = function(val) {
if (!arguments.length) {
var headerY = 71;
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions modules/svg/tag_pattern.js → modules/svg/tag_pattern.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Patterns only work in Firefox when set directly on element.
import type { TagDictionary } from '../util/object';

// (This is not a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=750632)
var patterns = {
const patterns: TagDictionary<string | Tags[]> = {
// tag - pattern name
// -or-
// tag - value - pattern name
Expand Down Expand Up @@ -76,7 +78,7 @@ var patterns = {
}
};

export function svgTagPattern(tags) {
export function svgTagPattern(tags: Tags) {
// Skip pattern filling if this is a building (buildings don't get patterns applied)
if (tags.building && tags.building !== 'no') {
return null;
Expand Down
2 changes: 1 addition & 1 deletion modules/svg/touch.js → modules/svg/touch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export function svgTouch() {

function drawTouch(selection) {
function drawTouch(selection: d3.Selection) {
selection.selectAll('.layer-touch')
.data(['areas', 'lines', 'points', 'turns', 'markers'])
.enter()
Expand Down
2 changes: 1 addition & 1 deletion modules/ui/confirm.js → modules/ui/confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { t } from '../core/localizer';
import { uiModal } from './modal';


export function uiConfirm(selection) {
export function uiConfirm(selection: d3.Selection) {
var modalSelection = uiModal(selection);

modalSelection.select('.modal')
Expand Down
4 changes: 2 additions & 2 deletions modules/ui/restore.js → modules/ui/restore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { t } from '../core/localizer';
import { uiModal } from './modal';


export function uiRestore(context) {
return function(selection) {
export function uiRestore(context: iD.Context) {
return function(selection: d3.Selection) {
if (!context.history().hasRestorableChanges()) return;

let modalSelection = uiModal(selection, true);
Expand Down
9 changes: 5 additions & 4 deletions modules/ui/scale.js → modules/ui/scale.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { displayLength } from '../util/units';
import { geoLonToMeters, geoMetersToLon } from '../geo';
import { localizer } from '../core/localizer';
import type { Vec2 } from '../geo/vector';


export function uiScale(context) {
export function uiScale(context: iD.Context) {
var projection = context.projection,
isImperial = !localizer.usesMetric(),
maxLength = 180,
tickHeight = 8;


function scaleDefs(loc1, loc2) {
function scaleDefs(loc1: Vec2, loc2: Vec2) {
var lat = (loc2[1] + loc1[1]) / 2,
conversion = (isImperial ? 3.28084 : 1),
dist = geoLonToMeters(loc2[0] - loc1[0], lat) * conversion,
Expand Down Expand Up @@ -43,7 +44,7 @@ export function uiScale(context) {
}


function update(selection) {
function update(selection: d3.Selection) {
// choose loc1, loc2 along bottom of viewport (near where the scale will be drawn)
var dims = context.map().dimensions(),
loc1 = projection.invert([0, dims[1]]),
Expand All @@ -59,7 +60,7 @@ export function uiScale(context) {
}


return function(selection) {
return function(selection: d3.Selection) {
function switchUnits() {
isImperial = !isImperial;
selection.call(update);
Expand Down
Loading