diff --git a/notNeededPackages.json b/notNeededPackages.json index e35ac38e73464c..a017e6a57cd0bb 100644 --- a/notNeededPackages.json +++ b/notNeededPackages.json @@ -1973,6 +1973,10 @@ "libraryName": "eslint-plugin-mocha", "asOfVersion": "11.1.0" }, + "eslint-scope": { + "libraryName": "eslint-scope", + "asOfVersion": "9.1.0" + }, "eslint-visitor-keys": { "libraryName": "eslint-visitor-keys", "asOfVersion": "3.3.0" @@ -1989,6 +1993,10 @@ "libraryName": "esm-utils", "asOfVersion": "2.0.1" }, + "espree": { + "libraryName": "espree", + "asOfVersion": "11.1.0" + }, "eth-sig-util": { "libraryName": "eth-sig-util", "asOfVersion": "2.5.3" @@ -4069,6 +4077,10 @@ "libraryName": "map-obj", "asOfVersion": "3.1.0" }, + "mapbox-gl": { + "libraryName": "mapbox-gl", + "asOfVersion": "3.5.0" + }, "mapbox__point-geometry": { "libraryName": "@mapbox/point-geometry", "asOfVersion": "1.0.0" @@ -7795,10 +7807,6 @@ "libraryName": "@typeform/embed", "asOfVersion": "1.0.0" }, - "vue-tel-input": { - "libraryName": "vue-tel-input", - "asOfVersion": "9.7.1" - }, "typescript": { "libraryName": "typescript", "asOfVersion": "2.0.0" @@ -8039,6 +8047,10 @@ "libraryName": "vue-scrollto", "asOfVersion": "2.17.1" }, + "vue-tel-input": { + "libraryName": "vue-tel-input", + "asOfVersion": "9.7.1" + }, "vue3-json-viewer": { "libraryName": "vue3-json-viewer", "asOfVersion": "2.4.0" diff --git a/types/eslint-scope/.npmignore b/types/eslint-scope/.npmignore deleted file mode 100644 index 93e307400a5456..00000000000000 --- a/types/eslint-scope/.npmignore +++ /dev/null @@ -1,5 +0,0 @@ -* -!**/*.d.ts -!**/*.d.cts -!**/*.d.mts -!**/*.d.*.ts diff --git a/types/eslint-scope/eslint-scope-tests.ts b/types/eslint-scope/eslint-scope-tests.ts deleted file mode 100644 index b8dfd855f361ed..00000000000000 --- a/types/eslint-scope/eslint-scope-tests.ts +++ /dev/null @@ -1,339 +0,0 @@ -import * as eslintScope from "eslint-scope"; -import type { AnalyzeOptions } from "eslint-scope"; -import * as espree from "espree"; -import * as estree from "estree"; - -const code = ` -function example() { - let x = 1; - console.log(x); -} -`; - -const ast = espree.parse(code, { ecmaVersion: 2022, sourceType: "module" }) as estree.Program; - -// $ExpectType ScopeManager -const scopeManager = eslintScope.analyze( - ast, - { - ecmaVersion: 2022, - sourceType: "module", - ignoreEval: true, - nodejsScope: false, - impliedStrict: false, - childVisitorKeys: null, - fallback: "iteration", - } satisfies AnalyzeOptions, -); - -// $ExpectType GlobalScope -scopeManager.globalScope; -// $ExpectType Scope, Reference>[] -scopeManager.scopes; - -// $ExpectType Scope, Reference> | null -const scope = scopeManager.acquire(ast); - -// $ExpectType Scope, Reference> | null -scopeManager.release(ast); - -if (scope) { - // $ExpectType "function" | "module" | "block" | "catch" | "class" | "for" | "function-expression-name" | "global" | "switch" | "with" | "TDZ" - scope.type; - // $ExpectType boolean - scope.isStrict; - // $ExpectType Scope, Reference> | null - scope.upper; - // $ExpectType Scope, Reference> - scope.variableScope; - // $ExpectType Variable[] - scope.variables; - // $ExpectType Reference[] - scope.references; - // $ExpectType Scope, Reference>[] - scope.childScopes; - // $ExpectType Node - scope.block; - // $ExpectType boolean - scope.functionExpressionScope; - // $ExpectType Reference[] - scope.implicit.left; - // $ExpectType Map> - scope.implicit.set; - // $ExpectType Variable[] - scope.implicit.variables; - // $ExpectType Map - scope.set; - // $ExpectType Reference[] - scope.through; -} - -const variable = scope?.variables[0]; -if (variable) { - // $ExpectType string - variable.name; - // $ExpectType Scope, Reference> - variable.scope; - // $ExpectType Identifier[] - variable.identifiers; - // $ExpectType Reference[] - variable.references; - // $ExpectType Definition[] - variable.defs; -} - -const reference = scope?.references[0]; -if (reference) { - // $ExpectType Identifier - reference.identifier; - // $ExpectType Variable | null - reference.resolved; - // $ExpectType () => boolean - reference.isWrite; - // $ExpectType () => boolean - reference.isRead; - // $ExpectType Scope, Reference> - reference.from; -} - -const definition = variable?.defs[0]; -if (definition) { - // $ExpectType "CatchClause" | "TDZ" | "ClassName" | "FunctionName" | "ImplicitGlobalVariable" | "ImportBinding" | "Parameter" | "Variable" - definition.type; - // $ExpectType Identifier - definition.name; - // $ExpectType ImportDeclaration | VariableDeclaration | null - definition.parent; -} - -// $ExpectType GlobalScope -const globalScope = scopeManager.globalScope; -// $ExpectType 'global' -globalScope.type; - -// $ExpectType ScopeManager -eslintScope.analyze(ast); - -const blockScope = new eslintScope.BlockScope(scopeManager, scopeManager.globalScope, ast); -// $ExpectType "block" -blockScope.type; - -const identifier: estree.Identifier = { - type: "Identifier", - name: "foo", -}; -const definition2 = new eslintScope.Definition( - "Variable", - identifier, - ast, - null, - null, - "let", -); -// $ExpectType "CatchClause" | "TDZ" | "ClassName" | "FunctionName" | "ImplicitGlobalVariable" | "ImportBinding" | "Parameter" | "Variable" -definition2.type; -// $ExpectType Identifier -definition2.name; - -const functionScope = new eslintScope.FunctionScope(scopeManager, scopeManager.globalScope, ast, false); -// $ExpectType "function" -functionScope.type; -// $ExpectType boolean -functionScope.isArgumentsMaterialized(); -// $ExpectType boolean -functionScope.isThisMaterialized(); - -const globalScopeInstance = new eslintScope.GlobalScope(scopeManager, ast); -// $ExpectType "global" -globalScopeInstance.type; - -const moduleScope = new eslintScope.ModuleScope(scopeManager, scopeManager.globalScope, ast); -// $ExpectType "module" -moduleScope.type; - -const ref = new eslintScope.Reference( - identifier, - scopeManager.globalScope, - 0, - null, - false, - false, - false, -); -// $ExpectType Identifier -ref.identifier; -// $ExpectType Scope, Reference> -ref.from; -// $ExpectType boolean -ref.isRead(); -// $ExpectType boolean -ref.isWrite(); -// $ExpectType boolean -ref.isReadOnly(); -// $ExpectType boolean -ref.isWriteOnly(); -// $ExpectType boolean -ref.isReadWrite(); - -const scopeInstance = new eslintScope.Scope( - scopeManager, - "block", - null, - ast, - false, -); -// $ExpectType "function" | "module" | "block" | "catch" | "class" | "for" | "function-expression-name" | "global" | "switch" | "with" | "TDZ" -scopeInstance.type; -// $ExpectType boolean -scopeInstance.isStrict; -// $ExpectType Scope, Reference> | null -scopeInstance.upper; -// $ExpectType Scope, Reference> -scopeInstance.variableScope; -// $ExpectType Variable[] -scopeInstance.variables; -// $ExpectType Reference[] -scopeInstance.references; -// $ExpectType Scope, Reference>[] -scopeInstance.childScopes; -// $ExpectType Node -scopeInstance.block; -// $ExpectType boolean -scopeInstance.functionExpressionScope; -// $ExpectType { left: Reference[]; set: Map>; variables: Variable[]; } -scopeInstance.implicit; -// $ExpectType Map -scopeInstance.set; -// $ExpectType Map> -scopeInstance.taints; -// $ExpectType Reference[] -scopeInstance.through; -// $ExpectType boolean -scopeInstance.dynamic; -// $ExpectType boolean -scopeInstance.directCallToEvalScope; -// $ExpectType boolean -scopeInstance.thisFound; -// $ExpectType void -scopeInstance.resolve(ref); -// $ExpectType boolean -scopeInstance.isStatic(); -// $ExpectType boolean -scopeInstance.isArgumentsMaterialized(); -// $ExpectType boolean -scopeInstance.isThisMaterialized(); -// $ExpectType boolean -scopeInstance.isUsedName("foo"); - -const scopeManagerInstance = new eslintScope.ScopeManager({ - ecmaVersion: 2022, - sourceType: "module", -}); -// $ExpectType GlobalScope -scopeManagerInstance.globalScope; -// $ExpectType Scope, Reference>[] -scopeManagerInstance.scopes; -// $ExpectType Scope, Reference> | null -scopeManagerInstance.acquire(ast); -// $ExpectType Scope, Reference>[] | null -scopeManagerInstance.acquireAll(ast); -// $ExpectType Scope, Reference> | null -scopeManagerInstance.release(ast); -// $ExpectType Variable[] -scopeManagerInstance.getDeclaredVariables(ast); -// $ExpectType boolean -scopeManagerInstance.isGlobalReturn(); -// $ExpectType boolean -scopeManagerInstance.isModule(); -// $ExpectType boolean -scopeManagerInstance.isImpliedStrict(); -// $ExpectType boolean -scopeManagerInstance.isStrictModeSupported(); - -const variableInstance = new eslintScope.Variable("foo", scopeInstance); -// $ExpectType string -variableInstance.name; -// $ExpectType Scope, Reference> -variableInstance.scope; -// $ExpectType Identifier[] -variableInstance.identifiers; -// $ExpectType Reference[] -variableInstance.references; -// $ExpectType Definition[] -variableInstance.defs; -// $ExpectType boolean -variableInstance.tainted; -// $ExpectType boolean -variableInstance.stack; - -let node: any; -if (eslintScope.PatternVisitor.isPattern(node)) { - // $ExpectType Identifier | ObjectPattern | ArrayPattern | SpreadElement | RestElement | AssignmentPattern - node; -} - -declare let rootPattern: estree.Pattern; - -// // $ExpectType PatternVisitor -const patternVisitor = new eslintScope.PatternVisitor( - { - fallback: (node: any) => Object.keys(node).filter((key) => key !== "parent"), - childVisitorKeys: { TestExpression: ["argument"] }, - }, - rootPattern, - (pattern, misc) => { - // $ExpectType Identifier - pattern; - // $ExpectType AssignmentPattern[] - misc.assignments; - // $ExpectType boolean - misc.rest; - // $ExpectType boolean - misc.topLevel; - }, -); - -// $ExpectType Pattern -patternVisitor.rootPattern; - -// $ExpectType PatternVisitorCallback -patternVisitor.callback; - -// $ExpectType AssignmentPattern[] -patternVisitor.assignments; - -// $ExpectType Expression[] -patternVisitor.rightHandNodes; - -// $ExpectType RestElement[] -patternVisitor.restElements; - -// $ExpectType (pattern: Identifier) => void -patternVisitor.Identifier; - -// $ExpectType (pattern: Property) => void -patternVisitor.Property; - -// $ExpectType (pattern: ArrayPattern) => void -patternVisitor.ArrayPattern; - -// $ExpectType (pattern: AssignmentPattern) => void -patternVisitor.AssignmentPattern; - -// $ExpectType (pattern: RestElement) => void -patternVisitor.RestElement; - -// $ExpectType (pattern: MemberExpression) => void -patternVisitor.MemberExpression; - -// $ExpectType (pattern: SpreadElement) => void -patternVisitor.SpreadElement; - -// $ExpectType (pattern: SpreadElement) => void -patternVisitor.ArrayExpression; - -// $ExpectType (pattern: AssignmentExpression) => void -patternVisitor.AssignmentExpression; - -// $ExpectType (pattern: CallExpression) => void -patternVisitor.CallExpression; diff --git a/types/eslint-scope/index.d.cts b/types/eslint-scope/index.d.cts deleted file mode 100644 index 0ef411ee4a85d9..00000000000000 --- a/types/eslint-scope/index.d.cts +++ /dev/null @@ -1,580 +0,0 @@ -import * as eslint from "eslint"; -import { VisitorKeys } from "eslint-visitor-keys"; -import { Visitor, VisitorOptions } from "esrecurse"; -import * as ESTree from "estree"; - -/** - * Options for scope analysis. - */ -export interface AnalyzeOptions { - /** - * Whether to ignore eval() calls, which normally create scopes. - * @default false - */ - ignoreEval?: boolean; - - /** - * Whether to create a top-level function scope for CommonJS evaluation. - * @default false - */ - nodejsScope?: boolean; - - /** - * Whether to evaluate code in strict mode even outside modules or without "use strict". - * @default false - */ - impliedStrict?: boolean; - - /** - * The ECMAScript version to use for evaluation (e.g., 5, 2015, 2022). - * @default 5 - */ - ecmaVersion?: number; - - /** - * The type of JavaScript file to evaluate. - * @default "script" - */ - sourceType?: "script" | "module" | "commonjs"; - - /** - * Visitor key information for performance enhancement. - * @default null - */ - childVisitorKeys?: VisitorKeys | null; - - /** - * Strategy to use when childVisitorKeys is not specified. - * @default "iteration" - */ - fallback?: "iteration" | ((node: ESTree.Node) => string[]); - - /** - * Whether to enable optimistic scope analysis. - * @default false - */ - optimistic?: boolean; - - /** - * Enables the tracking of JSX components as variable references. - * @default false - */ - jsx?: boolean; -} - -export type PatternVisitorCallback = ( - pattern: ESTree.Identifier, - misc: { - topLevel: boolean; - rest: boolean; - assignments: ESTree.AssignmentPattern[]; - }, -) => void; - -/** - * Manages the scope hierarchy of an AST. - */ -export class ScopeManager implements eslint.Scope.ScopeManager { - /** - * Creates a new ScopeManager instance. - * @param options Options for scope analysis. - */ - constructor(options: AnalyzeOptions); - - /** - * The global scope. - */ - globalScope: GlobalScope; - - /** - * All scopes in the analyzed program. - */ - scopes: Scope[]; - - /** - * Acquires the scope for a given node. - * @param node The AST node to get the scope for. - * @param inner Whether to get the innermost scope. - * @returns The scope or null if not found. - */ - acquire(node: ESTree.Node, inner?: boolean): Scope | null; - - /** - * acquire all scopes from node. - * @param node node for the acquired scope. - * @returns Scope array - */ - acquireAll(node: ESTree.Node): Scope[] | null; - - /** - * Releases a scope, moving to its parent. - * @param node The AST node to release the scope for. - * @param inner Whether to release the innermost scope. - * @returns The parent scope or null if not found. - */ - release(node: ESTree.Node, inner?: boolean): Scope | null; - - /** - * Gets all scopes for a given node, including parents. - * @param node The AST node to get scopes for. - * @param inner Whether to start from the innermost scope. - * @returns Array of scopes or empty array if none found. - */ - getDeclaredVariables(node: ESTree.Node): Variable[]; - - isGlobalReturn(): boolean; - - isModule(): boolean; - - isImpliedStrict(): boolean; - - isStrictModeSupported(): boolean; -} - -/** - * Base export class for all scopes. - */ -export class Scope - implements eslint.Scope.Scope -{ - /** - * Creates a new Scope instance. - * @param scopeManager The scope manager this scope belongs to. - * @param type The type of the scope. - * @param upper The parent scope, or null for the global scope. - * @param block The AST node that created this scope. - * @param isMethodDefinition Whether this scope is for a method definition. - */ - constructor( - scopeManager: ScopeManager, - type: string, - upper: Scope | null, - block: ESTree.Node, - isMethodDefinition: boolean, - ); - - /** - * The type of the scope (e.g., 'global', 'function'). - */ - type: eslint.Scope.Scope["type"]; - - /** - * Whether the scope is in strict mode. - */ - isStrict: boolean; - - /** - * The parent scope, or null for the global scope. - */ - upper: Scope | null; - - /** - * The scope where variables are declared (same as this for most scopes). - */ - variableScope: this; - - /** - * Variables defined in this scope. - */ - variables: TVariable[]; - - /** - * References to variables in this scope. - */ - references: TReference[]; - - /** - * Child scopes. - */ - childScopes: Scope[]; - - /** - * The AST node that created this scope. - */ - block: ESTree.Node; - - /** - * Whether this is a function expression scope. - */ - functionExpressionScope: boolean; - - /** - * Implicit references (e.g., 'arguments' in functions). - */ - implicit: { left: TReference[]; set: Map; variables: Variable[] }; - - /** - * Map of variable names to variables. - */ - set: eslint.Scope.Scope["set"]; - - /** - * The tainted variables of this scope. - */ - taints: Map; - - /** - * References that pass through this scope to outer scopes. - */ - through: eslint.Scope.Scope["through"]; - - /** - * Dynamic flag for certain scope types. - */ - dynamic: boolean; - - /** - * Direct call to eval() flag. - */ - directCallToEvalScope: boolean; - - /** - * This scope flag. - */ - thisFound: boolean; - - /** - * Resolves a reference in this scope. - * @param ref The reference to resolve. - * @param noChain Whether to avoid chaining to parent scopes. - */ - resolve(ref: Reference, noChain?: boolean): void; - - /** - * Whether the reference is static. - */ - isStatic(): boolean; - - /** - * returns this scope has materialized arguments. - */ - isArgumentsMaterialized(): boolean; - - /** - * returns this scope has materialized `this` reference - */ - isThisMaterialized(): boolean; - - isUsedName(name: string): boolean; -} - -/** - * Global scope. - */ -export class GlobalScope extends Scope { - /** - * Creates a new GlobalScope instance. - * @param scopeManager The scope manager this scope belongs to. - * @param block The AST node that created this scope. - */ - constructor(scopeManager: ScopeManager, block: ESTree.Node); - - type: "global"; -} - -/** - * Module scope. - */ -export class ModuleScope extends Scope { - /** - * Creates a new ModuleScope instance. - * @param scopeManager The scope manager this scope belongs to. - * @param upper The parent scope. - * @param block The AST node that created this scope. - */ - constructor(scopeManager: ScopeManager, upper: Scope, block: ESTree.Node); - - type: "module"; -} - -/** - * Function scope. - */ -export class FunctionScope extends Scope { - /** - * Creates a new FunctionScope instance. - * @param scopeManager The scope manager this scope belongs to. - * @param upper The parent scope. - * @param block The AST node that created this scope. - * @param isMethodDefinition Whether this scope is for a method definition. - */ - constructor( - scopeManager: ScopeManager, - upper: Scope, - block: ESTree.Node, - isMethodDefinition: boolean, - ); - - type: "function"; - - isArgumentsMaterialized(): boolean; - - isThisMaterialized(): boolean; -} - -/** - * Block scope. - */ -export class BlockScope extends Scope { - /** - * Creates a new BlockScope instance. - * @param scopeManager The scope manager this scope belongs to. - * @param upper The parent scope. - * @param block The AST node that created this scope. - */ - constructor(scopeManager: ScopeManager, upper: Scope, block: ESTree.Node); - - type: "block"; -} - -/** - * Represents a variable in a scope. - */ -export class Variable implements eslint.Scope.Variable { - /** - * Creates a new Variable instance. - * @param name The name of the variable. - * @param scope The scope where the variable is defined. - */ - constructor(name: string, scope: Scope); - - /** - * The name of the variable. - */ - name: string; - - /** - * The scope where the variable is defined. - */ - scope: Scope; - - /** - * Identifiers that declare this variable. - */ - identifiers: ESTree.Identifier[]; - - /** - * References to this variable. - */ - references: TReference[]; - - /** - * Definitions of this variable. - */ - defs: eslint.Scope.Definition[]; - - /** - * Whether the variable is tainted (e.g., potentially modified externally). - */ - tainted: boolean; - - /** - * Stack flag for certain variable types. - */ - stack: boolean; -} - -/** - * Represents a reference to a variable. - */ -export class Reference implements eslint.Scope.Reference { - /** - * Creates a new Reference instance. - * @param identifier The identifier node of the reference. - * @param scope The scope where the reference occurs. - * @param flag The reference flag (read, write, or read-write). - * @param writeExpr The expression being written, if applicable. - * @param maybeImplicitGlobal Whether this is a potential implicit global. - * @param partial Whether this is a partial reference. - * @param init Whether this is an initialization reference. - */ - constructor( - identifier: ESTree.Identifier, - scope: Scope, - flag: number, - writeExpr: ESTree.Expression | null, - maybeImplicitGlobal: boolean, - partial: boolean, - init: boolean, - ); - - /** - * The identifier node of the reference. - */ - identifier: ESTree.Identifier; - - /** - * The variable being referenced, or null if unresolved. - */ - resolved: Variable | null; - - /** - * Whether the reference is static. - */ - isStatic(): boolean; - - /** - * Whether this is a write operation. - */ - isWrite: eslint.Scope.Reference["isWrite"]; - - /** - * Whether this is a read operation. - */ - isRead: eslint.Scope.Reference["isRead"]; - - /** - * The scope where the reference occurs. - */ - from: Scope; - - /** - * Whether the reference comes from a dynamic scope (such as 'eval', - * 'with', etc.), and may be trapped by dynamic scopes. - */ - tainted: boolean; - - /** - * The expression being written, if applicable. - */ - writeExpr: ESTree.Expression | null; - - /** - * Whether this is a partial reference. - */ - partial: boolean; - - /** - * Whether this is an initialization reference. - */ - init: boolean; - - /** - * Whether this reference is only read. - * @returns True if the reference is read-only. - */ - isReadOnly(): boolean; - - /** - * Whether this reference is only written. - * @returns True if the reference is write-only. - */ - isWriteOnly(): boolean; - - /** - * Whether this reference is read-write. - * @returns True if the reference is read-write. - */ - isReadWrite(): boolean; -} - -/** - * Represents a variable definition. - * @todo extends eslint.Scope.Definition for this class - */ -export class Definition { - /** - * Creates a new Definition instance. - * @param type The type of definition (e.g., 'Variable', 'Parameter'). - * @param name The identifier node of the definition. - * @param node The AST node where the definition occurs. - * @param parent The parent node, if applicable. - * @param index The index of the definition in a pattern, if applicable. - * @param kind The kind of variable (e.g., 'var', 'let', 'const'), if applicable. - */ - constructor( - type: eslint.Scope.Definition["type"], - name: eslint.Scope.Definition["name"], - node: eslint.Scope.Definition["node"], - parent: eslint.Scope.Definition["parent"], - index: number | null, - kind: string | null, - ); - - /** - * The type of definition (e.g., 'Variable', 'Parameter'). - */ - type: eslint.Scope.Definition["type"]; - - /** - * The identifier node of the definition. - */ - name: eslint.Scope.Definition["name"]; - - /** - * The AST node where the definition occurs. - */ - node: eslint.Scope.Definition["node"]; - - /** - * The parent node, if applicable. - */ - parent: eslint.Scope.Definition["parent"]; - - /** - * The index of the definition in a pattern, if applicable. - */ - index: number | null; - - /** - * The kind of variable (e.g., 'var', 'let', 'const'), if applicable. - */ - kind: string | null; -} - -/** - * Visitor for destructuring patterns. - */ -export class PatternVisitor extends Visitor { - static isPattern(node: ESTree.Node): node is - | ESTree.Identifier - | ESTree.ObjectPattern - | ESTree.ArrayPattern - | ESTree.SpreadElement - | ESTree.RestElement - | ESTree.AssignmentPattern; - - constructor( - options: VisitorOptions | null | undefined, - rootPattern: ESTree.Pattern, - callback: PatternVisitorCallback, - ); - - rootPattern: ESTree.Pattern; - - callback: PatternVisitorCallback; - - assignments: ESTree.AssignmentPattern[]; - - rightHandNodes: ESTree.Expression[]; - - restElements: ESTree.RestElement[]; - - Identifier(pattern: ESTree.Identifier): void; - - Property(pattern: ESTree.Property): void; - - ArrayPattern(pattern: ESTree.ArrayPattern): void; - - AssignmentPattern(pattern: ESTree.AssignmentPattern): void; - - RestElement(pattern: ESTree.RestElement): void; - - MemberExpression(pattern: ESTree.MemberExpression): void; - - SpreadElement(pattern: ESTree.SpreadElement): void; - - ArrayExpression(pattern: ESTree.SpreadElement): void; - - AssignmentExpression(pattern: ESTree.AssignmentExpression): void; - - CallExpression(pattern: ESTree.CallExpression): void; -} - -/** - * Analyzes the scope of an AST. - * @param ast The ESTree-compliant AST to analyze. - * @param options Options for scope analysis. - * @returns The scope manager for the analyzed AST. - */ -export function analyze(ast: ESTree.Program, options?: AnalyzeOptions): ScopeManager; diff --git a/types/eslint-scope/index.d.mts b/types/eslint-scope/index.d.mts deleted file mode 100644 index 328c8bfd06a9f6..00000000000000 --- a/types/eslint-scope/index.d.mts +++ /dev/null @@ -1,31 +0,0 @@ -import { - analyze, - type AnalyzeOptions, - BlockScope, - Definition, - FunctionScope, - GlobalScope, - ModuleScope, - PatternVisitor, - type PatternVisitorCallback, - Reference, - Scope, - ScopeManager, - Variable, -} from "./index.cjs"; - -export { - analyze, - type AnalyzeOptions, - BlockScope, - Definition, - FunctionScope, - GlobalScope, - ModuleScope, - PatternVisitor, - type PatternVisitorCallback, - Reference, - Scope, - ScopeManager, - Variable, -}; diff --git a/types/eslint-scope/index.d.ts b/types/eslint-scope/index.d.ts deleted file mode 100644 index e1cfc6c6a8acda..00000000000000 --- a/types/eslint-scope/index.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { - analyze, - type AnalyzeOptions, - BlockScope, - Definition, - FunctionScope, - GlobalScope, - ModuleScope, - Reference, - Scope, - ScopeManager, - Variable, -} from "./index.cjs"; - -export { - analyze, - type AnalyzeOptions, - BlockScope, - Definition, - FunctionScope, - GlobalScope, - ModuleScope, - Reference, - Scope, - ScopeManager, - Variable, -}; diff --git a/types/eslint-scope/package.json b/types/eslint-scope/package.json deleted file mode 100644 index da32b4722fa455..00000000000000 --- a/types/eslint-scope/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "private": true, - "name": "@types/eslint-scope", - "version": "8.4.9999", - "type": "module", - "projects": [ - "https://github.com/eslint/eslint-scope" - ], - "dependencies": { - "@types/eslint": "*", - "@types/esrecurse": "*", - "@types/estree": "*", - "eslint-visitor-keys": "*" - }, - "devDependencies": { - "@types/eslint-scope": "workspace:.", - "@types/espree": "*" - }, - "exports": { - ".": { - "import": "./index.d.mts", - "require": "./index.d.cts" - }, - "./package.json": "./package.json" - }, - "owners": [ - { - "name": "Toru Nagashima", - "githubUsername": "mysticatea" - } - ] -} diff --git a/types/eslint-scope/tsconfig.json b/types/eslint-scope/tsconfig.json deleted file mode 100644 index 1bca3b3951c2c3..00000000000000 --- a/types/eslint-scope/tsconfig.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "compilerOptions": { - "module": "node16", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "strictFunctionTypes": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true, - "allowSyntheticDefaultImports": true - }, - "files": [ - "index.d.cts", - "index.d.mts", - "index.d.ts", - "eslint-scope-tests.ts" - ] -} diff --git a/types/espree/.npmignore b/types/espree/.npmignore deleted file mode 100644 index 93e307400a5456..00000000000000 --- a/types/espree/.npmignore +++ /dev/null @@ -1,5 +0,0 @@ -* -!**/*.d.ts -!**/*.d.cts -!**/*.d.mts -!**/*.d.*.ts diff --git a/types/espree/espree-tests.ts b/types/espree/espree-tests.ts deleted file mode 100644 index 138b903301ada2..00000000000000 --- a/types/espree/espree-tests.ts +++ /dev/null @@ -1,40 +0,0 @@ -import espree = require("espree"); -import type { Options } from "espree"; - -const ast = espree.parse("let foo = \"bar\""); -const ast_option = espree.parse("let foo = \"bar\"", { ecmaVersion: 6 }); - -const tokens = espree.tokenize("let foo = \"bar\""); -const tokens_option = espree.tokenize("let foo = \"bar\"", { ecmaVersion: 6 }); - -// $ExpectType string -const version = espree.version; - -const visitor_keys = espree.VisitorKeys; - -// $ExpectType number -const latest_ecma = espree.latestEcmaVersion; - -// $ExpectType number[] -const supported_ecma = espree.supportedEcmaVersions; - -const full_options: Options = { - range: false, - loc: false, - comment: false, - tokens: false, - ecmaVersion: 3, - allowReserved: true, - sourceType: "script", - ecmaFeatures: { - jsx: false, - globalReturn: false, - impliedStrict: false, - }, -}; - -const empty_options: Options = {}; - -const latest_options: Options = { - ecmaVersion: 16, -}; diff --git a/types/espree/index.d.cts b/types/espree/index.d.cts deleted file mode 100644 index 68fab8e3ac1fba..00000000000000 --- a/types/espree/index.d.cts +++ /dev/null @@ -1,122 +0,0 @@ -import type { Program, Token } from "acorn"; -import type { VisitorKeys } from "eslint-visitor-keys"; - -/** - * Parses the given code and returns a abstract syntax tree (AST). - * @param code The code which needs to be parsed. - * @param options Options defining how to tokenize. - * @returns The "Program" AST node. - */ -export function parse(code: string, options?: Options): Program; - -/** - * Returns the tokens of a given code. - * @param code The code which needs to be parsed. - * @param options Options defining how to tokenize. - * @returns An array of tokens. - */ -export function tokenize(code: string, options?: Options): Token[]; - -/** - * Returns the current `espree` version - */ -export const version: string; - -/** - * Returns all visitor keys for traversing the AST from eslint-visitor-keys - */ -export const VisitorKeys: VisitorKeys; - -/** - * Returns the latest ECMAScript supported by `espree` - */ -export const latestEcmaVersion: number; - -/** - * Returns an array of all supported ECMAScript versions - */ -export const supportedEcmaVersions: number[]; - -export interface Options { - /** - * Attach range information to each node - */ - range?: boolean; - - /** - * Attach line/column location information to each node - */ - loc?: boolean; - - /** - * Create a top-level comments array containing all comments - */ - comment?: boolean; - - /** - * Create a top-level tokens array containing all tokens - */ - tokens?: boolean; - - /** - * Set to 3, 5 (the default), 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 or 16 to specify the version of ECMAScript syntax you want to use. - * You can also set to 2015 (same as 6), 2016 (same as 7), 2017 (same as 8), 2018 (same as 9), 2019 (same as 10), 2020 (same as 11), 2021 (same as 12), 2022 (same as 13), 2023 (same as 14), 2024 (same as 15) or 2025 (same as 16) to use the year-based naming. - * You can also set "latest" to use the most recently supported version. - */ - ecmaVersion?: - | 3 - | 5 - | 6 - | 7 - | 8 - | 9 - | 10 - | 11 - | 12 - | 13 - | 14 - | 15 - | 16 - | 2015 - | 2016 - | 2017 - | 2018 - | 2019 - | 2020 - | 2021 - | 2022 - | 2023 - | 2024 - | 2025 - | "latest"; - - /** - * Only allowed when ecmaVersion is 3 - */ - allowReserved?: boolean; - - /** - * Specify which type of script you're parsing ("script", "module", or "commonjs") - */ - sourceType?: "script" | "module" | "commonjs"; - - /** - * Specify additional language features - */ - ecmaFeatures?: { - /** - * Enable JSX parsing - */ - jsx?: boolean; - - /** - * Enable return in global scope (set to true automatically when sourceType is "commonjs") - */ - globalReturn?: boolean; - - /** - * Enable implied strict mode (if ecmaVersion >= 5) - */ - impliedStrict?: boolean; - }; -} diff --git a/types/espree/index.d.ts b/types/espree/index.d.ts deleted file mode 100644 index bd5377d1bb805c..00000000000000 --- a/types/espree/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./index.cjs"; diff --git a/types/espree/package.json b/types/espree/package.json deleted file mode 100644 index f4508211753a47..00000000000000 --- a/types/espree/package.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "private": true, - "name": "@types/espree", - "version": "10.1.9999", - "type": "module", - "exports": { - ".": { - "import": "./index.d.ts", - "require": "./index.d.cts" - }, - "./package.json": "./package.json" - }, - "projects": [ - "https://github.com/eslint/espree" - ], - "dependencies": { - "acorn": "^8.12.0", - "eslint-visitor-keys": "^4.0.0" - }, - "devDependencies": { - "@types/espree": "workspace:." - }, - "owners": [ - { - "name": "e6nlaq", - "githubUsername": "e6nlaq" - } - ] -} diff --git a/types/espree/tsconfig.json b/types/espree/tsconfig.json deleted file mode 100644 index b529ec648638b7..00000000000000 --- a/types/espree/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "module": "node16", - "lib": [ - "es6" - ], - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "strictNullChecks": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "index.d.cts", - "espree-tests.ts" - ] -} diff --git a/types/mapbox-gl/.eslintrc.json b/types/mapbox-gl/.eslintrc.json deleted file mode 100644 index 0fe3c8d6ec5898..00000000000000 --- a/types/mapbox-gl/.eslintrc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rules": { - "@definitelytyped/export-just-namespace": "off", - "@definitelytyped/no-any-union": "off", - "@definitelytyped/no-unnecessary-generics": "off", - "@definitelytyped/strict-export-declare-modifiers": "off", - "@typescript-eslint/no-unsafe-function-type": "off", - "@typescript-eslint/no-wrapper-object-types": "off", - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/consistent-type-definitions": "off" - } -} diff --git a/types/mapbox-gl/.npmignore b/types/mapbox-gl/.npmignore deleted file mode 100644 index a5c5eebaff98f9..00000000000000 --- a/types/mapbox-gl/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -* -!**/*.d.ts -!**/*.d.cts -!**/*.d.mts -!**/*.d.*.ts -/v1/ -/v2/ diff --git a/types/mapbox-gl/index.d.ts b/types/mapbox-gl/index.d.ts deleted file mode 100644 index 9b480bd1ade73b..00000000000000 --- a/types/mapbox-gl/index.d.ts +++ /dev/null @@ -1,2801 +0,0 @@ -/// - -export = mapboxgl; -export as namespace mapboxgl; - -declare namespace mapboxgl { - let accessToken: string; - let version: string; - let baseApiUrl: string; - - /** - * Number of web workers instantiated on a page with GL JS maps. - * By default, it is set to half the number of CPU cores (capped at 6). - */ - let workerCount: number; - - /** - * Maximum number of images (raster tiles, sprites, icons) to load in parallel, which affects performance in raster-heavy maps. - * 16 by default. - */ - let maxParallelImageRequests: number; - - export function supported(options?: { failIfMajorPerformanceCaveat?: boolean | undefined }): boolean; - - /** - * Clears browser storage used by this library. Using this method flushes the Mapbox tile cache that is managed by this library. - * Tiles may still be cached by the browser in some cases. - */ - export function clearStorage(callback?: (err?: Error) => void): void; - - export function setRTLTextPlugin(pluginURL: string, callback: (error: Error) => void, deferred?: boolean): void; - export function getRTLTextPluginStatus(): PluginStatus; - - /** - * Initializes resources like WebWorkers that can be shared across maps to lower load - * times in some situations. `mapboxgl.workerUrl` and `mapboxgl.workerCount`, if being - * used, must be set before `prewarm()` is called to have an effect. - * - * By default, the lifecycle of these resources is managed automatically, and they are - * lazily initialized when a Map is first created. By invoking `prewarm()`, these - * resources will be created ahead of time, and will not be cleared when the last Map - * is removed from the page. This allows them to be re-used by new Map instances that - * are created later. They can be manually cleared by calling - * `mapboxgl.clearPrewarmedResources()`. This is only necessary if your web page remains - * active but stops using maps altogether. - * - * This is primarily useful when using GL-JS maps in a single page app, wherein a user - * would navigate between various views that can cause Map instances to constantly be - * created and destroyed. - */ - export function prewarm(): void; - - /** - * Clears up resources that have previously been created by `mapboxgl.prewarm()`. - * Note that this is typically not necessary. You should only call this function - * if you expect the user of your app to not return to a Map view at any point - * in your application. - */ - export function clearPrewarmedResources(): void; - - type PluginStatus = "unavailable" | "loading" | "loaded" | "error"; - - type LngLatLike = [number, number] | LngLat | { lng: number; lat: number } | { lon: number; lat: number }; - - type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number] | LngLatLike; - type PointLike = Point | [number, number]; - type Offset = number | PointLike | { [_: string]: PointLike }; - - type ExpressionName = - // Types - | "array" - | "boolean" - | "collator" - | "format" - | "literal" - | "number" - | "number-format" - | "object" - | "string" - | "image" - | "to-boolean" - | "to-color" - | "to-number" - | "to-string" - | "typeof" - // Feature data - | "feature-state" - | "geometry-type" - | "id" - | "line-progress" - | "properties" - // Lookup - | "at" - | "get" - | "has" - | "in" - | "index-of" - | "length" - | "slice" - | "config" - // Decision - | "!" - | "!=" - | "<" - | "<=" - | "==" - | ">" - | ">=" - | "all" - | "any" - | "case" - | "match" - | "coalesce" - | "within" - // Ramps, scales, curves - | "interpolate" - | "interpolate-hcl" - | "interpolate-lab" - | "step" - // Variable binding - | "let" - | "var" - // String - | "concat" - | "downcase" - | "is-supported-script" - | "resolved-locale" - | "upcase" - // Color - | "hsl" - | "hsla" - | "rgb" - | "rgba" - | "to-rgba" - // Math - | "-" - | "*" - | "/" - | "%" - | "^" - | "+" - | "abs" - | "acos" - | "asin" - | "atan" - | "ceil" - | "cos" - | "distance" - | "e" - | "floor" - | "ln" - | "ln2" - | "log10" - | "log2" - | "max" - | "min" - | "pi" - | "random" - | "round" - | "sin" - | "sqrt" - | "tan" - // Camera - | "distance-from-center" - | "pitch" - | "zoom" - | "raster-value" - // Lights - | "measure-light" - // Heatmap - | "heatmap-density"; - - type Expression = [ExpressionName, ...any[]]; - - type Anchor = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; - - type DragPanOptions = { - linearity?: number; - easing?: (t: number) => number; - deceleration?: number; - maxSpeed?: number; - }; - - type InteractiveOptions = { around?: "center" }; - - /** - * Map - */ - export class Map extends Evented { - constructor(options?: MapboxOptions); - - addControl( - control: Control | IControl, - position?: "top-right" | "top-left" | "bottom-right" | "bottom-left", - ): this; - - removeControl(control: Control | IControl): this; - - /** - * Checks if a control exists on the map. - * - * @param {IControl} control The {@link IControl} to check. - * @returns {boolean} True if map contains control. - * @example - */ - hasControl(control: IControl): boolean; - - resize(eventData?: EventData): this; - - getBounds(): LngLatBounds; - - getMaxBounds(): LngLatBounds | null; - - setMaxBounds(lnglatbounds?: LngLatBoundsLike): this; - - setMinZoom(minZoom?: number | null): this; - - getMinZoom(): number; - - setMaxZoom(maxZoom?: number | null): this; - - getMaxZoom(): number; - - setMinPitch(minPitch?: number | null): this; - - getMinPitch(): number; - - setMaxPitch(maxPitch?: number | null): this; - - getMaxPitch(): number; - - getRenderWorldCopies(): boolean; - - setRenderWorldCopies(renderWorldCopies?: boolean): this; - - project(lnglat: LngLatLike): mapboxgl.Point; - - unproject(point: PointLike): mapboxgl.LngLat; - - isMoving(): boolean; - - isZooming(): boolean; - - isRotating(): boolean; - - /** - * Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters. - * - * The properties value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only string and numeric property values are supported (i.e. null, Array, and Object values are not supported). - * - * Each feature includes top-level layer, source, and sourceLayer properties. The layer property is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature. - * - * Only features that are currently rendered are included. Some features will not be included, like: - * - * - Features from layers whose visibility property is "none". - * - Features from layers whose zoom range excludes the current zoom level. - * - Symbol features that have been hidden due to text or icon collision. - * - * Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to 0. - * - * The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat). - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param pointOrBox The geometry of the query region: either a single point or southwest and northeast points describing a bounding box. Omitting this parameter (i.e. calling Map#queryRenderedFeatures with zero arguments, or with only a options argument) is equivalent to passing a bounding box encompassing the entire map viewport. - * @param options - */ - queryRenderedFeatures( - pointOrBox?: PointLike | [PointLike, PointLike], - options?: { layers?: string[] | undefined; filter?: any[] | undefined } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - /** - * Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters. - * - * In contrast to Map#queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport. - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param sourceID The ID of the vector tile or GeoJSON source to query. - * @param parameters - */ - querySourceFeatures( - sourceID: string, - parameters?: { - sourceLayer?: string | undefined; - filter?: any[] | undefined; - } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - setStyle( - style: mapboxgl.Style | string, - options?: { diff?: boolean | undefined; localIdeographFontFamily?: string | undefined }, - ): this; - - getStyle(): mapboxgl.Style; - - isStyleLoaded(): boolean; - - addSource(id: string, source: AnySourceData): this; - - isSourceLoaded(id: string): boolean; - - areTilesLoaded(): boolean; - - removeSource(id: string): this; - - getSource(id: string): AnySourceImpl; - - addImage( - name: string, - image: - | HTMLImageElement - | ArrayBufferView - | { width: number; height: number; data: Uint8Array | Uint8ClampedArray } - | ImageData - | ImageBitmap, - options?: { - pixelRatio?: number | undefined; - sdf?: boolean | undefined; - stretchX?: Array<[number, number]> | undefined; - stretchY?: Array<[number, number]> | undefined; - content?: [number, number, number, number] | undefined; - }, - ): void; - - updateImage( - name: string, - image: - | HTMLImageElement - | ArrayBufferView - | { width: number; height: number; data: Uint8Array | Uint8ClampedArray } - | ImageData - | ImageBitmap, - ): void; - - hasImage(name: string): boolean; - - removeImage(name: string): void; - - loadImage(url: string, callback: (error?: Error, result?: HTMLImageElement | ImageBitmap) => void): void; - - listImages(): string[]; - - addLayer(layer: mapboxgl.AnyLayer, before?: string): this; - - moveLayer(id: string, beforeId?: string): this; - - removeLayer(id: string): this; - - getLayer(id: string): mapboxgl.AnyLayer; - - setFilter(layer: string, filter?: any[] | boolean | null, options?: FilterOptions | null): this; - - setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number): this; - - getFilter(layer: string): any[]; - - setPaintProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getPaintProperty(layer: string, name: string): any; - - setLayoutProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getLayoutProperty(layer: string, name: string): any; - - /** - * Returns the value of a configuration property in the imported style. - * - * @param {string} importId The name of the imported style to set the config for (e.g. `basemap`). - * @param {string} configName The name of the configuration property from the style. - * @returns {*} Returns the value of the configuration property. - * @example - * map.getConfigProperty('basemap', 'showLabels'); - */ - getConfigProperty(importId: string, configName: string): any; - - /** - * Sets the value of a configuration property in the currently set style. - * - * @param {string} importId The name of the imported style to set the config for (e.g. `basemap`). - * @param {string} configName The name of the configuration property from the style. - * @param {*} value The value of the configuration property. Must be of a type appropriate for the property, as defined by the style configuration schema. - * @returns {Map} Returns itself to allow for method chaining. - * @example - * map.setConfigProperty('basemap', 'showLabels', false); - */ - setConfigProperty(importId: string, configName: string, value: any): this; - - setLight(light: mapboxgl.Light, options?: FilterOptions): this; - - getLight(): mapboxgl.Light; - - /** - * Sets the terrain property of the style. - * - * @param terrain Terrain properties to set. Must conform to the [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#terrain). - * If `null` or `undefined` is provided, function removes terrain. - * @returns {Map} `this` - * @example - * map.addSource('mapbox-dem', { - * 'type': 'raster-dem', - * 'url': 'mapbox://mapbox.mapbox-terrain-dem-v1', - * 'tileSize': 512, - * 'maxzoom': 14 - * }); - * // add the DEM source as a terrain layer with exaggerated height - * map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.5 }); - */ - setTerrain(terrain?: TerrainSpecification | null): this; - - getTerrain(): TerrainSpecification | null; - - showTerrainWireframe: boolean; - - /** - * @param lngLat The coordinate to query - * @param options Optional {ElevationQueryOptions} - * @returns The elevation in meters at mean sea level or null - */ - queryTerrainElevation(lngLat: mapboxgl.LngLatLike, options?: ElevationQueryOptions): number | null; - - setFeatureState( - feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, - state: { [key: string]: any }, - ): void; - - getFeatureState(feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature): { [key: string]: any }; - - removeFeatureState(target: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, key?: string): void; - - getContainer(): HTMLElement; - - getCanvasContainer(): HTMLElement; - - getCanvas(): HTMLCanvasElement; - - loaded(): boolean; - - remove(): void; - - triggerRepaint(): void; - - showTileBoundaries: boolean; - - showCollisionBoxes: boolean; - - /** - * Gets and sets a Boolean indicating whether the map will visualize - * the padding offsets. - * - * @name showPadding - * @instance - * @memberof Map - */ - showPadding: boolean; - - repaint: boolean; - - getCenter(): mapboxgl.LngLat; - - setCenter(center: LngLatLike, eventData?: mapboxgl.EventData): this; - - panBy(offset: PointLike, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - panTo(lnglat: LngLatLike, options?: mapboxgl.AnimationOptions, eventdata?: mapboxgl.EventData): this; - - getZoom(): number; - - setZoom(zoom: number, eventData?: mapboxgl.EventData): this; - - zoomTo(zoom: number, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomIn(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomOut(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getBearing(): number; - - setBearing(bearing: number, eventData?: mapboxgl.EventData): this; - - /** - * Returns the current padding applied around the map viewport. - * - * @memberof Map# - * @returns The current padding around the map viewport. - */ - getPadding(): PaddingOptions; - - /** - * Sets the padding in pixels around the viewport. - * - * Equivalent to `jumpTo({padding: padding})`. - * - * @memberof Map# - * @param padding The desired padding. Format: { left: number, right: number, top: number, bottom: number } - * @param eventData Additional properties to be added to event objects of events triggered by this method. - * @fires movestart - * @fires moveend - * @returns {Map} `this` - * @example - * // Sets a left padding of 300px, and a top padding of 50px - * map.setPadding({ left: 300, top: 50 }); - */ - setPadding(padding: PaddingOptions, eventData?: EventData): this; - - rotateTo(bearing: number, options?: AnimationOptions & CameraOptions, eventData?: EventData): this; - - resetNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - resetNorthPitch(options?: mapboxgl.AnimationOptions | null, eventData?: mapboxgl.EventData | null): this; - - snapToNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getPitch(): number; - - setPitch(pitch: number, eventData?: EventData): this; - - cameraForBounds(bounds: LngLatBoundsLike, options?: CameraForBoundsOptions): CameraForBoundsResult | undefined; - - fitBounds(bounds: LngLatBoundsLike, options?: mapboxgl.FitBoundsOptions, eventData?: mapboxgl.EventData): this; - - fitScreenCoordinates( - p0: PointLike, - p1: PointLike, - bearing: number, - options?: AnimationOptions & CameraOptions, - eventData?: EventData, - ): this; - - jumpTo(options: mapboxgl.CameraOptions, eventData?: mapboxgl.EventData): this; - - /** - * Returns position and orientation of the camera entity. - * - * @memberof Map# - * @returns {FreeCameraOptions} The camera state - */ - getFreeCameraOptions(): FreeCameraOptions; - - /** - * FreeCameraOptions provides more direct access to the underlying camera entity. - * For backwards compatibility the state set using this API must be representable with - * `CameraOptions` as well. Parameters are clamped into a valid range or discarded as invalid - * if the conversion to the pitch and bearing presentation is ambiguous. For example orientation - * can be invalid if it leads to the camera being upside down, the quaternion has zero length, - * or the pitch is over the maximum pitch limit. - * - * @memberof Map# - * @param {FreeCameraOptions} options FreeCameraOptions object - * @param eventData Additional properties to be added to event objects of events triggered by this method. - * @fires movestart - * @fires zoomstart - * @fires pitchstart - * @fires rotate - * @fires move - * @fires zoom - * @fires pitch - * @fires moveend - * @fires zoomend - * @fires pitchend - * @returns {Map} `this` - */ - setFreeCameraOptions(options: FreeCameraOptions, eventData?: Object): this; - - easeTo(options: mapboxgl.EaseToOptions, eventData?: mapboxgl.EventData): this; - - flyTo(options: mapboxgl.FlyToOptions, eventData?: mapboxgl.EventData): this; - - isEasing(): boolean; - - stop(): this; - - on( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - on(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - on(type: string, listener: (ev: any) => void): this; - - once( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - once(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - once(type: string, listener: (ev: any) => void): this; - once(type: T): Promise; - - off( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - off(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - off(type: string, listener: (ev: any) => void): this; - - scrollZoom: ScrollZoomHandler; - - boxZoom: BoxZoomHandler; - - dragRotate: DragRotateHandler; - - dragPan: DragPanHandler; - - keyboard: KeyboardHandler; - - doubleClickZoom: DoubleClickZoomHandler; - - touchZoomRotate: TouchZoomRotateHandler; - - touchPitch: TouchPitchHandler; - - getFog(): Fog | null; - /** - * @param fog If `null` or `undefined` is provided, function removes fog from - * the map. - */ - setFog(fog: Fog | null | undefined): this; - - getProjection(): Projection; - setProjection(projection: Projection | string): this; - } - - export interface MapboxOptions { - /** - * If specified, map will use this token instead of the one defined in mapboxgl.accessToken. - * - * @default null - */ - accessToken?: string | undefined; - - /** - * If true, the gl context will be created with MSA antialiasing, which can be useful for antialiasing custom layers. - * This is false by default as a performance optimization. - */ - antialias?: boolean | undefined; - - /** If true, an attribution control will be added to the map. */ - attributionControl?: boolean | undefined; - - bearing?: number | undefined; - - /** Snap to north threshold in degrees. */ - bearingSnap?: number | undefined; - - /** The initial bounds of the map. If bounds is specified, it overrides center and zoom constructor options. */ - bounds?: LngLatBoundsLike | undefined; - - /** If true, enable the "box zoom" interaction (see BoxZoomHandler) */ - boxZoom?: boolean | undefined; - - /** initial map center */ - center?: LngLatLike | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click for it to be - * considered a valid click (as opposed to a mouse drag). - * - * @default 3 - */ - clickTolerance?: number | undefined; - - /** - * If `true`, Resource Timing API information will be collected for requests made by GeoJSON - * and Vector Tile web workers (this information is normally inaccessible from the main - * Javascript thread). Information will be returned in a `resourceTiming` property of - * relevant `data` events. - * - * @default false - */ - collectResourceTiming?: boolean | undefined; - - /** - * The initial configuration options for the style fragments. Each key in the object is a - * fragment ID (e.g., `basemap`) and each value is a configuration object. - * - * @default null - */ - config?: Record; - - /** - * If `true`, symbols from multiple sources can collide with each other during collision - * detection. If `false`, collision detection is run separately for the symbols in each source. - * - * @default true - */ - crossSourceCollisions?: boolean | undefined; - - /** ID of the container element */ - container: string | HTMLElement; - - /** - * If `true` , scroll zoom will require pressing the ctrl or ⌘ key while scrolling to zoom map, - * and touch pan will require using two fingers while panning to move the map. - * Touch pitch will require three fingers to activate if enabled. - */ - cooperativeGestures?: boolean; - - /** String or strings to show in an AttributionControl. - * Only applicable if options.attributionControl is `true`. */ - customAttribution?: string | string[] | undefined; - - /** - * If `true`, the "drag to pan" interaction is enabled. - * An `Object` value is passed as options to {@link DragPanHandler#enable}. - */ - dragPan?: boolean | DragPanOptions | undefined; - - /** If true, enable the "drag to rotate" interaction (see DragRotateHandler). */ - dragRotate?: boolean | undefined; - - /** If true, enable the "double click to zoom" interaction (see DoubleClickZoomHandler). */ - doubleClickZoom?: boolean | undefined; - - /** If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL. - * For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`. - * An additional string may optionally be provided to indicate a parameter-styled hash, - * e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo - * is a custom parameter and bar is an arbitrary hash distinct from the map hash. - */ - hash?: boolean | string | undefined; - - /** - * Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. - * This setting affects all symbol layers. This setting does not affect the duration of runtime - * styling transitions or raster tile cross-fading. - * - * @default 300 - */ - fadeDuration?: number | undefined; - - /** If true, map creation will fail if the implementation determines that the performance of the created WebGL context would be dramatically lower than expected. */ - failIfMajorPerformanceCaveat?: boolean | undefined; - - /** A fitBounds options object to use only when setting the bounds option. */ - fitBoundsOptions?: FitBoundsOptions | undefined; - - /** If false, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input */ - interactive?: boolean | undefined; - - /** If true, enable keyboard shortcuts (see KeyboardHandler). */ - keyboard?: boolean | undefined; - - /** - * A string with a BCP 47 language tag, or an array of such strings representing the desired - * languages used for the map's labels and UI components. - * - * @default null - */ - language?: "auto" | string | string[]; - - /** A patch to apply to the default localization table for UI strings, e.g. control tooltips. - * The `locale` object maps namespaced UI string IDs to translated strings in the target language; - * see `src/ui/default_locale.js` for an example with all supported string IDs. - * The object may specify all UI strings (thereby adding support for a new translation) or - * only a subset of strings (thereby patching the default translation table). - */ - locale?: { [key: string]: string } | undefined; - - /** - * Overrides the generation of all glyphs and font settings except font-weight keywords - * Also overrides localIdeographFontFamily - * @default null - */ - localFontFamily?: string | undefined; - - /** - * If specified, defines a CSS font-family for locally overriding generation of glyphs in the - * 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. In these ranges, font settings from - * the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). - * The purpose of this option is to avoid bandwidth-intensive glyph server requests. - * - * @default null - */ - localIdeographFontFamily?: string | undefined; - - /** - * A string representing the position of the Mapbox wordmark on the map. - * - * @default "bottom-left" - */ - logoPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | undefined; - - /** If set, the map is constrained to the given bounds. */ - maxBounds?: LngLatBoundsLike | undefined; - - /** Maximum pitch of the map. */ - maxPitch?: number | undefined; - - /** - * The maximum number of tiles stored in the tile cache for a given source. If omitted, the - * cache will be dynamically sized based on the current viewport. - * - * @default null - */ - maxTileCacheSize?: number | undefined; - - /** Maximum zoom of the map. */ - maxZoom?: number | undefined; - - /** Minimum pitch of the map. */ - minPitch?: number | undefined; - - /** - * The minimum number of tiles stored in the tile cache for a given source. If omitted, the - * cache will be dynamically sized based on the current viewport. - * - * @default null - */ - minTileCacheSize?: number | undefined; - - /** Minimum zoom of the map. */ - minZoom?: number | undefined; - - /** - * If `true`, mapbox-gl will collect and send performance metrics. - * - * @default true - */ - performanceMetricsCollection?: boolean; - - /** If true, The maps canvas can be exported to a PNG using map.getCanvas().toDataURL();. This is false by default as a performance optimization. */ - preserveDrawingBuffer?: boolean | undefined; - - /** - * The initial pitch (tilt) of the map, measured in degrees away from the plane of the - * screen (0-60). - * - * @default 0 - */ - pitch?: number | undefined; - - /** - * A style's projection property sets which projection a map is rendered in. - * - * @default 'mercator' - */ - projection?: Projection | Projection["name"]; - - /** - * If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled. - * - * @default true - */ - pitchWithRotate?: boolean | undefined; - - /** - * If `false`, the map won't attempt to re-request tiles once they expire per their HTTP - * `cacheControl`/`expires` headers. - * - * @default true - */ - refreshExpiredTiles?: boolean | undefined; - - /** - * If `true`, multiple copies of the world will be rendered, when zoomed out. - * - * @default true - */ - renderWorldCopies?: boolean | undefined; - - /** - * If set to `true`, the map will respect the user's `prefers-reduced-motion` browser - * setting and apply a reduced motion mode, minimizing animations and transitions. When set - * to `false` , the map will always ignore the `prefers-reduced-motion` settings, regardless - * of the user's preference, making all animations essential. - * - * @default true - */ - respectPrefersReducedMotion?: boolean; - - /** - * If `true`, the "scroll to zoom" interaction is enabled. - * An `Object` value is passed as options to {@link ScrollZoomHandler#enable}. - */ - scrollZoom?: boolean | InteractiveOptions | undefined; - - /** stylesheet location */ - style?: mapboxgl.Style | string | undefined; - - /** - * Allows for the usage of the map in automated tests without an accessToken with custom self-hosted test fixtures. - * - * @default null - */ - testMode?: boolean | undefined; - - /** If true, the map will automatically resize when the browser window resizes */ - trackResize?: boolean | undefined; - - /** - * A callback run before the Map makes a request for an external URL. The callback can be - * used to modify the url, set headers, or set the credentials property for cross-origin requests. - * - * @default null - */ - transformRequest?: TransformRequestFunction | undefined; - - /** - * If `true`, the "pinch to rotate and zoom" interaction is enabled. - * An `Object` value is passed as options to {@link TouchZoomRotateHandler#enable}. - */ - touchZoomRotate?: boolean | InteractiveOptions | undefined; - - /** - * If `true`, the "drag to pitch" interaction is enabled. - * An `Object` value is passed as options to {@link TouchPitchHandler#enable}. - */ - touchPitch?: boolean | InteractiveOptions | undefined; - - /** - * Sets the map's worldview. A worldview determines the way that certain disputed boundaries are rendered. - * By default, GL JS will not set a worldview so that the worldview of Mapbox tiles will be determined by - * the vector tile source's TileJSON. Valid worldview strings must be an ISO alpha-2 country code. - * - * @default null - */ - worldview?: string | undefined; - - /** Initial zoom level */ - zoom?: number | undefined; - } - - type quat = number[]; - type vec3 = number[]; - - /** - * Various options for accessing physical properties of the underlying camera entity. - * A direct access to these properties allows more flexible and precise controlling of the camera - * while also being fully compatible and interchangeable with CameraOptions. All fields are optional. - * See {@Link Camera#setFreeCameraOptions} and {@Link Camera#getFreeCameraOptions} - * - * @param {MercatorCoordinate} position Position of the camera in slightly modified web mercator coordinates - - The size of 1 unit is the width of the projected world instead of the "mercator meter". - Coordinate [0, 0, 0] is the north-west corner and [1, 1, 0] is the south-east corner. - - Z coordinate is conformal and must respect minimum and maximum zoom values. - - Zoom is automatically computed from the altitude (z) - * @param {quat} orientation Orientation of the camera represented as a unit quaternion [x, y, z, w] - in a left-handed coordinate space. Direction of the rotation is clockwise around the respective axis. - The default pose of the camera is such that the forward vector is looking up the -Z axis and - the up vector is aligned with north orientation of the map: - forward: [0, 0, -1] - up: [0, -1, 0] - right [1, 0, 0] - Orientation can be set freely but certain constraints still apply - - Orientation must be representable with only pitch and bearing. - - Pitch has an upper limit - */ - export class FreeCameraOptions { - constructor(position?: MercatorCoordinate, orientation?: quat); - - position: MercatorCoordinate | undefined; - - /** - * Helper function for setting orientation of the camera by defining a focus point - * on the map. - * - * @param {LngLatLike} location Location of the focus point on the map - * @param {vec3} up Up vector of the camera is required in certain scenarios where bearing can't be deduced - * from the viewing direction. - */ - lookAtPoint(location: LngLatLike, up?: vec3): void; - - /** - * Helper function for setting the orientation of the camera as a pitch and a bearing. - * - * @param {number} pitch Pitch angle in degrees - * @param {number} bearing Bearing angle in degrees - */ - setPitchBearing(pitch: number, bearing: number): void; - } - - export type ResourceType = - | "Unknown" - | "Style" - | "Source" - | "Tile" - | "Glyphs" - | "SpriteImage" - | "SpriteJSON" - | "Image"; - - export interface RequestParameters { - /** - * The URL to be requested. - */ - url: string; - - /** - * Use `'include'` to send cookies with cross-origin requests. - */ - credentials?: "same-origin" | "include" | undefined; - - /** - * The headers to be sent with the request. - */ - headers?: { [header: string]: any } | undefined; - - method?: "GET" | "POST" | "PUT" | undefined; - - collectResourceTiming?: boolean | undefined; - } - - export type TransformRequestFunction = (url: string, resourceType: ResourceType) => RequestParameters; - - export interface PaddingOptions { - top: number; - bottom: number; - left: number; - right: number; - } - - export interface FeatureIdentifier { - id?: string | number | undefined; - source: string; - sourceLayer?: string | undefined; - } - - /** - * BoxZoomHandler - */ - export class BoxZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * ScrollZoomHandler - */ - export class ScrollZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - setZoomRate(zoomRate: number): void; - - setWheelZoomRate(wheelZoomRate: number): void; - } - - /** - * DragPenHandler - */ - export class DragPanHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(options?: DragPanOptions): void; - - disable(): void; - } - - /** - * DragRotateHandler - */ - export class DragRotateHandler { - constructor( - map: mapboxgl.Map, - options?: { bearingSnap?: number | undefined; pitchWithRotate?: boolean | undefined }, - ); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * KeyboardHandler - */ - export class KeyboardHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - - /** - * Returns true if the handler is enabled and has detected the start of a - * zoom/rotate gesture. - * - * @returns {boolean} `true` if the handler is enabled and has detected the - * start of a zoom/rotate gesture. - */ - isActive(): boolean; - - /** - * Disables the "keyboard pan/rotate" interaction, leaving the - * "keyboard zoom" interaction enabled. - * - * @example - * map.keyboard.disableRotation(); - */ - disableRotation(): void; - - /** - * Enables the "keyboard pan/rotate" interaction. - * - * @example - * map.keyboard.enable(); - * map.keyboard.enableRotation(); - */ - enableRotation(): void; - } - - /** - * DoubleClickZoomHandler - */ - export class DoubleClickZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * TouchZoomRotateHandler - */ - export class TouchZoomRotateHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - disableRotation(): void; - - enableRotation(): void; - } - - export class TouchPitchHandler { - constructor(map: mapboxgl.Map); - - enable(options?: InteractiveOptions): void; - - isActive(): boolean; - - isEnabled(): boolean; - - disable(): void; - } - - export interface IControl { - onAdd(map: Map): HTMLElement; - - onRemove(map: Map): void; - - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Control - */ - export class Control extends Evented implements IControl { - onAdd(map: Map): HTMLElement; - onRemove(map: Map): void; - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Navigation - */ - export class NavigationControl extends Control { - constructor(options?: { - showCompass?: boolean | undefined; - showZoom?: boolean | undefined; - visualizePitch?: boolean | undefined; - }); - } - - export class PositionOptions { - enableHighAccuracy?: boolean | undefined; - timeout?: number | undefined; - maximumAge?: number | undefined; - } - - /** - * Geolocate - */ - export class GeolocateControl extends Control { - constructor(options?: { - positionOptions?: PositionOptions | undefined; - fitBoundsOptions?: FitBoundsOptions | undefined; - trackUserLocation?: boolean | undefined; - showAccuracyCircle?: boolean | undefined; - showUserLocation?: boolean | undefined; - showUserHeading?: boolean | undefined; - geolocation?: Geolocation | undefined; - }); - trigger(): boolean; - } - - /** - * Attribution - */ - export class AttributionControl extends Control { - constructor(options?: { compact?: boolean | undefined; customAttribution?: string | string[] | undefined }); - } - - /** - * Scale - */ - export class ScaleControl extends Control { - constructor(options?: { maxWidth?: number | undefined; unit?: string | undefined }); - - setUnit(unit: "imperial" | "metric" | "nautical"): void; - } - - /** - * FullscreenControl - */ - export class FullscreenControl extends Control { - constructor(options?: FullscreenControlOptions | null); - } - - export interface FullscreenControlOptions { - /** - * A compatible DOM element which should be made full screen. - * By default, the map container element will be made full screen. - */ - container?: HTMLElement | null | undefined; - } - - /** - * Popup - */ - export class Popup extends Evented { - constructor(options?: mapboxgl.PopupOptions); - - addTo(map: mapboxgl.Map): this; - - isOpen(): boolean; - - remove(): this; - - getLngLat(): mapboxgl.LngLat; - - /** - * Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior. - * - * @param lnglat The geographical location to set as the popup's anchor. - */ - setLngLat(lnglat: LngLatLike): this; - - /** - * Tracks the popup anchor to the cursor position, on screens with a pointer device (will be hidden on touchscreens). Replaces the setLngLat behavior. - * For most use cases, `closeOnClick` and `closeButton` should also be set to `false` here. - */ - trackPointer(): this; - - /** Returns the `Popup`'s HTML element. */ - getElement(): HTMLElement; - - setText(text: string): this; - - setHTML(html: string): this; - - setDOMContent(htmlNode: Node): this; - - getMaxWidth(): string; - - setMaxWidth(maxWidth: string): this; - - /** - * Adds a CSS class to the popup container element. - * - * @param {string} className Non-empty string with CSS class name to add to popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.addClassName('some-class') - */ - addClassName(className: string): void; - - /** - * Removes a CSS class from the popup container element. - * - * @param {string} className Non-empty string with CSS class name to remove from popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.removeClassName('some-class') - */ - removeClassName(className: string): void; - - /** - * Sets the popup's offset. - * - * @param offset Sets the popup's offset. - * @returns {Popup} `this` - */ - setOffset(offset?: Offset | null): this; - - /** - * Add or remove the given CSS class on the popup container, depending on whether the container currently has that class. - * - * @param {string} className Non-empty string with CSS class name to add/remove - * - * @returns {boolean} if the class was removed return false, if class was added, then return true - * - * @example - * let popup = new mapboxgl.Popup() - * popup.toggleClassName('toggleClass') - */ - toggleClassName(className: string): void; - } - - export interface PopupOptions { - closeButton?: boolean | undefined; - - closeOnClick?: boolean | undefined; - - /** - * @param {boolean} [options.closeOnMove=false] If `true`, the popup will closed when the map moves. - */ - closeOnMove?: boolean | undefined; - - /** - * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the - * first focusable element inside the popup. - */ - focusAfterOpen?: boolean | null | undefined; - - anchor?: Anchor | undefined; - - offset?: Offset | null | undefined; - - className?: string | undefined; - - maxWidth?: string | undefined; - } - - export interface Style { - layers: AnyLayer[]; - sources: Sources; - - bearing?: number | undefined; - center?: number[] | undefined; - fog?: Fog | undefined; - glyphs?: string | undefined; - metadata?: any; - name?: string | undefined; - pitch?: number | undefined; - light?: Light | undefined; - sprite?: string | undefined; - terrain?: TerrainSpecification | undefined; - transition?: Transition | undefined; - version: number; - zoom?: number | undefined; - } - - export interface Transition { - delay?: number | undefined; - duration?: number | undefined; - } - - export interface Light { - anchor?: "map" | "viewport" | undefined; - position?: number[] | undefined; - "position-transition"?: Transition | undefined; - color?: string | undefined; - "color-transition"?: Transition | undefined; - intensity?: number | undefined; - "intensity-transition"?: Transition | undefined; - } - - export interface Fog { - color?: string | Expression | undefined; - "horizon-blend"?: number | Expression | undefined; - range?: number[] | Expression | undefined; - "high-color"?: string | Expression | undefined; - "space-color"?: string | Expression | undefined; - "star-intensity"?: number | Expression | undefined; - } - - export interface Sources { - [sourceName: string]: AnySourceData; - } - - export type PromoteIdSpecification = { [key: string]: string } | string; - - export type AnySourceData = - | GeoJSONSourceRaw - | VideoSourceRaw - | ImageSourceRaw - | CanvasSourceRaw - | VectorSource - | RasterSource - | RasterDemSource - | CustomSourceInterface; - - interface RasterSourceImpl extends RasterSource { - /** - * Reloads the source data and re-renders the map. - */ - reload(): void; - - /** - * Sets the source `tiles` property and re-renders the map. - * - * @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec. - * @returns {RasterTileSource} this - */ - setTiles(tiles: readonly string[]): RasterSourceImpl; - - /** - * Sets the source `url` property and re-renders the map. - * - * @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://`. - * @returns {RasterTileSource} this - */ - setUrl(url: string): RasterSourceImpl; - } - - interface VectorSourceImpl extends VectorSource { - /** - * Reloads the source data and re-renders the map. - */ - reload(): void; - - /** - * Sets the source `tiles` property and re-renders the map. - * - * @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec. - * @returns {VectorTileSource} this - */ - setTiles(tiles: readonly string[]): VectorSourceImpl; - - /** - * Sets the source `url` property and re-renders the map. - * - * @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://`. - * @returns {VectorTileSource} this - */ - setUrl(url: string): VectorSourceImpl; - } - - export type AnySourceImpl = - | GeoJSONSource - | VideoSource - | ImageSource - | CanvasSource - | VectorSourceImpl - | RasterSourceImpl - | RasterDemSource - | CustomSource; - - export interface Source { - type: "vector" | "raster" | "raster-dem" | "geojson" | "image" | "video" | "canvas" | "custom"; - } - - /** - * GeoJSONSource - */ - - export interface GeoJSONSourceRaw extends Source, GeoJSONSourceOptions { - type: "geojson"; - } - - export class GeoJSONSource implements GeoJSONSourceRaw { - type: "geojson"; - - constructor(options?: mapboxgl.GeoJSONSourceOptions); - - setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; - - getClusterExpansionZoom(clusterId: number, callback: (error: any, zoom: number) => void): this; - - getClusterChildren( - clusterId: number, - callback: (error: any, features: Array>) => void, - ): this; - - getClusterLeaves( - cluserId: number, - limit: number, - offset: number, - callback: (error: any, features: Array>) => void, - ): this; - } - - export interface GeoJSONSourceOptions { - data?: - | GeoJSON.Feature - | GeoJSON.FeatureCollection - | GeoJSON.Geometry - | string - | undefined; - - maxzoom?: number | undefined; - - attribution?: string | undefined; - - buffer?: number | undefined; - - tolerance?: number | undefined; - - cluster?: number | boolean | undefined; - - clusterRadius?: number | undefined; - - clusterMaxZoom?: number | undefined; - - /** - * Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`. - */ - clusterMinPoints?: number | undefined; - - clusterProperties?: object | undefined; - - lineMetrics?: boolean | undefined; - - generateId?: boolean | undefined; - - promoteId?: PromoteIdSpecification | undefined; - - filter?: any; - } - - /** - * VideoSource - */ - export interface VideoSourceRaw extends Source, VideoSourceOptions { - type: "video"; - } - - export class VideoSource implements VideoSourceRaw { - type: "video"; - - constructor(options?: mapboxgl.VideoSourceOptions); - - getVideo(): HTMLVideoElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface VideoSourceOptions { - urls?: string[] | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * ImageSource - */ - export interface ImageSourceRaw extends Source, ImageSourceOptions { - type: "image"; - } - - export class ImageSource implements ImageSourceRaw { - type: "image"; - - constructor(options?: mapboxgl.ImageSourceOptions); - - updateImage(options: ImageSourceOptions): this; - - setCoordinates(coordinates: number[][]): this; - } - - export interface ImageSourceOptions { - url?: string | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * CanvasSource - */ - export interface CanvasSourceRaw extends Source, CanvasSourceOptions { - type: "canvas"; - } - - export class CanvasSource implements CanvasSourceRaw { - type: "canvas"; - - coordinates: number[][]; - - canvas: string | HTMLCanvasElement; - - play(): void; - - pause(): void; - - getCanvas(): HTMLCanvasElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface CanvasSourceOptions { - coordinates: number[][]; - - animate?: boolean | undefined; - - canvas: string | HTMLCanvasElement; - } - - export type CameraFunctionSpecification = - | { type: "exponential"; stops: Array<[number, T]> } - | { type: "interval"; stops: Array<[number, T]> }; - - export type ExpressionSpecification = unknown[]; - - export type PropertyValueSpecification = T | CameraFunctionSpecification | ExpressionSpecification; - - export interface TerrainSpecification { - source: string; - exaggeration?: PropertyValueSpecification | undefined; - } - - /** - * @see https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#33-vector_layers - */ - type SourceVectorLayer = { - id: string; - fields?: Record; - description?: string; - minzoom?: number; - maxzoom?: number; - - // Non standard extensions that are valid in a Mapbox context. - source?: string; - source_name?: string; - }; - - interface VectorSource extends Source { - type: "vector"; - format?: "pbf"; - - url?: string | undefined; - id?: string; - name?: string; - - tiles?: string[] | undefined; - bounds?: number[] | undefined; - scheme?: "xyz" | "tms" | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - attribution?: string | undefined; - promoteId?: PromoteIdSpecification | undefined; - - vector_layers?: SourceVectorLayer[]; - } - - interface RasterSource extends Source { - name?: string; - type: "raster"; - id?: string; - format?: "webp" | string; - - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - scheme?: "xyz" | "tms" | undefined; - attribution?: string | undefined; - } - - interface RasterDemSource extends Source { - name?: string; - type: "raster-dem"; - id?: string; - - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - attribution?: string | undefined; - encoding?: "terrarium" | "mapbox" | undefined; - } - - interface CustomSourceInterface { - id: string; - type: "custom"; - dataType: "raster"; - minzoom?: number; - maxzoom?: number; - scheme?: string; - tileSize?: number; - attribution?: string; - bounds?: [number, number, number, number]; - hasTile?: (tileID: { z: number; x: number; y: number }) => boolean; - loadTile: (tileID: { z: number; x: number; y: number }, options: { signal: AbortSignal }) => Promise; - prepareTile?: (tileID: { z: number; x: number; y: number }) => T | undefined; - unloadTile?: (tileID: { z: number; x: number; y: number }) => void; - onAdd?: (map: Map) => void; - onRemove?: (map: Map) => void; - } - - interface CustomSource extends Source { - id: string; - type: "custom"; - scheme: string; - minzoom: number; - maxzoom: number; - tileSize: number; - attribution: string; - - _implementation: CustomSourceInterface; - } - - /** - * LngLat - */ - export class LngLat { - lng: number; - lat: number; - - constructor(lng: number, lat: number); - - /** Return a new LngLat object whose longitude is wrapped to the range (-180, 180). */ - wrap(): mapboxgl.LngLat; - - /** Return a LngLat as an array */ - toArray(): number[]; - - /** Return a LngLat as a string */ - toString(): string; - - /** Returns the approximate distance between a pair of coordinates in meters - * Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159) */ - distanceTo(lngLat: LngLat): number; - - toBounds(radius: number): LngLatBounds; - - static convert(input: LngLatLike): mapboxgl.LngLat; - } - - /** - * LngLatBounds - */ - export class LngLatBounds { - sw: LngLatLike; - ne: LngLatLike; - _sw: LngLat; - _ne: LngLat; - - constructor(boundsLike?: [LngLatLike, LngLatLike] | [number, number, number, number]); - constructor(sw: LngLatLike, ne: LngLatLike); - - setNorthEast(ne: LngLatLike): this; - - setSouthWest(sw: LngLatLike): this; - - /** Check if the point is within the bounding box. */ - contains(lnglat: LngLatLike): boolean; - - /** Extend the bounds to include a given LngLat or LngLatBounds. */ - extend(obj: mapboxgl.LngLatLike | mapboxgl.LngLatBoundsLike): this; - - /** Get the point equidistant from this box's corners */ - getCenter(): mapboxgl.LngLat; - - /** Get southwest corner */ - getSouthWest(): mapboxgl.LngLat; - - /** Get northeast corner */ - getNorthEast(): mapboxgl.LngLat; - - /** Get northwest corner */ - getNorthWest(): mapboxgl.LngLat; - - /** Get southeast corner */ - getSouthEast(): mapboxgl.LngLat; - - /** Get west edge longitude */ - getWest(): number; - - /** Get south edge latitude */ - getSouth(): number; - - /** Get east edge longitude */ - getEast(): number; - - /** Get north edge latitude */ - getNorth(): number; - - /** Returns a LngLatBounds as an array */ - toArray(): number[][]; - - /** Return a LngLatBounds as a string */ - toString(): string; - - /** Returns a boolean */ - isEmpty(): boolean; - - /** Convert an array to a LngLatBounds object, or return an existing LngLatBounds object unchanged. */ - static convert(input: LngLatBoundsLike): mapboxgl.LngLatBounds; - } - - /** - * Point - */ - // Todo: Pull out class to seperate definition for Module "point-geometry" - export class Point { - x: number; - y: number; - - constructor(x: number, y: number); - - clone(): Point; - - add(p: Point): Point; - - sub(p: Point): Point; - - mult(k: number): Point; - - div(k: number): Point; - - rotate(a: number): Point; - - matMult(m: number): Point; - - unit(): Point; - - perp(): Point; - - round(): Point; - - mag(): number; - - equals(p: Point): boolean; - - dist(p: Point): number; - - distSqr(p: Point): number; - - angle(): number; - - angleTo(p: Point): number; - - angleWidth(p: Point): number; - - angleWithSep(x: number, y: number): number; - - static convert(a: PointLike): Point; - } - - /** - * MercatorCoordinate - */ - export class MercatorCoordinate { - /** The x component of the position. */ - x: number; - - /** The y component of the position. */ - y: number; - - /** - * The z component of the position. - * - * @default 0 - */ - z?: number | undefined; - - constructor(x: number, y: number, z?: number); - - /** Returns the altitude in meters of the coordinate. */ - toAltitude(): number; - - /** Returns the LngLat for the coordinate. */ - toLngLat(): LngLat; - - /** - * Returns the distance of 1 meter in MercatorCoordinate units at this latitude. - * - * For coordinates in real world units using meters, this naturally provides the - * scale to transform into MercatorCoordinates. - */ - meterInMercatorCoordinateUnits(): number; - - /** Project a LngLat to a MercatorCoordinate. */ - static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate; - } - - /** - * Marker - */ - export class Marker extends Evented { - constructor(options?: mapboxgl.MarkerOptions); - - constructor(element?: HTMLElement, options?: mapboxgl.MarkerOptions); - - addTo(map: Map): this; - - remove(): this; - - getLngLat(): LngLat; - - setLngLat(lngLat: LngLatLike): this; - - getElement(): HTMLElement; - - setPopup(popup?: Popup): this; - - getPopup(): Popup; - - togglePopup(): this; - - getOffset(): PointLike; - - setOffset(offset: PointLike): this; - - setDraggable(shouldBeDraggable: boolean): this; - - isDraggable(): boolean; - - getRotation(): number; - - setRotation(rotation: number): this; - - getRotationAlignment(): Alignment; - - setRotationAlignment(alignment: Alignment): this; - - getPitchAlignment(): Alignment; - - setPitchAlignment(alignment: Alignment): this; - - getOccludedOpacity(): number; - - setOccludedOpacity(opacity: number): this; - } - - type Alignment = "map" | "viewport" | "auto"; - - /** @see https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker-parameters */ - export interface MarkerOptions { - /** DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker */ - element?: HTMLElement | undefined; - - /** The offset in pixels as a PointLike object to apply relative to the element's center. Negatives indicate left and up. */ - offset?: PointLike | undefined; - - /** A string indicating the part of the Marker that should be positioned closest to the coordinate set via Marker.setLngLat. - * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`. - * The default value os `'center'` - */ - anchor?: Anchor | undefined; - - /** The color to use for the default marker if options.element is not provided. The default is light blue (#3FB1CE). */ - color?: string | undefined; - - /** Space-separated CSS class names to add to marker element. */ - className?: string | undefined; - - /** A boolean indicating whether or not a marker is able to be dragged to a new position on the map. The default value is false */ - draggable?: boolean | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click on the marker for it to be considered a valid click - * (as opposed to a marker drag). The default (0) is to inherit map's clickTolerance. - */ - clickTolerance?: number | null | undefined; - - /** The rotation angle of the marker in degrees, relative to its `rotationAlignment` setting. A positive value will rotate the marker clockwise. - * The default value is 0. - */ - rotation?: number | undefined; - - /** `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates. - * `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations. - * `auto` is equivalent to `viewport`. - * The default value is `auto` - */ - rotationAlignment?: Alignment | undefined; - - /** `map` aligns the `Marker` to the plane of the map. - * `viewport` aligns the `Marker` to the plane of the viewport. - * `auto` automatically matches the value of `rotationAlignment`. - * The default value is `auto`. - */ - pitchAlignment?: Alignment | undefined; - - /** The scale to use for the default marker if options.element is not provided. - * The default scale (1) corresponds to a height of `41px` and a width of `27px`. - */ - scale?: number | undefined; - - /** - * The opacity of a marker that's occluded by 3D terrain. Number between 0 and 1. - */ - occludedOpacity?: number | undefined; - } - - type EventedListener = (object?: Object) => any; - /** - * Evented - */ - export class Evented { - on(type: string, listener: EventedListener): this; - - off(type?: string | any, listener?: EventedListener): this; - - once(type: string, listener: EventedListener): this; - - // https://github.com/mapbox/mapbox-gl-js/issues/6522 - fire(type: string, properties?: { [key: string]: any }): this; - } - - /** - * StyleOptions - */ - export interface StyleOptions { - transition?: boolean | undefined; - } - - export type MapboxGeoJSONFeature = GeoJSON.Feature & { - layer: Layer; - source: string; - sourceLayer: string; - state: { [key: string]: any }; - }; - - export type EventData = { [key: string]: any }; - - export class MapboxEvent { - type: string; - target: Map; - originalEvent: TOrig; - } - - export class MapMouseEvent extends MapboxEvent { - type: - | "mousedown" - | "mouseup" - | "click" - | "dblclick" - | "mousemove" - | "mouseover" - | "mouseenter" - | "mouseleave" - | "mouseout" - | "contextmenu"; - - point: Point; - lngLat: LngLat; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerMouseEvent = MapMouseEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapTouchEvent extends MapboxEvent { - type: "touchstart" | "touchend" | "touchcancel"; - - point: Point; - lngLat: LngLat; - points: Point[]; - lngLats: LngLat[]; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerTouchEvent = MapTouchEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapWheelEvent extends MapboxEvent { - type: "wheel"; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export interface MapBoxZoomEvent extends MapboxEvent { - type: "boxzoomstart" | "boxzoomend" | "boxzoomcancel"; - - boxZoomBounds: LngLatBounds; - } - - export type MapDataEvent = MapSourceDataEvent | MapStyleDataEvent; - - export interface MapStyleDataEvent extends MapboxEvent { - dataType: "style"; - } - - export interface MapSourceDataEvent extends MapboxEvent { - dataType: "source"; - isSourceLoaded: boolean; - source: Source; - sourceId: string; - sourceDataType: "metadata" | "content"; - tile: any; - coord: Coordinate; - } - - export interface Coordinate { - canonical: CanonicalCoordinate; - wrap: number; - key: number; - } - - export interface CanonicalCoordinate { - x: number; - y: number; - z: number; - key: number; - equals(coord: CanonicalCoordinate): boolean; - } - - export interface MapContextEvent extends MapboxEvent { - type: "webglcontextlost" | "webglcontextrestored"; - } - - export class ErrorEvent extends MapboxEvent { - type: "error"; - error: Error; - } - - /** - * FilterOptions - */ - export interface FilterOptions { - /** - * Whether to check if the filter conforms to the Mapbox GL Style Specification. - * Disabling validation is a performance optimization that should only be used - * if you have previously validated the values you will be passing to this function. - */ - validate?: boolean | null | undefined; - } - - /** - * AnimationOptions - */ - export interface AnimationOptions { - /** Number in milliseconds */ - duration?: number | undefined; - /** - * A function taking a time in the range 0..1 and returning a number where 0 is the initial - * state and 1 is the final state. - */ - easing?: ((time: number) => number) | undefined; - /** point, origin of movement relative to map center */ - offset?: PointLike | undefined; - /** When set to false, no animation happens */ - animate?: boolean | undefined; - - /** If `true`, then the animation is considered essential and will not be affected by `prefers-reduced-motion`. - * Otherwise, the transition will happen instantly if the user has enabled the `reduced motion` accesibility feature in their operating system. - */ - essential?: boolean | undefined; - } - - /** - * CameraOptions - */ - export interface CameraOptions { - /** Map center */ - center?: LngLatLike | undefined; - /** Map zoom level */ - zoom?: number | undefined; - /** Map rotation bearing in degrees counter-clockwise from north */ - bearing?: number | undefined; - /** Map angle in degrees at which the camera is looking at the ground */ - pitch?: number | undefined; - /** If zooming, the zoom center (defaults to map center) */ - around?: LngLatLike | undefined; - /** Dimensions in pixels applied on each side of the viewport for shifting the vanishing point. */ - padding?: number | PaddingOptions | undefined; - } - - export interface CameraForBoundsOptions extends CameraOptions { - offset?: PointLike | undefined; - maxZoom?: number | undefined; - } - - // The Mapbox docs say that if the result is defined, it will have zoom, center and bearing set. - // In practice center is always a {lat, lng} object. - export type CameraForBoundsResult = Required> & { - /** Map center */ - center: { lng: number; lat: number }; - }; - - /** - * FlyToOptions - */ - export interface FlyToOptions extends AnimationOptions, CameraOptions { - curve?: number | undefined; - minZoom?: number | undefined; - speed?: number | undefined; - screenSpeed?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * EaseToOptions - */ - export interface EaseToOptions extends AnimationOptions, CameraOptions { - delayEndEvents?: number | undefined; - } - - export interface FitBoundsOptions extends mapboxgl.FlyToOptions { - linear?: boolean | undefined; - offset?: mapboxgl.PointLike | undefined; - maxZoom?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * MapEvent - */ - export type MapEventType = { - error: ErrorEvent; - - load: MapboxEvent; - idle: MapboxEvent; - remove: MapboxEvent; - render: MapboxEvent; - resize: MapboxEvent; - - webglcontextlost: MapContextEvent; - webglcontextrestored: MapContextEvent; - - dataloading: MapDataEvent; - data: MapDataEvent; - tiledataloading: MapDataEvent; - sourcedataloading: MapSourceDataEvent; - styledataloading: MapStyleDataEvent; - sourcedata: MapSourceDataEvent; - styledata: MapStyleDataEvent; - "style.load": MapboxEvent; - "style.import.load": MapboxEvent; - - boxzoomcancel: MapBoxZoomEvent; - boxzoomstart: MapBoxZoomEvent; - boxzoomend: MapBoxZoomEvent; - - touchcancel: MapTouchEvent; - touchmove: MapTouchEvent; - touchend: MapTouchEvent; - touchstart: MapTouchEvent; - - click: MapMouseEvent; - contextmenu: MapMouseEvent; - dblclick: MapMouseEvent; - mousemove: MapMouseEvent; - mouseup: MapMouseEvent; - mousedown: MapMouseEvent; - mouseout: MapMouseEvent; - mouseover: MapMouseEvent; - - movestart: MapboxEvent; - move: MapboxEvent; - moveend: MapboxEvent; - - zoomstart: MapboxEvent; - zoom: MapboxEvent; - zoomend: MapboxEvent; - - rotatestart: MapboxEvent; - rotate: MapboxEvent; - rotateend: MapboxEvent; - - dragstart: MapboxEvent; - drag: MapboxEvent; - dragend: MapboxEvent; - - pitchstart: MapboxEvent; - pitch: MapboxEvent; - pitchend: MapboxEvent; - - wheel: MapWheelEvent; - }; - - export type MapLayerEventType = { - click: MapLayerMouseEvent; - dblclick: MapLayerMouseEvent; - mousedown: MapLayerMouseEvent; - mouseup: MapLayerMouseEvent; - mousemove: MapLayerMouseEvent; - mouseenter: MapLayerMouseEvent; - mouseleave: MapLayerMouseEvent; - mouseover: MapLayerMouseEvent; - mouseout: MapLayerMouseEvent; - contextmenu: MapLayerMouseEvent; - - touchstart: MapLayerTouchEvent; - touchend: MapLayerTouchEvent; - touchcancel: MapLayerTouchEvent; - }; - - export type AnyLayout = - | BackgroundLayout - | FillLayout - | FillExtrusionLayout - | LineLayout - | SymbolLayout - | RasterLayout - | CircleLayout - | HeatmapLayout - | HillshadeLayout - | SkyLayout; - - export type AnyPaint = - | BackgroundPaint - | FillPaint - | FillExtrusionPaint - | LinePaint - | SymbolPaint - | RasterPaint - | CirclePaint - | HeatmapPaint - | HillshadePaint - | SkyPaint; - - interface Layer { - id: string; - type: string; - - metadata?: any; - ref?: string | undefined; - - source?: string | AnySourceData | undefined; - - "source-layer"?: string | undefined; - - minzoom?: number | undefined; - maxzoom?: number | undefined; - - interactive?: boolean | undefined; - - filter?: any[] | undefined; - layout?: AnyLayout | undefined; - paint?: AnyPaint | undefined; - } - - interface BackgroundLayer extends Layer { - type: "background"; - layout?: BackgroundLayout | undefined; - paint?: BackgroundPaint | undefined; - } - - interface CircleLayer extends Layer { - type: "circle"; - layout?: CircleLayout | undefined; - paint?: CirclePaint | undefined; - } - - interface FillExtrusionLayer extends Layer { - type: "fill-extrusion"; - layout?: FillExtrusionLayout | undefined; - paint?: FillExtrusionPaint | undefined; - } - - interface FillLayer extends Layer { - type: "fill"; - layout?: FillLayout | undefined; - paint?: FillPaint | undefined; - } - - interface HeatmapLayer extends Layer { - type: "heatmap"; - layout?: HeatmapLayout | undefined; - paint?: HeatmapPaint | undefined; - } - - interface HillshadeLayer extends Layer { - type: "hillshade"; - layout?: HillshadeLayout | undefined; - paint?: HillshadePaint | undefined; - } - - interface LineLayer extends Layer { - type: "line"; - layout?: LineLayout | undefined; - paint?: LinePaint | undefined; - } - - interface RasterLayer extends Layer { - type: "raster"; - layout?: RasterLayout | undefined; - paint?: RasterPaint | undefined; - } - - interface SymbolLayer extends Layer { - type: "symbol"; - layout?: SymbolLayout | undefined; - paint?: SymbolPaint | undefined; - } - - interface SkyLayer extends Layer { - type: "sky"; - layout?: SkyLayout | undefined; - paint?: SkyPaint | undefined; - } - - export type AnyLayer = - | BackgroundLayer - | CircleLayer - | FillExtrusionLayer - | FillLayer - | HeatmapLayer - | HillshadeLayer - | LineLayer - | RasterLayer - | SymbolLayer - | CustomLayerInterface - | SkyLayer; - - // See https://docs.mapbox.com/mapbox-gl-js/api/#customlayerinterface - export interface CustomLayerInterface { - /** A unique layer id. */ - id: string; - - /* The layer's type. Must be "custom". */ - type: "custom"; - - /* Either "2d" or "3d". Defaults to "2d". */ - renderingMode?: "2d" | "3d" | undefined; - - /** - * Optional method called when the layer has been removed from the Map with Map#removeLayer. - * This gives the layer a chance to clean up gl resources and event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onRemove?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called when the layer has been added to the Map with Map#addLayer. - * This gives the layer a chance to initialize gl resources and register event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onAdd?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called during a render frame to allow a layer to prepare resources - * or render into a texture. - * - * The layer cannot make any assumptions about the current GL state and must bind a framebuffer - * before rendering. - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - prerender?(gl: WebGLRenderingContext, matrix: number[]): void; - - /** - * Called during a render frame allowing the layer to draw into the GL context. - * - * The layer can assume blending and depth state is set to allow the layer to properly blend - * and clip other layers. The layer cannot make any other assumptions about the current GL state. - * - * If the layer needs to render to a texture, it should implement the prerender method to do this - * and only use the render method for drawing directly into the main framebuffer. - * - * The blend function is set to gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA). This expects - * colors to be provided in premultiplied alpha form where the r, g and b values are already - * multiplied by the a value. If you are unable to provide colors in premultiplied form you may - * want to change the blend function to - * gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA). - * - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - render(gl: WebGLRenderingContext, matrix: number[]): void; - } - - export interface StyleFunction { - stops?: any[][] | undefined; - property?: string | undefined; - base?: number | undefined; - type?: "identity" | "exponential" | "interval" | "categorical" | undefined; - default?: any; - colorSpace?: "rgb" | "lab" | "hcl" | undefined; - } - - type Visibility = "visible" | "none"; - - export interface Layout { - visibility?: Visibility | undefined; - } - - export interface BackgroundLayout extends Layout {} - - export interface BackgroundPaint { - "background-color"?: string | Expression | undefined; - "background-color-transition"?: Transition | undefined; - "background-pattern"?: string | undefined; - "background-pattern-transition"?: Transition | undefined; - "background-opacity"?: number | Expression | undefined; - "background-opacity-transition"?: Transition | undefined; - "background-emissive-strength"?: number | Expression | undefined; - } - - export interface FillLayout extends Layout { - "fill-sort-key"?: number | Expression | undefined; - } - - export interface FillPaint { - "fill-antialias"?: boolean | Expression | undefined; - "fill-opacity"?: number | StyleFunction | Expression | undefined; - "fill-opacity-transition"?: Transition | undefined; - "fill-color"?: string | StyleFunction | Expression | undefined; - "fill-color-transition"?: Transition | undefined; - "fill-outline-color"?: string | StyleFunction | Expression | undefined; - "fill-outline-color-transition"?: Transition | undefined; - "fill-translate"?: number[] | undefined; - "fill-translate-transition"?: Transition | undefined; - "fill-translate-anchor"?: "map" | "viewport" | undefined; - "fill-pattern"?: string | Expression | undefined; - "fill-pattern-transition"?: Transition | undefined; - "fill-emissive-strength"?: number | Expression | undefined; - "fill-extrusion-ambient-occlusion-ground-attenuation"?: number | Expression | undefined; - "fill-extrusion-ambient-occlusion-ground-radius"?: number | Expression | undefined; - "fill-extrusion-ambient-occlusion-wall-radius"?: number | Expression | undefined; - "fill-extrusion-flood-light-color"?: string | StyleFunction | Expression | undefined; - "fill-extrusion-flood-light-ground-attenuation"?: number | Expression | undefined; - "fill-extrusion-flood-light-ground-radius"?: number | Expression | undefined; - "fill-extrusion-flood-light-intensity"?: number | Expression | undefined; - "fill-extrusion-flood-light-wall-radius"?: number | Expression | undefined; - "fill-extrusion-vertical-scale"?: number | Expression | undefined; - } - - export interface FillExtrusionLayout extends Layout {} - - export interface FillExtrusionPaint { - "fill-extrusion-opacity"?: number | Expression | undefined; - "fill-extrusion-opacity-transition"?: Transition | undefined; - "fill-extrusion-color"?: string | StyleFunction | Expression | undefined; - "fill-extrusion-color-transition"?: Transition | undefined; - "fill-extrusion-translate"?: number[] | Expression | undefined; - "fill-extrusion-translate-transition"?: Transition | undefined; - "fill-extrusion-translate-anchor"?: "map" | "viewport" | undefined; - "fill-extrusion-pattern"?: string | Expression | undefined; - "fill-extrusion-pattern-transition"?: Transition | undefined; - "fill-extrusion-height"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-height-transition"?: Transition | undefined; - "fill-extrusion-base"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-base-transition"?: Transition | undefined; - "fill-extrusion-vertical-gradient"?: boolean | undefined; - } - - export interface LineLayout extends Layout { - "line-cap"?: "butt" | "round" | "square" | Expression | undefined; - "line-join"?: "bevel" | "round" | "miter" | Expression | undefined; - "line-miter-limit"?: number | Expression | undefined; - "line-round-limit"?: number | Expression | undefined; - "line-sort-key"?: number | Expression | undefined; - } - - export interface LinePaint { - "line-opacity"?: number | StyleFunction | Expression | undefined; - "line-opacity-transition"?: Transition | undefined; - "line-color"?: string | StyleFunction | Expression | undefined; - "line-color-transition"?: Transition | undefined; - "line-translate"?: number[] | Expression | undefined; - "line-translate-transition"?: Transition | undefined; - "line-translate-anchor"?: "map" | "viewport" | undefined; - "line-width"?: number | StyleFunction | Expression | undefined; - "line-width-transition"?: Transition | undefined; - "line-gap-width"?: number | StyleFunction | Expression | undefined; - "line-gap-width-transition"?: Transition | undefined; - "line-offset"?: number | StyleFunction | Expression | undefined; - "line-offset-transition"?: Transition | undefined; - "line-blur"?: number | StyleFunction | Expression | undefined; - "line-blur-transition"?: Transition | undefined; - "line-dasharray"?: number[] | Expression | undefined; - "line-dasharray-transition"?: Transition | undefined; - "line-pattern"?: string | Expression | undefined; - "line-pattern-transition"?: Transition | undefined; - "line-gradient"?: Expression | undefined; - "line-emissive-strength"?: number | Expression | undefined; - } - - export interface SymbolLayout extends Layout { - "symbol-placement"?: "point" | "line" | "line-center" | undefined; - "symbol-spacing"?: number | Expression | undefined; - "symbol-avoid-edges"?: boolean | undefined; - "symbol-z-order"?: "viewport-y" | "source" | undefined; - "icon-allow-overlap"?: boolean | StyleFunction | Expression | undefined; - "icon-ignore-placement"?: boolean | Expression | undefined; - "icon-optional"?: boolean | undefined; - "icon-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "icon-size"?: number | StyleFunction | Expression | undefined; - "icon-text-fit"?: "none" | "both" | "width" | "height" | undefined; - "icon-text-fit-padding"?: number[] | Expression | undefined; - "icon-image"?: string | StyleFunction | Expression | undefined; - "icon-rotate"?: number | StyleFunction | Expression | undefined; - "icon-padding"?: number | Expression | undefined; - "icon-keep-upright"?: boolean | undefined; - "icon-offset"?: number[] | StyleFunction | Expression | undefined; - "icon-anchor"?: Anchor | StyleFunction | Expression | undefined; - "icon-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-field"?: string | StyleFunction | Expression | undefined; - "text-font"?: string[] | Expression | undefined; - "text-size"?: number | StyleFunction | Expression | undefined; - "text-max-width"?: number | StyleFunction | Expression | undefined; - "text-line-height"?: number | Expression | undefined; - "text-letter-spacing"?: number | Expression | undefined; - "text-justify"?: "auto" | "left" | "center" | "right" | Expression | undefined; - "text-anchor"?: Anchor | StyleFunction | Expression | undefined; - "text-max-angle"?: number | Expression | undefined; - "text-rotate"?: number | StyleFunction | Expression | undefined; - "text-padding"?: number | Expression | undefined; - "text-keep-upright"?: boolean | undefined; - "text-transform"?: "none" | "uppercase" | "lowercase" | StyleFunction | Expression | undefined; - "text-offset"?: number[] | Expression | undefined; - "text-allow-overlap"?: boolean | undefined; - "text-ignore-placement"?: boolean | undefined; - "text-optional"?: boolean | undefined; - "text-radial-offset"?: number | Expression | undefined; - "text-variable-anchor"?: Anchor[] | undefined; - "text-writing-mode"?: Array<"horizontal" | "vertical"> | undefined; - "symbol-sort-key"?: number | Expression | undefined; - } - - export interface SymbolPaint { - "icon-opacity"?: number | StyleFunction | Expression | undefined; - "icon-opacity-transition"?: Transition | undefined; - "icon-color"?: string | StyleFunction | Expression | undefined; - "icon-color-transition"?: Transition | undefined; - "icon-halo-color"?: string | StyleFunction | Expression | undefined; - "icon-halo-color-transition"?: Transition | undefined; - "icon-halo-width"?: number | StyleFunction | Expression | undefined; - "icon-halo-width-transition"?: Transition | undefined; - "icon-halo-blur"?: number | StyleFunction | Expression | undefined; - "icon-halo-blur-transition"?: Transition | undefined; - "icon-translate"?: number[] | Expression | undefined; - "icon-translate-transition"?: Transition | undefined; - "icon-translate-anchor"?: "map" | "viewport" | undefined; - "icon-emissive-strength"?: number | StyleFunction | Expression | undefined; - "icon-image-cross-fade"?: number | StyleFunction | Expression | undefined; - "text-opacity"?: number | StyleFunction | Expression | undefined; - "text-opacity-transition"?: Transition | undefined; - "text-color"?: string | StyleFunction | Expression | undefined; - "text-color-transition"?: Transition | undefined; - "text-halo-color"?: string | StyleFunction | Expression | undefined; - "text-halo-color-transition"?: Transition | undefined; - "text-halo-width"?: number | StyleFunction | Expression | undefined; - "text-halo-width-transition"?: Transition | undefined; - "text-halo-blur"?: number | StyleFunction | Expression | undefined; - "text-halo-blur-transition"?: Transition | undefined; - "text-translate"?: number[] | Expression | undefined; - "text-translate-transition"?: Transition | undefined; - "text-translate-anchor"?: "map" | "viewport" | undefined; - "text-emissive-strength"?: number | StyleFunction | Expression | undefined; - } - - export interface RasterLayout extends Layout {} - - export interface RasterPaint { - "raster-opacity"?: number | Expression | undefined; - "raster-opacity-transition"?: Transition | undefined; - "raster-hue-rotate"?: number | Expression | undefined; - "raster-hue-rotate-transition"?: Transition | undefined; - "raster-brightness-min"?: number | Expression | undefined; - "raster-brightness-min-transition"?: Transition | undefined; - "raster-brightness-max"?: number | Expression | undefined; - "raster-brightness-max-transition"?: Transition | undefined; - "raster-saturation"?: number | Expression | undefined; - "raster-saturation-transition"?: Transition | undefined; - "raster-contrast"?: number | Expression | undefined; - "raster-contrast-transition"?: Transition | undefined; - "raster-fade-duration"?: number | Expression | undefined; - "raster-resampling"?: "linear" | "nearest" | undefined; - "raster-color"?: string | Expression | undefined; - "raster-color-mix"?: [number, number, number, number] | Expression | undefined; - "raster-color-range"?: [number, number] | Expression | undefined; - } - - export interface CircleLayout extends Layout { - "circle-sort-key"?: number | Expression | undefined; - } - - export interface CirclePaint { - "circle-radius"?: number | StyleFunction | Expression | undefined; - "circle-radius-transition"?: Transition | undefined; - "circle-color"?: string | StyleFunction | Expression | undefined; - "circle-color-transition"?: Transition | undefined; - "circle-blur"?: number | StyleFunction | Expression | undefined; - "circle-blur-transition"?: Transition | undefined; - "circle-opacity"?: number | StyleFunction | Expression | undefined; - "circle-opacity-transition"?: Transition | undefined; - "circle-translate"?: number[] | Expression | undefined; - "circle-translate-transition"?: Transition | undefined; - "circle-translate-anchor"?: "map" | "viewport" | undefined; - "circle-pitch-scale"?: "map" | "viewport" | undefined; - "circle-pitch-alignment"?: "map" | "viewport" | undefined; - "circle-stroke-width"?: number | StyleFunction | Expression | undefined; - "circle-stroke-width-transition"?: Transition | undefined; - "circle-stroke-color"?: string | StyleFunction | Expression | undefined; - "circle-stroke-color-transition"?: Transition | undefined; - "circle-stroke-opacity"?: number | StyleFunction | Expression | undefined; - "circle-stroke-opacity-transition"?: Transition | undefined; - "circle-emissive-strength"?: number | StyleFunction | Expression | undefined; - } - - export interface HeatmapLayout extends Layout {} - - export interface HeatmapPaint { - "heatmap-radius"?: number | StyleFunction | Expression | undefined; - "heatmap-radius-transition"?: Transition | undefined; - "heatmap-weight"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity-transition"?: Transition | undefined; - "heatmap-color"?: string | StyleFunction | Expression | undefined; - "heatmap-opacity"?: number | StyleFunction | Expression | undefined; - "heatmap-opacity-transition"?: Transition | undefined; - } - - export interface HillshadeLayout extends Layout {} - - export interface HillshadePaint { - "hillshade-illumination-direction"?: number | Expression | undefined; - "hillshade-illumination-anchor"?: "map" | "viewport" | undefined; - "hillshade-exaggeration"?: number | Expression | undefined; - "hillshade-exaggeration-transition"?: Transition | undefined; - "hillshade-shadow-color"?: string | Expression | undefined; - "hillshade-shadow-color-transition"?: Transition | undefined; - "hillshade-highlight-color"?: string | Expression | undefined; - "hillshade-highlight-color-transition"?: Transition | undefined; - "hillshade-accent-color"?: string | Expression | undefined; - "hillshade-accent-color-transition"?: Transition | undefined; - } - - export interface SkyLayout extends Layout {} - - export interface SkyPaint { - "sky-atmosphere-color"?: string | Expression | undefined; - "sky-atmosphere-halo-color"?: string | Expression | undefined; - "sky-atmosphere-sun"?: number[] | Expression | undefined; - "sky-atmosphere-sun-intensity"?: number | Expression | undefined; - "sky-gradient"?: string | Expression | undefined; - "sky-gradient-center"?: number[] | Expression | undefined; - "sky-gradient-radius"?: number | Expression | undefined; - "sky-opacity"?: number | Expression | undefined; - "sky-type"?: "gradient" | "atmosphere" | undefined; - } - - export type ElevationQueryOptions = { - exaggerated: boolean; - }; - - export interface Projection { - name: - | "albers" - | "equalEarth" - | "equirectangular" - | "lambertConformalConic" - | "mercator" - | "naturalEarth" - | "winkelTripel" - | "globe"; - center?: [number, number]; - parallels?: [number, number]; - } -} diff --git a/types/mapbox-gl/mapbox-gl-tests.ts b/types/mapbox-gl/mapbox-gl-tests.ts deleted file mode 100644 index ae637a8abb234e..00000000000000 --- a/types/mapbox-gl/mapbox-gl-tests.ts +++ /dev/null @@ -1,2100 +0,0 @@ -import { IControl } from "mapbox-gl"; -import mapboxgl = require("mapbox-gl"); - -// These examples adapted from Mapbox's examples (https://www.mapbox.com/mapbox-gl-js/examples) - -/** - * Set API Access Token - */ -mapboxgl.accessToken = "foo"; - -/** - * Set Base API URL - */ -mapboxgl.baseApiUrl = "https://example.com"; - -/** - * Set amount of workers - */ -mapboxgl.workerCount = 3; - -/** - * Set max amount of parallel images requests - */ -mapboxgl.maxParallelImageRequests = 10; - -/** - * Clears browser storage used by this library - */ -mapboxgl.clearStorage(() => {}); - -/** - * Get RTL Text Plugin Status - */ -expectType(mapboxgl.getRTLTextPluginStatus()); - -/** - * Set RTL Text Plugin - */ -// $ExpectType void -mapboxgl.setRTLTextPlugin("https://github.com", e => {}, false); - -// $ExpectType void -mapboxgl.prewarm(); - -// $ExpectType void -mapboxgl.clearPrewarmedResources(); - -/** - * Display a Map - */ -let map = new mapboxgl.Map({ - container: "map", - style: "mapbox://styles/mapbox/streets-v8", - center: [-50, 50], - zoom: 10, - minZoom: 1, - maxZoom: 2, - minPitch: 0, - maxPitch: 60, - interactive: true, - attributionControl: true, - customAttribution: "© YourCo", - performanceMetricsCollection: false, - respectPrefersReducedMotion: true, - config: { - basemap: { - lightPreset: "night", - }, - }, - bearingSnap: 7, - scrollZoom: true, - maxBounds: [ - [-100, -90], - [100, 90], - ], - boxZoom: true, - dragRotate: false, - dragPan: true, - antialias: true, - accessToken: "some-token", - locale: { - "FullscreenControl.Enter": "Розгорнути на весь екран", - "FullscreenControl.Exit": "Вийти з повоноеранного режиму", - }, -}); - -/** - * Initialize map with bounds - */ -expectType({ - container: "map", - bounds: new mapboxgl.LngLatBounds([-100, -90, 100, 90]), - fitBoundsOptions: { - padding: 0, - offset: new mapboxgl.Point(0, 0), - linear: true, - maxZoom: 22, - easing: time => time, - }, -}); -expectType({ - container: "map", - bounds: [ - [-100, -90], - [100, 90], - ], - fitBoundsOptions: { - offset: [0, 0], - }, -}); -expectType({ - container: "map", - bounds: [-100, -90, 100, 90], -}); - -expectType({ - container: "map", - touchPitch: true, -}); - -/** - * Check `touchPitch`, `touchZoomRotate`, `scrollZoom` to accept Object - */ -expectType({ - container: "map", - touchPitch: { around: "center" }, - touchZoomRotate: { around: "center" }, - scrollZoom: { around: "center" }, -}); - -/** - * Check `dragPan` to accept Object - */ -expectType({ - container: "map", - dragPan: { - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, - }, -}); - -/** - * Check `cooperativeGestures` - */ -expectType({ - container: "map", - cooperativeGestures: true, -}); - -/** - * Create and style marker clusters - */ -map.on("load", function() { - // Add a new source from our GeoJSON data and set the - // 'cluster' option to true. - map.addSource("data", { - type: "geojson", - data: "/data.geojson", - cluster: true, - clusterMaxZoom: 14, // Max zoom to cluster points on - clusterMinPoints: 8, - clusterRadius: 50, // Radius of each cluster when clustering points (defaults to 50) - clusterProperties: { sum: ["+", ["get", "property"]] }, - filter: "something", - }); - - map.addLayer({ - id: "layer", - type: "symbol", - source: "data", - layout: { - "icon-image": "marker-15", - "text-field": ["get", "property"], - "text-max-width": { - stops: [ - [10, 2], - [12, 5], - ], - }, - }, - }); - - var layers: Array<[number, string]> = [ - [150, "#f28cb1"], - [20, "#f1f075"], - [0, "#51bbd6"], - ]; - - layers.forEach(function(layer, i) { - map.addLayer({ - id: "cluster-" + i, - type: "circle", - source: "data", - paint: { - "circle-color": layer[1], - "circle-radius": 18, - }, - filter: i == 0 - ? [">=", "point_count", layer[0]] - : ["all", [">=", "point_count", layer[0]], ["<", "point_count", layers[i - 1][0]]], - }); - }); - - // Add a layer for the clusters' count labels - map.addLayer({ - id: "cluster-count", - type: "symbol", - source: "data", - layout: { - "text-field": "{point_count}", - "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"], - "text-size": 12, - }, - }); - - /** - * Add a GeoJSON line - */ - map.addSource("route", { - type: "geojson", - data: { - type: "Feature", - properties: {}, - geometry: { - type: "LineString", - coordinates: [ - [-122.48369693756104, 37.83381888486939], - [-122.48348236083984, 37.83317489144141], - [-122.48339653015138, 37.83270036637107], - [-122.48356819152832, 37.832056363179625], - [-122.48404026031496, 37.83114119107971], - [-122.48404026031496, 37.83049717427869], - [-122.48348236083984, 37.829920943955045], - [-122.48356819152832, 37.82954808664175], - [-122.48507022857666, 37.82944639795659], - [-122.48610019683838, 37.82880236636284], - [-122.48695850372314, 37.82931081282506], - [-122.48700141906738, 37.83080223556934], - [-122.48751640319824, 37.83168351665737], - [-122.48803138732912, 37.832158048267786], - [-122.48888969421387, 37.83297152392784], - [-122.48987674713133, 37.83263257682617], - [-122.49043464660643, 37.832937629287755], - [-122.49125003814696, 37.832429207817725], - [-122.49163627624512, 37.832564787218985], - [-122.49223709106445, 37.83337825839438], - [-122.49378204345702, 37.83368330777276], - ], - }, - }, - promoteId: { original: "COUNTY" }, - }); - - map.addLayer({ - id: "route", - type: "line", - source: "route", - layout: { - "line-join": "round", - "line-cap": "round", - }, - paint: { - "line-color": "#888", - "line-width": 8, - "line-dasharray": ["step", ["zoom"], ["literal", [1, 0]], 15, ["literal", [1.75, 1]]], - }, - }); - - // Add a vector source - map.addSource("vector-source", { - type: "vector", - promoteId: { original: "COUNTY" }, - }); - - // Add a custom layer - map.addLayer({ - id: "custom", - type: "custom", - renderingMode: "3d", - onRemove: function(map, gl) { - map; // $ExpectType Map - gl; // $ExpectType WebGLRenderingContext - }, - render: function(gl, matrix) { - gl; // $ExpectType WebGLRenderingContext - matrix; // $ExpectType number[] - }, - }); -}); - -// -// setTerrain -// - -// $ExpectType Map -map.setTerrain(); -// $ExpectType Map -map.setTerrain(null); -// $ExpectType Map -map.setTerrain(undefined); -// $ExpectType Map -map.setTerrain({ - source: "something", - exaggeration: 10, -}); - -// -// getFreeCameraOptions -// - -// $ExpectType FreeCameraOptions -map.getFreeCameraOptions(); - -// -// setFreeCameraOptions -// - -// $ExpectType Map -map.setFreeCameraOptions(new mapboxgl.FreeCameraOptions()); - -// FlyTo -map.flyTo({ - center: [0, 0], - zoom: 10, - speed: 0.5, - curve: 1, - screenSpeed: 1, - easing: function(t: number) { - return t; - }, - maxDuration: 1, -}); - -// RotateTo -map.rotateTo(45, { - duration: 2000, - animate: true, - easing: (t) => t, - center: [-122.3085, 47.5505], - zoom: 10, - pitch: 60, -}); - -// QueryRenderedFeatures -const features = map.queryRenderedFeatures([0, 0], { layers: ["custom"], validate: false }); -features; // $ExpectType MapboxGeoJSONFeature[] - -// querySourceFeatures -const features2 = map.querySourceFeatures("some_source", { - sourceLayer: "source_layer", - filter: ["all"], - validate: null, -}); -features2; // $ExpectType MapboxGeoJSONFeature[] - -/** - * GeoJSONSource - */ -var geoJSONSourceObj = new mapboxgl.GeoJSONSource({ - data: { - type: "FeatureCollection", - features: [ - { - type: "Feature", - properties: null, - geometry: { - type: "Point", - coordinates: [-50, 0], - }, - }, - ], - }, -}); -map.addSource("some id", geoJSONSourceObj); // add -map.removeSource("some id"); // remove - -/** - * ImageSource - */ -var imageSourceObj = new mapboxgl.ImageSource({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", imageSourceObj); // add -map.removeSource("some id"); // remove - -imageSourceObj.updateImage({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); - -imageSourceObj.setCoordinates([ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], -]); - -/** - * Video Source - */ -var videoSourceObj = new mapboxgl.VideoSource({ - urls: ["/blah.mp4", "/blah.webm"], - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", videoSourceObj); // add -map.removeSource("some id"); // remove - -/** - * Raster Source - */ -const rasterSource = map.getSource("tile-source") as mapboxgl.RasterSourceImpl; -// $ExpectType void -rasterSource.reload(); -// $ExpectType RasterSourceImpl -rasterSource.setTiles(["a", "b"]); -// $ExpectType RasterSourceImpl -rasterSource.setUrl("https://github.com"); - -/** - * Vector Source - */ -const vectorSource = map.getSource("tile-source") as mapboxgl.VectorSourceImpl; -// $ExpectType void -vectorSource.reload(); -// $ExpectType VectorSourceImpl -vectorSource.setTiles(["a", "b"]); -// $ExpectType VectorSourceImpl -vectorSource.setUrl("https://github.com"); - -/** - * Add Raster Source /// made URL optional to allow only tiles. - */ -map.addSource("radar", { - type: "raster", - tiles: [ - "https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WmsServer?bbox={bbox-epsg-3857}&service=WMS&request=GetMap&version=1.3.0&layers=1&styles=&format=image/png&transparent=true&height=256&width=256&crs=EPSG:3857", - ], - tileSize: 256, -}); - -map.addLayer({ - id: "radar", - type: "raster", - source: "radar", - paint: {}, -}); - -/** - * Manipulate feature state - */ -let featureIdentifier = { - id: 1337, - source: "source-id", - sourceLayer: "liam-was-here", -}; -expectType(featureIdentifier); -map.setFeatureState(featureIdentifier, { someState: true, someOtherState: 123 }); -map.getFeatureState(featureIdentifier); -map.removeFeatureState(featureIdentifier, "someState"); -map.removeFeatureState(featureIdentifier); - -/** - * Popup - */ -const popupOptions: mapboxgl.PopupOptions = { - closeOnClick: false, - closeOnMove: true, - closeButton: true, - focusAfterOpen: true, - anchor: "top-right", - offset: { - top: [0, 0] as [number, number], - bottom: [25, -50] as [number, number], - }, - className: "custom-class", - maxWidth: "400px", -}; - -const popup = new mapboxgl.Popup(popupOptions) - .setLngLat([-50, 50]) - .trackPointer() - .setHTML("

Hello World!

") - .setMaxWidth("none") - .addTo(map); -popup.getMaxWidth(); -popup.getElement(); // $ExpectType HTMLElement -popup.addClassName("class1"); -popup.removeClassName("class2"); -popup.toggleClassName("class3"); -// $ExpectType Popup -popup.setOffset([10, 20]); - -/** - * Add terrain - */ -const terrainStyle: mapboxgl.Style = { - version: 8, - name: "terrain", - sources: { - dem: { - type: "raster-dem", - url: "mapbox://mapbox.mapbox-terrain-dem-v1", - }, - }, - layers: [], - terrain: { - source: "dem", - exaggeration: 1.5, - }, -}; - -/** - * Add an image - */ -var mapStyle: mapboxgl.Style = { - version: 8, - name: "Dark", - sources: { - mapbox: { - type: "vector", - url: "mapbox://mapbox.mapbox-streets-v6", - }, - overlay: { - type: "image", - url: "/mapbox-gl-js/assets/radar.gif", - coordinates: [ - [-50, 40], - [0, 40], - [0, 0], - [-50, 0], - ], - }, - }, - sprite: "mapbox://sprites/mapbox/dark-v8", - glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", - layers: [ - { - id: "background", - type: "background", - paint: { "background-color": "#111" }, - }, - { - id: "water", - source: "mapbox", - "source-layer": "water", - type: "fill", - paint: { "fill-color": "#2c2c2c" }, - }, - { - id: "boundaries", - source: "mapbox", - "source-layer": "admin", - type: "line", - paint: { "line-color": "#797979", "line-dasharray": [2, 2, 6, 2] }, - filter: ["all", ["==", "maritime", 0]], - }, - { - id: "overlay", - source: "overlay", - type: "raster", - paint: { "raster-opacity": 0.85 }, - }, - { - id: "cities", - source: "mapbox", - "source-layer": "place_label", - type: "symbol", - layout: { - "text-field": "{name_en}", - "text-font": ["DIN Offc Pro Bold", "Arial Unicode MS Bold"], - "text-size": { - stops: [ - [4, 9], - [6, 12], - ], - }, - }, - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - { - id: "states", - source: "mapbox", - "source-layer": "state_label", - type: "symbol", - layout: { - "text-transform": "uppercase", - "text-field": "{name_en}", - "text-font": [ - "step", - ["zoom"], - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - 8, - [ - "step", - ["get", "symbolrank"], - ["literal", ["DIN Offc Pro Medium", "Arial Unicode MS Regular"]], - 11, - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - ], - ], - "text-justify": [ - "step", - ["zoom"], - [ - "match", - ["get", "text_anchor"], - ["bottom", "top"], - "center", - ["left", "bottom-left", "top-left"], - "left", - ["right", "bottom-right", "top-right"], - "right", - "center", - ], - 8, - "center", - ], - "text-letter-spacing": 0.15, - "text-max-width": 7, - "text-size": { - stops: [ - [4, 10], - [6, 14], - ], - }, - }, - filter: [">=", "area", 80000], - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - ], -}; - -/** - * Add video - */ -var videoStyle: mapboxgl.Style = { - version: 8, - sources: { - satellite: { - type: "raster", - url: "mapbox://mapbox.satellite", - tileSize: 256, - }, - video: { - type: "video", - urls: ["drone.mp4", "drone.webm"], - coordinates: [ - [-122.51596391201019, 37.56238816766053], - [-122.51467645168304, 37.56410183312965], - [-122.51309394836426, 37.563391708549425], - [-122.51423120498657, 37.56161849366671], - ], - }, - }, - layers: [ - { - id: "background", - type: "background", - paint: { - "background-color": "rgb(4,7,14)", - }, - }, - { - id: "satellite", - type: "raster", - source: "satellite", - }, - { - id: "video", - type: "raster", - source: "video", - }, - ], -}; - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: mapStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: videoStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - hash: "customHash", -}); - -const syncOnce: mapboxgl.Map = map.once("load", () => {}); -const asyncOnce: Promise = map.once("load"); - -/** - * Marker - */ -let marker = new mapboxgl.Marker(undefined, { - className: "test", - element: undefined, - offset: [10, 0], - anchor: "bottom-right", - color: "green", - draggable: false, - clickTolerance: 10, - rotation: 15, - rotationAlignment: "map", - pitchAlignment: "viewport", - scale: 5.5, - occludedOpacity: 0.5, -}) - .setLngLat([-50, 50]) - .setPitchAlignment("map") - .setRotation(100) - .setRotationAlignment("viewport") - .addTo(map); - -// $ExpectType Alignment -marker.getPitchAlignment(); - -// $ExpectType number -marker.getRotation(); - -// $ExpectType Alignment -marker.getRotationAlignment(); - -// $ExpectType number -marker.getOccludedOpacity(); - -// $ExpectType Marker -marker.setOccludedOpacity(1); - -marker.remove(); - -/* - * LngLatBounds - */ -let bool: boolean; -let bounds = new mapboxgl.LngLatBounds(); -bool = bounds.isEmpty(); -expectType(bounds.contains([37, 50])); - -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLat(45, 30)); -// $ExpectType LngLatBounds -bounds.extend({ lng: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend({ lon: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend([45, 30]); -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLatBounds()); -// $ExpectType LngLatBounds -bounds.extend([ - [45, 30], - [60, 60], -]); -// $ExpectType LngLatBounds -bounds.extend([45, 30, 60, 60]); - -// controls -// $ExpectType IControl -new mapboxgl.Control() as IControl; -// $ExpectType IControl -new mapboxgl.AttributionControl() as IControl; - -/* - * GeolocateControl - */ -const geolocateControl = new mapboxgl.GeolocateControl({ showAccuracyCircle: true }); - -/* - * AttributionControl - */ -let attributionControl = new mapboxgl.AttributionControl({ compact: false, customAttribution: "© YourCo" }); -attributionControl.on("click", () => {}); - -/* - * FullscreenControl - */ -new mapboxgl.FullscreenControl(); -new mapboxgl.FullscreenControl(null); -new mapboxgl.FullscreenControl({}); -new mapboxgl.FullscreenControl({ container: document.querySelector("body") }); - -// $ExpectType boolean -map.hasControl(attributionControl); - -declare var lnglat: mapboxgl.LngLat; -declare var lnglatlike: mapboxgl.LngLatLike; -declare var lnglatboundslike: mapboxgl.LngLatBoundsLike; -declare var mercatorcoordinate: mapboxgl.MercatorCoordinate; -declare var pointlike: mapboxgl.PointLike; - -function expectType(value: T) { - return value; -} - -// prettier-ignore -interface EitherType { - (a: A): A; - (a: A, b: B): A | B; - (a: A, b: B, c: C): A | B | C; - (a: A, b: B, c: C, d: D): A | B | C | D; - (a: A, b: B, c: C, d: D, e: E): A | B | C | D | E; - (a: A, b: B, c: C, d: D, e: E, f: F): A | B | C | D | E | F; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G): A | B | C | D | E | F | G; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): A | B | C | D | E | F | G | H; - ( - a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - ): A | B | C | D | E | F | G | H | I; - ( - a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - j: J, - ): A | B | C | D | E | F | G | H | I | J; - /* Add more as needed */ -} - -/** - * Takes a variable amount of arguments and returns a new - * type that is a union of all the provided argument types. Useful to test properties - * that accept multiple types - */ -const eitherType: EitherType = () => { - /* let the compiler handle things */ -}; - -/* - * LngLatLike - */ - -expectType(new mapboxgl.LngLat(0, 0)); -expectType([0, 0]); -expectType({ lng: 0, lat: 0 }); -expectType({ lon: 0, lat: 0 }); - -/* - * LngLat - */ - -new mapboxgl.LngLat(0, 0); -expectType(mapboxgl.LngLat.convert(lnglatlike)); -expectType(new mapboxgl.LngLat(0, 0).distanceTo(new mapboxgl.LngLat(0, 0))); - -/* - * LngLatBoundsLike - */ - -expectType([lnglatlike, lnglatlike]); -expectType([0, 0, 1, 1]); -expectType(new mapboxgl.LngLatBounds()); - -/* - * LngLatBounds - */ - -new mapboxgl.LngLatBounds(); -new mapboxgl.LngLatBounds([0, 0, 1, 1]); -new mapboxgl.LngLatBounds([lnglatlike, lnglatlike]); -new mapboxgl.LngLatBounds(lnglat, lnglat); -new mapboxgl.LngLatBounds(lnglatlike, lnglatlike); -expectType(mapboxgl.LngLatBounds.convert(lnglatboundslike)); - -/* - * PointLike - */ - -expectType(new mapboxgl.Point(0, 0)); -expectType([0, 0]); - -/* - * Point - */ - -new mapboxgl.Point(0, 0); -expectType(mapboxgl.Point.convert(pointlike)); - -/* - * MercatorCoordinate - */ - -new mapboxgl.MercatorCoordinate(0, 0); -new mapboxgl.MercatorCoordinate(0, 0, 0); -mercatorcoordinate.toAltitude(); // $ExpectType number -mercatorcoordinate.toLngLat(); // $ExpectType LngLat -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike); // $ExpectType MercatorCoordinate -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike, 0); // $ExpectType MercatorCoordinate -mercatorcoordinate.meterInMercatorCoordinateUnits(); // $ExpectType number - -/* - * TransformRequestFunction - */ - -expectType((url: string) => ({ url })); -expectType((url: string, resourceType: mapboxgl.ResourceType) => ({ - url, - credentials: "same-origin", - headers: { "Accept-Encoding": "compress" }, - method: "POST", - collectResourceTiming: true, -})); - -/* - * Map - */ - -let padding: mapboxgl.PaddingOptions = { - top: 0, - bottom: 0, - left: 0, - right: 0, -}; -let animOpts: mapboxgl.AnimationOptions = { - essential: true, -}; -let cameraOpts: mapboxgl.CameraOptions = { - around: lnglatlike, - center: lnglatlike, - bearing: 0, - pitch: 0, - zoom: 0, - padding, -}; -let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = { - offset: pointlike, - maxZoom: 10, - ...cameraOpts, -}; - -expectType(map.cameraForBounds(lnglatboundslike)); -expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts)); - -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts, { key: "value" })); - -// $ExpectType void -map.triggerRepaint(); - -// $ExpectType PaddingOptions -map.getPadding(); - -// $ExpectType Map -map.setPadding({ top: 10, bottom: 20, left: 30, right: 40 }, { myData: "MY DATA" }); - -map.setPaintProperty("layerId", "layerName", null, { validate: true }); -map.setPaintProperty("layerId", "layerName", null, { validate: false }); -map.setPaintProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setPaintProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLayoutProperty("layerId", "layerName", null, { validate: true }); -map.setLayoutProperty("layerId", "layerName", null, { validate: false }); -map.setLayoutProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setLayoutProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: true }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: false }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, {}); -// @ts-expect-error -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { some_option: "some_string" }); - -// $ExpectType boolean -map.showPadding; -map.showPadding = false; - -expectType(map.setFilter("layerId", true)); -expectType(map.setFilter("layerId", false)); - -map.setFilter("layerId", true, { validate: true }); -map.setFilter("layerId", true, { validate: null }); -map.setFilter("layerId", true, {}); -// @ts-expect-error -map.setFilter("layerId", true, { some_option: "some_string" }); - -// $ExpectType Map -map.setMinZoom(5); -// $ExpectType Map -map.setMaxZoom(10); -// $ExpectType Map -map.setMinZoom(null); -// $ExpectType Map -map.setMinZoom(); -// $ExpectType Map -map.setMaxZoom(null); -// $ExpectType Map -map.setMaxZoom(); - -// $ExpectType number -map.getMinZoom(); -// $ExpectType number -map.getMaxZoom(); - -// $ExpectType Map -map.setMinPitch(5); -// $ExpectType Map -map.setMaxPitch(10); -// $ExpectType Map -map.setMinPitch(null); -// $ExpectType Map -map.setMinPitch(); -// $ExpectType Map -map.setMaxPitch(null); -// $ExpectType Map -map.setMaxPitch(); -// $ExpectType Map -map.resetNorthPitch(animOpts); - -// $ExpectType number -map.getMinPitch(); -// $ExpectType number -map.getMaxPitch(); - -// $ExpectType Map -map.setFog({ - color: "blue", - "horizon-blend": 0.5, - range: [4, 15], - "high-color": "red", - "space-color": "black", - "star-intensity": 0.5, -}); -// $ExpectType Map -map.setFog(null); -// $ExpectType Map -map.setFog(undefined); - -// $ExpectType Fog | null -map.getFog(); - -/* - * Map Events - */ - -// General events -expectType( - map.on("load", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -// $ExpectType Map -map.on("idle", ev => { - ev; // $ExpectType MapboxEvent & EventData -}); -expectType( - map.on("remove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("render", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("resize", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Error event -expectType( - map.on("error", ev => { - expectType(ev); - expectType(ev.error); - expectType(ev.originalEvent); - }), -); - -// Mouse events -expectType( - map.on("mousedown", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseup", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("click", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("dblclick", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mousemove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseover", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseout", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("contextmenu", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Touch events -expectType( - map.on("touchcancel", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchmove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchend", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchstart", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Context events -expectType( - map.on("webglcontextlost", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("webglcontextrestored", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Data events -expectType( - map.on("dataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("data", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("tiledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("sourcedataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("sourcedata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("styledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); -expectType( - map.on("styledata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); - -// Layer events -expectType( - map.on("click", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("dblclick", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousedown", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseup", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousemove", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseenter", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseleave", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseover", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseout", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("contextmenu", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.on("touchstart", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchend", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchcancel", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.once("click", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("dblclick", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mousedown", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseup", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mousemove", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseenter", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseleave", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseover", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseout", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("contextmenu", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.once("touchstart", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("touchend", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("touchcancel", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType(map.off("click", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("dblclick", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mousedown", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseup", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mousemove", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseenter", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseleave", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseover", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseout", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("contextmenu", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchstart", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchend", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchcancel", eitherType("text", ["text1", "text2"]), () => {})); - -/* - * Expression - */ -expectType(["id"]); -expectType(["get", "property"]); -expectType([ - "format", - ["concat", ["get", "name"], "\n"], - {}, - ["concat", ["get", "area"], "foobar", { "font-scale": 0.8 }], -]); -expectType([ - "number-format", - ["get", "quantity"], - { "min-fraction-digits": 1, "max-fraction-digits": 1 }, -]); -expectType([ - "hsla", - ["random", 200, 300, ["id"]], - 80, - ["random", 70, 100, ["+", 2, ["id"]]], - 1.0, -]); -const expression = expectType(["coalesce", ["get", "property"], ["get", "property"]]); - -/* - * ScrollZoomHandler - */ -// $ExpectType void -new mapboxgl.Map().scrollZoom.setZoomRate(1); - -// $ExpectType void -new mapboxgl.Map().scrollZoom.setWheelZoomRate(1); -new mapboxgl.Map().scrollZoom.enable({ around: "center" }); - -const touchPitchHandler = new mapboxgl.TouchPitchHandler(map); -// $ExpectType void -touchPitchHandler.enable(); -touchPitchHandler.enable({ around: "center" }); -// $ExpectType boolean -touchPitchHandler.isActive(); -// $ExpectType boolean -touchPitchHandler.isEnabled(); -// $ExpectType void -touchPitchHandler.disable(); - -new mapboxgl.Map().touchPitch = touchPitchHandler; - -/** - * `dragPan` - */ -// $ExpectType void -new mapboxgl.Map().dragPan.enable({ - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, -}); - -/** - * `touchZoomRotate` - */ -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({ - around: "center", -}); -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable(); - -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({}); - -/* - * Visibility - */ -expectType("visible"); -expectType("none"); - -/* - * Transition - */ - -expectType({ duration: 0 }); -expectType({ delay: 0 }); -const transition = expectType({ duration: 0, delay: 0 }); - -/* - * StyleFunction - */ - -expectType({ base: 1, type: "categorical" }); -const styleFunction = expectType({ - base: 1, - type: "exponential", - default: 0, - stops: [ - [1, 2], - [3, 4], - ], -}); - -/* - * Anchor - */ - -expectType( - eitherType("center", "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right"), -); -const anchor: mapboxgl.Anchor = "center"; - -/* - * Layouts and Paint options - */ - -const backgroundLayout: mapboxgl.BackgroundLayout = { - visibility: eitherType("visible", "none"), -}; - -const backgroundPaint: mapboxgl.BackgroundPaint = { - "background-color": eitherType("#000", expression), - "background-color-transition": transition, - "background-pattern": "pattern", - "background-pattern-transition": transition, - "background-opacity": eitherType(0, expression), - "background-opacity-transition": transition, - "background-emissive-strength": eitherType(0, expression), -}; - -const fillLayout: mapboxgl.FillLayout = { - "fill-sort-key": eitherType(0, expression), -}; - -const fillPaint: mapboxgl.FillPaint = { - "fill-antialias": eitherType(false, expression), - "fill-opacity": eitherType(0, styleFunction, expression), - "fill-opacity-transition": transition, - "fill-color": eitherType("#000", styleFunction, expression), - "fill-color-transition": transition, - "fill-outline-color": eitherType("#000", styleFunction, expression), - "fill-outline-color-transition": transition, - "fill-translate": [1], - "fill-translate-transition": transition, - "fill-translate-anchor": eitherType("map", "viewport"), - "fill-pattern": eitherType("#000", expression), - "fill-pattern-transition": transition, - "fill-emissive-strength": eitherType(0, expression), - "fill-extrusion-ambient-occlusion-ground-attenuation": eitherType(0, expression), - "fill-extrusion-ambient-occlusion-ground-radius": eitherType(0, expression), - "fill-extrusion-ambient-occlusion-wall-radius": eitherType(0, expression), - "fill-extrusion-flood-light-color": eitherType("#000", styleFunction, expression), - "fill-extrusion-flood-light-ground-attenuation": eitherType(0, expression), - "fill-extrusion-flood-light-ground-radius": eitherType(0, expression), - "fill-extrusion-flood-light-intensity": eitherType(0, expression), - "fill-extrusion-flood-light-wall-radius": eitherType(0, expression), - "fill-extrusion-vertical-scale": eitherType(0, expression), -}; - -const fillExtrusionLayout: mapboxgl.FillExtrusionLayout = { - visibility: eitherType("visible", "none"), -}; - -const fillExtrusionPaint: mapboxgl.FillExtrusionPaint = { - "fill-extrusion-opacity": eitherType(0, expression), - "fill-extrusion-opacity-transition": transition, - "fill-extrusion-color": eitherType("#000", styleFunction, expression), - "fill-extrusion-color-transition": transition, - "fill-extrusion-translate": eitherType([0], expression), - "fill-extrusion-translate-transition": transition, - "fill-extrusion-translate-anchor": eitherType("map", "viewport"), - "fill-extrusion-pattern": eitherType("#000", expression), - "fill-extrusion-pattern-transition": transition, - "fill-extrusion-height": eitherType(0, styleFunction, expression), - "fill-extrusion-height-transition": transition, - "fill-extrusion-base": eitherType(0, styleFunction, expression), - "fill-extrusion-base-transition": transition, - "fill-extrusion-vertical-gradient": false, -}; - -const lineLayout: mapboxgl.LineLayout = { - "line-cap": eitherType("butt", "round", "square"), - "line-join": eitherType("bevel", "round", "miter", expression), - "line-miter-limit": eitherType(0, expression), - "line-round-limit": eitherType(0, expression), - "line-sort-key": eitherType(0, expression), -}; - -const linePaint: mapboxgl.LinePaint = { - "line-opacity": eitherType(0, styleFunction, expression), - "line-opacity-transition": transition, - "line-color": eitherType("#000", styleFunction, expression), - "line-color-transition": transition, - "line-translate": eitherType([0], expression), - "line-translate-transition": transition, - "line-translate-anchor": eitherType("map", "viewport"), - "line-width": eitherType(0, styleFunction, expression), - "line-width-transition": transition, - "line-gap-width": eitherType(0, styleFunction, expression), - "line-gap-width-transition": transition, - "line-offset": eitherType(0, styleFunction, expression), - "line-offset-transition": transition, - "line-blur": eitherType(0, styleFunction, expression), - "line-blur-transition": transition, - "line-dasharray": eitherType([0], expression), - "line-dasharray-transition": transition, - "line-pattern": eitherType("#000", expression), - "line-pattern-transition": transition, - "line-gradient": expression, - "line-emissive-strength": eitherType(0, expression), -}; - -const symbolLayout: mapboxgl.SymbolLayout = { - "symbol-placement": eitherType("point", "line", "line-center"), - "symbol-spacing": eitherType(0, expression), - "symbol-avoid-edges": false, - "symbol-z-order": eitherType("viewport-y", "source"), - "icon-allow-overlap": eitherType(false, styleFunction, expression), - "icon-ignore-placement": eitherType(false, expression), - "icon-optional": false, - "icon-rotation-alignment": eitherType("map", "viewport", "auto"), - "icon-size": eitherType(0, styleFunction, expression), - "icon-text-fit": eitherType("none", "both", "width", "height"), - "icon-text-fit-padding": eitherType([0], expression), - "icon-image": eitherType("#000", styleFunction, expression), - "icon-rotate": eitherType(0, styleFunction, expression), - "icon-padding": eitherType(0, expression), - "icon-keep-upright": false, - "icon-offset": eitherType([0], styleFunction, expression), - "icon-anchor": eitherType("center", styleFunction, expression), - "icon-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-rotation-alignment": eitherType("map", "viewport", "auto"), - "text-field": eitherType("#000", styleFunction, expression), - "text-font": eitherType(["arial"], expression), - "text-size": eitherType(0, styleFunction, expression), - "text-max-width": eitherType(0, styleFunction, expression), - "text-line-height": eitherType(0, expression), - "text-letter-spacing": eitherType(0, expression), - "text-justify": eitherType("auto", "left", "center", "right", expression), - "text-anchor": eitherType("center", styleFunction, expression), - "text-max-angle": eitherType(0, expression), - "text-rotate": eitherType(0, styleFunction, expression), - "text-padding": eitherType(0, expression), - "text-keep-upright": false, - "text-transform": eitherType("none", "uppercase", "lowercase", styleFunction, expression), - "text-offset": eitherType([0], expression), - "text-allow-overlap": false, - "text-ignore-placement": false, - "text-optional": false, - "text-radial-offset": eitherType(0, expression), - "text-variable-anchor": [anchor], - "text-writing-mode": eitherType< - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical"> - >(["horizontal"], ["vertical"], ["horizontal", "vertical"]), - "symbol-sort-key": eitherType(0, expression), -}; - -const symbolPaint: mapboxgl.SymbolPaint = { - "icon-opacity": eitherType(0, styleFunction, expression), - "icon-opacity-transition": transition, - "icon-color": eitherType("#000", styleFunction, expression), - "icon-color-transition": transition, - "icon-halo-color": eitherType("#000", styleFunction, expression), - "icon-halo-color-transition": transition, - "icon-halo-width": eitherType(0, styleFunction, expression), - "icon-halo-width-transition": transition, - "icon-halo-blur": eitherType(0, styleFunction, expression), - "icon-halo-blur-transition": transition, - "icon-translate": eitherType([0], expression), - "icon-translate-transition": transition, - "icon-translate-anchor": eitherType("map", "viewport"), - "icon-emissive-strength": eitherType(0, styleFunction, expression), - "icon-image-cross-fade": eitherType(0, styleFunction, expression), - "text-opacity": eitherType(0, styleFunction, expression), - "text-opacity-transition": transition, - "text-color": eitherType("#000", styleFunction, expression), - "text-color-transition": transition, - "text-halo-color": eitherType("#000", styleFunction, expression), - "text-halo-color-transition": transition, - "text-halo-width": eitherType(0, styleFunction, expression), - "text-halo-width-transition": transition, - "text-halo-blur": eitherType(0, styleFunction, expression), - "text-halo-blur-transition": transition, - "text-translate": eitherType([0], expression), - "text-translate-transition": transition, - "text-translate-anchor": eitherType("map", "viewport"), - "text-emissive-strength": eitherType(0, styleFunction, expression), -}; - -const rasterLayout: mapboxgl.RasterLayout = { - visibility: eitherType("visible", "none"), -}; - -const rasterPaint: mapboxgl.RasterPaint = { - "raster-opacity": eitherType(0, expression), - "raster-opacity-transition": transition, - "raster-hue-rotate": eitherType(0, expression), - "raster-hue-rotate-transition": transition, - "raster-brightness-min": eitherType(0, expression), - "raster-brightness-min-transition": transition, - "raster-brightness-max": eitherType(0, expression), - "raster-brightness-max-transition": transition, - "raster-saturation": eitherType(0, expression), - "raster-saturation-transition": transition, - "raster-contrast": eitherType(0, expression), - "raster-contrast-transition": transition, - "raster-fade-duration": eitherType(0, expression), - "raster-resampling": eitherType("linear", "nearest"), - "raster-color-mix": eitherType([0, 0, 0, 0], expression), - "raster-color-range": eitherType([0, 0], expression), - "raster-color": eitherType("#000", expression), -}; - -const circleLayout: mapboxgl.CircleLayout = { - visibility: eitherType("visible", "none"), - "circle-sort-key": eitherType(0, expression), -}; - -const circlePaint: mapboxgl.CirclePaint = { - "circle-radius": eitherType(0, styleFunction, expression), - "circle-radius-transition": transition, - "circle-color": eitherType("#000", styleFunction, expression), - "circle-color-transition": transition, - "circle-blur": eitherType(0, styleFunction, expression), - "circle-blur-transition": transition, - "circle-opacity": eitherType(0, styleFunction, expression), - "circle-opacity-transition": transition, - "circle-translate": eitherType([0], expression), - "circle-translate-transition": transition, - "circle-translate-anchor": eitherType("map", "viewport"), - "circle-pitch-scale": eitherType("map", "viewport"), - "circle-pitch-alignment": eitherType("map", "viewport"), - "circle-stroke-width": eitherType(0, styleFunction, expression), - "circle-stroke-width-transition": transition, - "circle-stroke-color": eitherType("#000", styleFunction, expression), - "circle-stroke-color-transition": transition, - "circle-stroke-opacity": eitherType(0, styleFunction, expression), - "circle-stroke-opacity-transition": transition, - "circle-emissive-strength": eitherType(0, styleFunction, expression), -}; - -const heatmapLayout: mapboxgl.HeatmapLayout = { - visibility: eitherType("visible", "none"), -}; - -const heatmapPaint: mapboxgl.HeatmapPaint = { - "heatmap-radius": eitherType(0, styleFunction, expression), - "heatmap-radius-transition": transition, - "heatmap-weight": eitherType(0, styleFunction, expression), - "heatmap-intensity": eitherType(0, styleFunction, expression), - "heatmap-intensity-transition": transition, - "heatmap-color": eitherType("#000", styleFunction, expression), - "heatmap-opacity": eitherType(0, styleFunction, expression), - "heatmap-opacity-transition": transition, -}; - -const hillshadeLayout: mapboxgl.HillshadeLayout = { - visibility: eitherType("visible", "none"), -}; - -const hillshadePaint: mapboxgl.HillshadePaint = { - "hillshade-illumination-direction": eitherType(0, expression), - "hillshade-illumination-anchor": eitherType("map", "viewport"), - "hillshade-exaggeration": eitherType(0, expression), - "hillshade-exaggeration-transition": transition, - "hillshade-shadow-color": eitherType("#000", expression), - "hillshade-shadow-color-transition": transition, - "hillshade-highlight-color": eitherType("#000", expression), - "hillshade-highlight-color-transition": transition, - "hillshade-accent-color": eitherType("#000", expression), - "hillshade-accent-color-transition": transition, -}; - -const skyLayout: mapboxgl.SkyLayout = { - visibility: eitherType("visible", "none"), -}; - -const skyPaint: mapboxgl.SkyPaint = { - "sky-atmosphere-color": eitherType("white", expression), - "sky-atmosphere-halo-color": eitherType("white", expression), - "sky-atmosphere-sun": eitherType([0], expression), - "sky-atmosphere-sun-intensity": eitherType(0, expression), - "sky-gradient": eitherType("#000", expression), - "sky-gradient-center": eitherType([0], expression), - "sky-gradient-radius": eitherType(0, expression), - "sky-opacity": eitherType(0, expression), - "sky-type": eitherType("gradient", "atmosphere"), -}; - -/* Make sure every layout has all properties optional */ -eitherType< - mapboxgl.BackgroundLayout, - mapboxgl.FillLayout, - mapboxgl.FillExtrusionLayout, - mapboxgl.LineLayout, - mapboxgl.SymbolLayout, - mapboxgl.RasterLayout, - mapboxgl.CircleLayout, - mapboxgl.HeatmapLayout, - mapboxgl.HillshadeLayout, - mapboxgl.SkyLayout ->({}, {}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* Make sure every paint has all properties optional */ -eitherType< - mapboxgl.BackgroundPaint, - mapboxgl.FillPaint, - mapboxgl.FillExtrusionPaint, - mapboxgl.LinePaint, - mapboxgl.SymbolPaint, - mapboxgl.RasterPaint, - mapboxgl.CirclePaint, - mapboxgl.HeatmapPaint, - mapboxgl.HillshadePaint, - mapboxgl.SkyPaint ->({}, {}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* - * AnyLayout - */ -expectType( - eitherType( - backgroundLayout, - fillLayout, - fillExtrusionLayout, - lineLayout, - symbolLayout, - rasterLayout, - circleLayout, - heatmapLayout, - hillshadeLayout, - skyLayout, - ), -); - -/* - * AnyPaint - */ -expectType( - eitherType( - backgroundPaint, - fillPaint, - fillExtrusionPaint, - linePaint, - symbolPaint, - rasterPaint, - circlePaint, - heatmapPaint, - hillshadePaint, - skyPaint, - ), -); - -/* - * Make sure layer gets proper Paint, corresponding to layer's type - */ - -expectType({ id: "unique", type: "background", paint: { "background-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "background", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "fill", paint: { "fill-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "fill", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "line", paint: { "line-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "line", paint: { "fill-opacity": 1 } }); - -/** - * Test map.addImage() - */ - -// HTMLImageElement -const fooHTMLImageElement = document.createElement("img"); -map.addImage("foo", fooHTMLImageElement); - -// ImageData -const fooImageData = new ImageData(8, 8); -map.addImage("foo", fooImageData); - -// ImageData like -const fooImageDataLike1 = { - width: 10, - height: 10, - data: new Uint8ClampedArray(8), -}; -map.addImage("foo", fooImageDataLike1); - -const fooImageDataLike2 = { - width: 10, - height: 10, - data: new Uint8Array(8), -}; -map.addImage("foo", fooImageDataLike2); - -// ArrayBufferView -const fooArrayBufferView: ArrayBufferView = new Uint8Array(8); -map.addImage("foo", fooArrayBufferView); - -// ImageBitmap -createImageBitmap(fooHTMLImageElement).then(fooImageBitmap => { - map.addImage("foo", fooImageBitmap); -}); - -// $ExpectType void -map.loadImage("foo", (error, result) => {}); - -// KeyboardHandler -var keyboardHandler = new mapboxgl.KeyboardHandler(map); -// $ExpectType void -keyboardHandler.enableRotation(); -// $ExpectType void -keyboardHandler.disableRotation(); - -/** - * Test projections - */ - -// projection config: name only -expectType({ name: "mercator" }); - -// projection config: with center and parallels -expectType({ name: "lambertConformalConic", center: [0, 0], parallels: [30, 60] }); - -// set projection with string -map.setProjection("mercator"); - -// set projection with config -map.setProjection({ name: "globe" }); - -// get projections -expectType(map.getProjection()); - -/** - * v3 - */ - -// set config property -map.setConfigProperty("basemap", "lightPreset", "dusk"); -map.setConfigProperty("basemap", "showPointOfInterestLabels", false); - -// get config property -map.getConfigProperty("basemap", "lightPreset"); -map.getConfigProperty("basemap", "showPointOfInterestLabels"); diff --git a/types/mapbox-gl/package.json b/types/mapbox-gl/package.json deleted file mode 100644 index 8c36af4de8eee9..00000000000000 --- a/types/mapbox-gl/package.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "private": true, - "name": "@types/mapbox-gl", - "version": "3.4.9999", - "projects": [ - "https://github.com/mapbox/mapbox-gl-js" - ], - "dependencies": { - "@types/geojson": "*" - }, - "devDependencies": { - "@types/mapbox-gl": "workspace:." - }, - "owners": [ - { - "name": "Dominik Bruderer", - "githubUsername": "dobrud" - }, - { - "name": "Karl-Aksel Puulmann", - "githubUsername": "macobo" - }, - { - "name": "Dmytro Gokun", - "githubUsername": "dmytro-gokun" - }, - { - "name": "Liam Clarke", - "githubUsername": "LiamAttClarke" - }, - { - "name": "Vladimir Dashukevich", - "githubUsername": "life777" - }, - { - "name": "André Fonseca", - "githubUsername": "amxfonseca" - }, - { - "name": "makspetrov", - "githubUsername": "Nosfit" - }, - { - "name": "Michael Bullington", - "githubUsername": "mbullington" - }, - { - "name": "Olivier Pascal", - "githubUsername": "pascaloliv" - }, - { - "name": "Marko Schilde", - "githubUsername": "mschilde" - } - ] -} diff --git a/types/mapbox-gl/tsconfig.json b/types/mapbox-gl/tsconfig.json deleted file mode 100644 index f69bcb46d0e49f..00000000000000 --- a/types/mapbox-gl/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "module": "node16", - "lib": [ - "es6", - "dom" - ], - "strictNullChecks": true, - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "mapbox-gl-tests.ts" - ] -} diff --git a/types/mapbox-gl/v1/.eslintrc.json b/types/mapbox-gl/v1/.eslintrc.json deleted file mode 100644 index 0fe3c8d6ec5898..00000000000000 --- a/types/mapbox-gl/v1/.eslintrc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rules": { - "@definitelytyped/export-just-namespace": "off", - "@definitelytyped/no-any-union": "off", - "@definitelytyped/no-unnecessary-generics": "off", - "@definitelytyped/strict-export-declare-modifiers": "off", - "@typescript-eslint/no-unsafe-function-type": "off", - "@typescript-eslint/no-wrapper-object-types": "off", - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/consistent-type-definitions": "off" - } -} diff --git a/types/mapbox-gl/v1/.npmignore b/types/mapbox-gl/v1/.npmignore deleted file mode 100644 index 93e307400a5456..00000000000000 --- a/types/mapbox-gl/v1/.npmignore +++ /dev/null @@ -1,5 +0,0 @@ -* -!**/*.d.ts -!**/*.d.cts -!**/*.d.mts -!**/*.d.*.ts diff --git a/types/mapbox-gl/v1/index.d.ts b/types/mapbox-gl/v1/index.d.ts deleted file mode 100644 index f50a0e88a10cee..00000000000000 --- a/types/mapbox-gl/v1/index.d.ts +++ /dev/null @@ -1,2338 +0,0 @@ -/// - -export = mapboxgl; -export as namespace mapboxgl; - -declare namespace mapboxgl { - let accessToken: string; - let version: string; - let baseApiUrl: string; - - /** - * Number of web workers instantiated on a page with GL JS maps. - * By default, it is set to half the number of CPU cores (capped at 6). - */ - let workerCount: number; - - /** - * Maximum number of images (raster tiles, sprites, icons) to load in parallel, which affects performance in raster-heavy maps. - * 16 by default. - */ - let maxParallelImageRequests: number; - - export function supported(options?: { failIfMajorPerformanceCaveat?: boolean | undefined }): boolean; - - /** - * Clears browser storage used by this library. Using this method flushes the Mapbox tile cache that is managed by this library. - * Tiles may still be cached by the browser in some cases. - */ - export function clearStorage(callback?: (err?: Error) => void): void; - - export function setRTLTextPlugin(pluginURL: string, callback: (error: Error) => void, deferred?: boolean): void; - export function getRTLTextPluginStatus(): PluginStatus; - - /** - * Initializes resources like WebWorkers that can be shared across maps to lower load - * times in some situations. `mapboxgl.workerUrl` and `mapboxgl.workerCount`, if being - * used, must be set before `prewarm()` is called to have an effect. - * - * By default, the lifecycle of these resources is managed automatically, and they are - * lazily initialized when a Map is first created. By invoking `prewarm()`, these - * resources will be created ahead of time, and will not be cleared when the last Map - * is removed from the page. This allows them to be re-used by new Map instances that - * are created later. They can be manually cleared by calling - * `mapboxgl.clearPrewarmedResources()`. This is only necessary if your web page remains - * active but stops using maps altogether. - * - * This is primarily useful when using GL-JS maps in a single page app, wherein a user - * would navigate between various views that can cause Map instances to constantly be - * created and destroyed. - */ - export function prewarm(): void; - - /** - * Clears up resources that have previously been created by `mapboxgl.prewarm()`. - * Note that this is typically not necessary. You should only call this function - * if you expect the user of your app to not return to a Map view at any point - * in your application. - */ - export function clearPrewarmedResources(): void; - - type PluginStatus = "unavailable" | "loading" | "loaded" | "error"; - - type LngLatLike = - | [number, number] - | LngLat - | { lng: number; lat: number } - | { lon: number; lat: number } - | [number, number]; - - type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number] | LngLatLike; - type PointLike = Point | [number, number]; - type Offset = number | PointLike | { [_: string]: PointLike }; - - type ExpressionName = - // Types - | "array" - | "boolean" - | "collator" - | "format" - | "literal" - | "number" - | "object" - | "string" - | "image" - | "to-boolean" - | "to-color" - | "to-number" - | "to-string" - | "typeof" - // Feature data - | "feature-state" - | "geometry-type" - | "id" - | "line-progress" - | "properties" - // Lookup - | "at" - | "get" - | "has" - | "in" - | "index-of" - | "length" - | "slice" - // Decision - | "!" - | "!=" - | "<" - | "<=" - | "==" - | ">" - | ">=" - | "all" - | "any" - | "case" - | "match" - | "coalesce" - // Ramps, scales, curves - | "interpolate" - | "interpolate-hcl" - | "interpolate-lab" - | "step" - // Variable binding - | "let" - | "var" - // String - | "concat" - | "downcase" - | "is-supported-script" - | "resolved-locale" - | "upcase" - // Color - | "rgb" - | "rgba" - // Math - | "-" - | "*" - | "/" - | "%" - | "^" - | "+" - | "abs" - | "acos" - | "asin" - | "atan" - | "ceil" - | "cos" - | "e" - | "floor" - | "ln" - | "ln2" - | "log10" - | "log2" - | "max" - | "min" - | "pi" - | "round" - | "sin" - | "sqrt" - | "tan" - // Zoom, Heatmap - | "zoom" - | "heatmap-density"; - - type Expression = [ExpressionName, ...any[]]; - - type Anchor = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; - - type DragPanOptions = { - linearity?: number; - easing?: (t: number) => number; - deceleration?: number; - maxSpeed?: number; - }; - - type InteractiveOptions = { around?: "center" }; - - /** - * Map - */ - export class Map extends Evented { - constructor(options?: MapboxOptions); - - addControl( - control: Control | IControl, - position?: "top-right" | "top-left" | "bottom-right" | "bottom-left", - ): this; - - removeControl(control: Control | IControl): this; - - /** - * Checks if a control exists on the map. - * - * @param {IControl} control The {@link IControl} to check. - * @returns {boolean} True if map contains control. - * @example - */ - hasControl(control: IControl): boolean; - - resize(eventData?: EventData): this; - - getBounds(): LngLatBounds; - - getMaxBounds(): LngLatBounds | null; - - setMaxBounds(lnglatbounds?: LngLatBoundsLike): this; - - setMinZoom(minZoom?: number | null): this; - - getMinZoom(): number; - - setMaxZoom(maxZoom?: number | null): this; - - getMaxZoom(): number; - - setMinPitch(minPitch?: number | null): this; - - getMinPitch(): number; - - setMaxPitch(maxPitch?: number | null): this; - - getMaxPitch(): number; - - getRenderWorldCopies(): boolean; - - setRenderWorldCopies(renderWorldCopies?: boolean): this; - - project(lnglat: LngLatLike): mapboxgl.Point; - - unproject(point: PointLike): mapboxgl.LngLat; - - isMoving(): boolean; - - isZooming(): boolean; - - isRotating(): boolean; - - /** - * Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters. - * - * The properties value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only string and numeric property values are supported (i.e. null, Array, and Object values are not supported). - * - * Each feature includes top-level layer, source, and sourceLayer properties. The layer property is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature. - * - * Only features that are currently rendered are included. Some features will not be included, like: - * - * - Features from layers whose visibility property is "none". - * - Features from layers whose zoom range excludes the current zoom level. - * - Symbol features that have been hidden due to text or icon collision. - * - * Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to 0. - * - * The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat). - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param pointOrBox The geometry of the query region: either a single point or southwest and northeast points describing a bounding box. Omitting this parameter (i.e. calling Map#queryRenderedFeatures with zero arguments, or with only a options argument) is equivalent to passing a bounding box encompassing the entire map viewport. - * @param options - */ - queryRenderedFeatures( - pointOrBox?: PointLike | [PointLike, PointLike], - options?: { layers?: string[] | undefined; filter?: any[] | undefined } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - /** - * Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters. - * - * In contrast to Map#queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport. - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param sourceID The ID of the vector tile or GeoJSON source to query. - * @param parameters - */ - querySourceFeatures( - sourceID: string, - parameters?: { - sourceLayer?: string | undefined; - filter?: any[] | undefined; - } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - setStyle( - style: mapboxgl.Style | string, - options?: { diff?: boolean | undefined; localIdeographFontFamily?: string | undefined }, - ): this; - - getStyle(): mapboxgl.Style; - - isStyleLoaded(): boolean; - - addSource(id: string, source: AnySourceData): this; - - isSourceLoaded(id: string): boolean; - - areTilesLoaded(): boolean; - - removeSource(id: string): this; - - getSource(id: string): AnySourceImpl; - - addImage( - name: string, - image: - | HTMLImageElement - | ArrayBufferView - | { width: number; height: number; data: Uint8Array | Uint8ClampedArray } - | ImageData - | ImageBitmap, - options?: { pixelRatio?: number | undefined; sdf?: boolean | undefined }, - ): this; - - hasImage(name: string): boolean; - - removeImage(name: string): this; - - loadImage(url: string, callback: Function): this; - - listImages(): string[]; - - addLayer(layer: mapboxgl.AnyLayer, before?: string): this; - - moveLayer(id: string, beforeId?: string): this; - - removeLayer(id: string): this; - - getLayer(id: string): mapboxgl.AnyLayer; - - setFilter(layer: string, filter?: any[] | boolean | null, options?: FilterOptions | null): this; - - setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number): this; - - getFilter(layer: string): any[]; - - setPaintProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getPaintProperty(layer: string, name: string): any; - - setLayoutProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getLayoutProperty(layer: string, name: string): any; - - setLight(light: mapboxgl.Light, options?: FilterOptions): this; - - getLight(): mapboxgl.Light; - - setFeatureState( - feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, - state: { [key: string]: any }, - ): void; - - getFeatureState(feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature): { [key: string]: any }; - - removeFeatureState(target: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, key?: string): void; - - getContainer(): HTMLElement; - - getCanvasContainer(): HTMLElement; - - getCanvas(): HTMLCanvasElement; - - loaded(): boolean; - - remove(): void; - - triggerRepaint(): void; - - showTileBoundaries: boolean; - - showCollisionBoxes: boolean; - - /** - * Gets and sets a Boolean indicating whether the map will visualize - * the padding offsets. - * - * @name showPadding - * @instance - * @memberof Map - */ - showPadding: boolean; - - repaint: boolean; - - getCenter(): mapboxgl.LngLat; - - setCenter(center: LngLatLike, eventData?: mapboxgl.EventData): this; - - panBy(offset: PointLike, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - panTo(lnglat: LngLatLike, options?: mapboxgl.AnimationOptions, eventdata?: mapboxgl.EventData): this; - - getZoom(): number; - - setZoom(zoom: number, eventData?: mapboxgl.EventData): this; - - zoomTo(zoom: number, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomIn(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomOut(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getBearing(): number; - - setBearing(bearing: number, eventData?: mapboxgl.EventData): this; - - /** - * Returns the current padding applied around the map viewport. - * - * @memberof Map# - * @returns The current padding around the map viewport. - */ - getPadding(): PaddingOptions; - - /** - * Sets the padding in pixels around the viewport. - * - * Equivalent to `jumpTo({padding: padding})`. - * - * @memberof Map# - * @param padding The desired padding. Format: { left: number, right: number, top: number, bottom: number } - * @param eventData Additional properties to be added to event objects of events triggered by this method. - * @fires movestart - * @fires moveend - * @returns {Map} `this` - * @example - * // Sets a left padding of 300px, and a top padding of 50px - * map.setPadding({ left: 300, top: 50 }); - */ - setPadding(padding: PaddingOptions, eventData?: EventData): this; - - rotateTo(bearing: number, options?: mapboxgl.AnimationOptions, eventData?: EventData): this; - - resetNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - resetNorthPitch(options?: mapboxgl.AnimationOptions | null, eventData?: mapboxgl.EventData | null): this; - - snapToNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getPitch(): number; - - setPitch(pitch: number, eventData?: EventData): this; - - cameraForBounds(bounds: LngLatBoundsLike, options?: CameraForBoundsOptions): CameraForBoundsResult | undefined; - - fitBounds(bounds: LngLatBoundsLike, options?: mapboxgl.FitBoundsOptions, eventData?: mapboxgl.EventData): this; - - fitScreenCoordinates( - p0: PointLike, - p1: PointLike, - bearing: number, - options?: AnimationOptions & CameraOptions, - eventData?: EventData, - ): this; - - jumpTo(options: mapboxgl.CameraOptions, eventData?: mapboxgl.EventData): this; - - easeTo(options: mapboxgl.EaseToOptions, eventData?: mapboxgl.EventData): this; - - flyTo(options: mapboxgl.FlyToOptions, eventData?: mapboxgl.EventData): this; - - isEasing(): boolean; - - stop(): this; - - on( - type: T, - layer: string, - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - on(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - on(type: string, listener: (ev: any) => void): this; - - once( - type: T, - layer: string, - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - once(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - once(type: string, listener: (ev: any) => void): this; - - off( - type: T, - layer: string, - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - off(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - off(type: string, listener: (ev: any) => void): this; - - scrollZoom: ScrollZoomHandler; - - boxZoom: BoxZoomHandler; - - dragRotate: DragRotateHandler; - - dragPan: DragPanHandler; - - keyboard: KeyboardHandler; - - doubleClickZoom: DoubleClickZoomHandler; - - touchZoomRotate: TouchZoomRotateHandler; - - touchPitch: TouchPitchHandler; - } - - export interface MapboxOptions { - /** - * If true, the gl context will be created with MSA antialiasing, which can be useful for antialiasing custom layers. - * This is false by default as a performance optimization. - */ - antialias?: boolean | undefined; - - /** If true, an attribution control will be added to the map. */ - attributionControl?: boolean | undefined; - - bearing?: number | undefined; - - /** Snap to north threshold in degrees. */ - bearingSnap?: number | undefined; - - /** The initial bounds of the map. If bounds is specified, it overrides center and zoom constructor options. */ - bounds?: LngLatBoundsLike | undefined; - - /** If true, enable the "box zoom" interaction (see BoxZoomHandler) */ - boxZoom?: boolean | undefined; - - /** initial map center */ - center?: LngLatLike | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click for it to be - * considered a valid click (as opposed to a mouse drag). - * - * @default 3 - */ - clickTolerance?: number | undefined; - - /** - * If `true`, Resource Timing API information will be collected for requests made by GeoJSON - * and Vector Tile web workers (this information is normally inaccessible from the main - * Javascript thread). Information will be returned in a `resourceTiming` property of - * relevant `data` events. - * - * @default false - */ - collectResourceTiming?: boolean | undefined; - - /** - * If `true`, symbols from multiple sources can collide with each other during collision - * detection. If `false`, collision detection is run separately for the symbols in each source. - * - * @default true - */ - crossSourceCollisions?: boolean | undefined; - - /** ID of the container element */ - container: string | HTMLElement; - - /** String or strings to show in an AttributionControl. - * Only applicable if options.attributionControl is `true`. */ - customAttribution?: string | string[] | undefined; - - /** If true, enable the "drag to pan" interaction (see DragPanHandler). */ - dragPan?: boolean | DragPanOptions | undefined; - - /** If true, enable the "drag to rotate" interaction (see DragRotateHandler). */ - dragRotate?: boolean | undefined; - - /** If true, enable the "double click to zoom" interaction (see DoubleClickZoomHandler). */ - doubleClickZoom?: boolean | undefined; - - /** If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL. - * For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`. - * An additional string may optionally be provided to indicate a parameter-styled hash, - * e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo - * is a custom parameter and bar is an arbitrary hash distinct from the map hash. - */ - hash?: boolean | string | undefined; - - /** - * Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. - * This setting affects all symbol layers. This setting does not affect the duration of runtime - * styling transitions or raster tile cross-fading. - * - * @default 300 - */ - fadeDuration?: number | undefined; - - /** If true, map creation will fail if the implementation determines that the performance of the created WebGL context would be dramatically lower than expected. */ - failIfMajorPerformanceCaveat?: boolean | undefined; - - /** A fitBounds options object to use only when setting the bounds option. */ - fitBoundsOptions?: FitBoundsOptions | undefined; - - /** If false, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input */ - interactive?: boolean | undefined; - - /** If true, enable keyboard shortcuts (see KeyboardHandler). */ - keyboard?: boolean | undefined; - - /** A patch to apply to the default localization table for UI strings, e.g. control tooltips. - * The `locale` object maps namespaced UI string IDs to translated strings in the target language; - * see `src/ui/default_locale.js` for an example with all supported string IDs. - * The object may specify all UI strings (thereby adding support for a new translation) or - * only a subset of strings (thereby patching the default translation table). - */ - locale?: { [key: string]: string } | undefined; - - /** - * If specified, defines a CSS font-family for locally overriding generation of glyphs in the - * 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. In these ranges, font settings from - * the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). - * The purpose of this option is to avoid bandwidth-intensive glyph server requests. - * - * @default null - */ - localIdeographFontFamily?: string | undefined; - - /** - * A string representing the position of the Mapbox wordmark on the map. - * - * @default "bottom-left" - */ - logoPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | undefined; - - /** If set, the map is constrained to the given bounds. */ - maxBounds?: LngLatBoundsLike | undefined; - - /** Maximum pitch of the map. */ - maxPitch?: number | undefined; - - /** Maximum zoom of the map. */ - maxZoom?: number | undefined; - - /** Minimum pitch of the map. */ - minPitch?: number | undefined; - - /** Minimum zoom of the map. */ - minZoom?: number | undefined; - - /** If true, The maps canvas can be exported to a PNG using map.getCanvas().toDataURL();. This is false by default as a performance optimization. */ - preserveDrawingBuffer?: boolean | undefined; - - /** - * The initial pitch (tilt) of the map, measured in degrees away from the plane of the - * screen (0-60). - * - * @default 0 - */ - pitch?: number | undefined; - - /** - * If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled. - * - * @default true - */ - pitchWithRotate?: boolean | undefined; - - /** - * If `false`, the map won't attempt to re-request tiles once they expire per their HTTP - * `cacheControl`/`expires` headers. - * - * @default true - */ - refreshExpiredTiles?: boolean | undefined; - - /** - * If `true`, multiple copies of the world will be rendered, when zoomed out. - * - * @default true - */ - renderWorldCopies?: boolean | undefined; - - /** If true, enable the "scroll to zoom" interaction */ - scrollZoom?: boolean | InteractiveOptions | undefined; - - /** stylesheet location */ - style?: mapboxgl.Style | string | undefined; - - /** If true, the map will automatically resize when the browser window resizes */ - trackResize?: boolean | undefined; - - /** - * A callback run before the Map makes a request for an external URL. The callback can be - * used to modify the url, set headers, or set the credentials property for cross-origin requests. - * - * @default null - */ - transformRequest?: TransformRequestFunction | undefined; - - /** If true, enable the "pinch to rotate and zoom" interaction (see TouchZoomRotateHandler). */ - touchZoomRotate?: boolean | InteractiveOptions | undefined; - - /** If true, the "drag to pitch" interaction is enabled */ - touchPitch?: boolean | InteractiveOptions | undefined; - - /** Initial zoom level */ - zoom?: number | undefined; - - /** - * The maximum number of tiles stored in the tile cache for a given source. If omitted, the - * cache will be dynamically sized based on the current viewport. - * - * @default null - */ - maxTileCacheSize?: number | undefined; - - /** - * If specified, map will use this token instead of the one defined in mapboxgl.accessToken. - * - * @default null - */ - accessToken?: string | undefined; - } - - export type ResourceType = - | "Unknown" - | "Style" - | "Source" - | "Tile" - | "Glyphs" - | "SpriteImage" - | "SpriteJSON" - | "Image"; - - export interface RequestParameters { - /** - * The URL to be requested. - */ - url: string; - - /** - * Use `'include'` to send cookies with cross-origin requests. - */ - credentials?: "same-origin" | "include" | undefined; - - /** - * The headers to be sent with the request. - */ - headers?: { [header: string]: any } | undefined; - - method?: "GET" | "POST" | "PUT" | undefined; - - collectResourceTiming?: boolean | undefined; - } - - export type TransformRequestFunction = (url: string, resourceType: ResourceType) => RequestParameters; - - export interface PaddingOptions { - top: number; - bottom: number; - left: number; - right: number; - } - - export interface FeatureIdentifier { - id?: string | number | undefined; - source: string; - sourceLayer?: string | undefined; - } - - /** - * BoxZoomHandler - */ - export class BoxZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * ScrollZoomHandler - */ - export class ScrollZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - setZoomRate(zoomRate: number): void; - - setWheelZoomRate(wheelZoomRate: number): void; - } - - /** - * DragPenHandler - */ - export class DragPanHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(options?: DragPanOptions): void; - - disable(): void; - } - - /** - * DragRotateHandler - */ - export class DragRotateHandler { - constructor( - map: mapboxgl.Map, - options?: { bearingSnap?: number | undefined; pitchWithRotate?: boolean | undefined }, - ); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * KeyboardHandler - */ - export class KeyboardHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - - /** - * Returns true if the handler is enabled and has detected the start of a - * zoom/rotate gesture. - * - * @returns {boolean} `true` if the handler is enabled and has detected the - * start of a zoom/rotate gesture. - */ - isActive(): boolean; - - /** - * Disables the "keyboard pan/rotate" interaction, leaving the - * "keyboard zoom" interaction enabled. - * - * @example - * map.keyboard.disableRotation(); - */ - disableRotation(): void; - - /** - * Enables the "keyboard pan/rotate" interaction. - * - * @example - * map.keyboard.enable(); - * map.keyboard.enableRotation(); - */ - enableRotation(): void; - } - - /** - * DoubleClickZoomHandler - */ - export class DoubleClickZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * TouchZoomRotateHandler - */ - export class TouchZoomRotateHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - disableRotation(): void; - - enableRotation(): void; - } - - export class TouchPitchHandler { - constructor(map: mapboxgl.Map); - - enable(options?: InteractiveOptions): void; - - isActive(): boolean; - - isEnabled(): boolean; - - disable(): void; - } - - export interface IControl { - onAdd(map: Map): HTMLElement; - - onRemove(map: Map): void; - - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Control - */ - export class Control extends Evented implements IControl { - onAdd(map: Map): HTMLElement; - onRemove(map: Map): void; - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Navigation - */ - export class NavigationControl extends Control { - constructor(options?: { - showCompass?: boolean | undefined; - showZoom?: boolean | undefined; - visualizePitch?: boolean | undefined; - }); - } - - export class PositionOptions { - enableHighAccuracy?: boolean | undefined; - timeout?: number | undefined; - maximumAge?: number | undefined; - } - - /** - * Geolocate - */ - export class GeolocateControl extends Control { - constructor(options?: { - positionOptions?: PositionOptions | undefined; - fitBoundsOptions?: FitBoundsOptions | undefined; - trackUserLocation?: boolean | undefined; - showAccuracyCircle?: boolean | undefined; - showUserLocation?: boolean | undefined; - }); - trigger(): boolean; - } - - /** - * Attribution - */ - export class AttributionControl extends Control { - constructor(options?: { compact?: boolean | undefined; customAttribution?: string | string[] | undefined }); - } - - /** - * Scale - */ - export class ScaleControl extends Control { - constructor(options?: { maxWidth?: number | undefined; unit?: string | undefined }); - - setUnit(unit: "imperial" | "metric" | "nautical"): void; - } - - /** - * FullscreenControl - */ - export class FullscreenControl extends Control { - constructor(options?: FullscreenControlOptions | null); - } - - export interface FullscreenControlOptions { - /** - * A compatible DOM element which should be made full screen. - * By default, the map container element will be made full screen. - */ - container?: HTMLElement | null | undefined; - } - - /** - * Popup - */ - export class Popup extends Evented { - constructor(options?: mapboxgl.PopupOptions); - - addTo(map: mapboxgl.Map): this; - - isOpen(): boolean; - - remove(): this; - - getLngLat(): mapboxgl.LngLat; - - /** - * Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior. - * - * @param lnglat The geographical location to set as the popup's anchor. - */ - setLngLat(lnglat: LngLatLike): this; - - /** - * Tracks the popup anchor to the cursor position, on screens with a pointer device (will be hidden on touchscreens). Replaces the setLngLat behavior. - * For most use cases, `closeOnClick` and `closeButton` should also be set to `false` here. - */ - trackPointer(): this; - - /** Returns the `Popup`'s HTML element. */ - getElement(): HTMLElement; - - setText(text: string): this; - - setHTML(html: string): this; - - setDOMContent(htmlNode: Node): this; - - getMaxWidth(): string; - - setMaxWidth(maxWidth: string): this; - - /** - * Adds a CSS class to the popup container element. - * - * @param {string} className Non-empty string with CSS class name to add to popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.addClassName('some-class') - */ - addClassName(className: string): void; - - /** - * Removes a CSS class from the popup container element. - * - * @param {string} className Non-empty string with CSS class name to remove from popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.removeClassName('some-class') - */ - removeClassName(className: string): void; - - /** - * Sets the popup's offset. - * - * @param offset Sets the popup's offset. - * @returns {Popup} `this` - */ - setOffset(offset?: Offset | null): this; - - /** - * Add or remove the given CSS class on the popup container, depending on whether the container currently has that class. - * - * @param {string} className Non-empty string with CSS class name to add/remove - * - * @returns {boolean} if the class was removed return false, if class was added, then return true - * - * @example - * let popup = new mapboxgl.Popup() - * popup.toggleClassName('toggleClass') - */ - toggleClassName(className: string): void; - } - - export interface PopupOptions { - closeButton?: boolean | undefined; - - closeOnClick?: boolean | undefined; - - /** - * @param {boolean} [options.closeOnMove=false] If `true`, the popup will closed when the map moves. - */ - closeOnMove?: boolean | undefined; - - /** - * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the - * first focusable element inside the popup. - */ - focusAfterOpen?: boolean | null | undefined; - - anchor?: Anchor | undefined; - - offset?: Offset | null | undefined; - - className?: string | undefined; - - maxWidth?: string | undefined; - } - - export interface Style { - bearing?: number | undefined; - center?: number[] | undefined; - glyphs?: string | undefined; - layers?: AnyLayer[] | undefined; - metadata?: any; - name?: string | undefined; - pitch?: number | undefined; - light?: Light | undefined; - sources?: Sources | undefined; - sprite?: string | undefined; - transition?: Transition | undefined; - version: number; - zoom?: number | undefined; - } - - export interface Transition { - delay?: number | undefined; - duration?: number | undefined; - } - - export interface Light { - anchor?: "map" | "viewport" | undefined; - position?: number[] | undefined; - "position-transition"?: Transition | undefined; - color?: string | undefined; - "color-transition"?: Transition | undefined; - intensity?: number | undefined; - "intensity-transition"?: Transition | undefined; - } - - export interface Sources { - [sourceName: string]: AnySourceData; - } - - export type PromoteIdSpecification = { [key: string]: string } | string; - - export type AnySourceData = - | GeoJSONSourceRaw - | VideoSourceRaw - | ImageSourceRaw - | CanvasSourceRaw - | VectorSource - | RasterSource - | RasterDemSource; - - interface VectorSourceImpl extends VectorSource { - /** - * Sets the source `tiles` property and re-renders the map. - * - * @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec. - * @returns {VectorTileSource} this - */ - setTiles(tiles: readonly string[]): VectorSourceImpl; - - /** - * Sets the source `url` property and re-renders the map. - * - * @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://`. - * @returns {VectorTileSource} this - */ - setUrl(url: string): VectorSourceImpl; - } - - export type AnySourceImpl = - | GeoJSONSource - | VideoSource - | ImageSource - | CanvasSource - | VectorSourceImpl - | RasterSource - | RasterDemSource; - - export interface Source { - type: "vector" | "raster" | "raster-dem" | "geojson" | "image" | "video" | "canvas"; - } - - /** - * GeoJSONSource - */ - - export interface GeoJSONSourceRaw extends Source, GeoJSONSourceOptions { - type: "geojson"; - } - - export class GeoJSONSource implements GeoJSONSourceRaw { - type: "geojson"; - - constructor(options?: mapboxgl.GeoJSONSourceOptions); - - setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; - - getClusterExpansionZoom(clusterId: number, callback: (error: any, zoom: number) => void): this; - - getClusterChildren( - clusterId: number, - callback: (error: any, features: Array>) => void, - ): this; - - getClusterLeaves( - cluserId: number, - limit: number, - offset: number, - callback: (error: any, features: Array>) => void, - ): this; - } - - export interface GeoJSONSourceOptions { - data?: GeoJSON.Feature | GeoJSON.FeatureCollection | string | undefined; - - maxzoom?: number | undefined; - - attribution?: string | undefined; - - buffer?: number | undefined; - - tolerance?: number | undefined; - - cluster?: number | boolean | undefined; - - clusterRadius?: number | undefined; - - clusterMaxZoom?: number | undefined; - - /** - * Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`. - */ - clusterMinPoints?: number | undefined; - - clusterProperties?: object | undefined; - - lineMetrics?: boolean | undefined; - - generateId?: boolean | undefined; - - promoteId?: PromoteIdSpecification | undefined; - - filter?: any; - } - - /** - * VideoSource - */ - export interface VideoSourceRaw extends Source, VideoSourceOptions { - type: "video"; - } - - export class VideoSource implements VideoSourceRaw { - type: "video"; - - constructor(options?: mapboxgl.VideoSourceOptions); - - getVideo(): HTMLVideoElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface VideoSourceOptions { - urls?: string[] | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * ImageSource - */ - export interface ImageSourceRaw extends Source, ImageSourceOptions { - type: "image"; - } - - export class ImageSource implements ImageSourceRaw { - type: "image"; - - constructor(options?: mapboxgl.ImageSourceOptions); - - updateImage(options: ImageSourceOptions): this; - - setCoordinates(coordinates: number[][]): this; - } - - export interface ImageSourceOptions { - url?: string | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * CanvasSource - */ - export interface CanvasSourceRaw extends Source, CanvasSourceOptions { - type: "canvas"; - } - - export class CanvasSource implements CanvasSourceRaw { - type: "canvas"; - - coordinates: number[][]; - - canvas: string | HTMLCanvasElement; - - play(): void; - - pause(): void; - - getCanvas(): HTMLCanvasElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface CanvasSourceOptions { - coordinates: number[][]; - - animate?: boolean | undefined; - - canvas: string | HTMLCanvasElement; - } - - interface VectorSource extends Source { - type: "vector"; - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - scheme?: "xyz" | "tms" | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - attribution?: string | undefined; - promoteId?: PromoteIdSpecification | undefined; - } - - interface RasterSource extends Source { - type: "raster"; - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - scheme?: "xyz" | "tms" | undefined; - attribution?: string | undefined; - } - - interface RasterDemSource extends Source { - type: "raster-dem"; - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - attribution?: string | undefined; - encoding?: "terrarium" | "mapbox" | undefined; - } - - /** - * LngLat - */ - export class LngLat { - lng: number; - lat: number; - - constructor(lng: number, lat: number); - - /** Return a new LngLat object whose longitude is wrapped to the range (-180, 180). */ - wrap(): mapboxgl.LngLat; - - /** Return a LngLat as an array */ - toArray(): number[]; - - /** Return a LngLat as a string */ - toString(): string; - - /** Returns the approximate distance between a pair of coordinates in meters - * Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159) */ - distanceTo(lngLat: LngLat): number; - - toBounds(radius: number): LngLatBounds; - - static convert(input: LngLatLike): mapboxgl.LngLat; - } - - /** - * LngLatBounds - */ - export class LngLatBounds { - sw: LngLatLike; - ne: LngLatLike; - - constructor(boundsLike?: [LngLatLike, LngLatLike] | [number, number, number, number]); - constructor(sw: LngLatLike, ne: LngLatLike); - - setNorthEast(ne: LngLatLike): this; - - setSouthWest(sw: LngLatLike): this; - - /** Check if the point is within the bounding box. */ - contains(lnglat: LngLatLike): boolean; - - /** Extend the bounds to include a given LngLat or LngLatBounds. */ - extend(obj: mapboxgl.LngLatLike | mapboxgl.LngLatBoundsLike): this; - - /** Get the point equidistant from this box's corners */ - getCenter(): mapboxgl.LngLat; - - /** Get southwest corner */ - getSouthWest(): mapboxgl.LngLat; - - /** Get northeast corner */ - getNorthEast(): mapboxgl.LngLat; - - /** Get northwest corner */ - getNorthWest(): mapboxgl.LngLat; - - /** Get southeast corner */ - getSouthEast(): mapboxgl.LngLat; - - /** Get west edge longitude */ - getWest(): number; - - /** Get south edge latitude */ - getSouth(): number; - - /** Get east edge longitude */ - getEast(): number; - - /** Get north edge latitude */ - getNorth(): number; - - /** Returns a LngLatBounds as an array */ - toArray(): number[][]; - - /** Return a LngLatBounds as a string */ - toString(): string; - - /** Returns a boolean */ - isEmpty(): boolean; - - /** Convert an array to a LngLatBounds object, or return an existing LngLatBounds object unchanged. */ - static convert(input: LngLatBoundsLike): mapboxgl.LngLatBounds; - } - - /** - * Point - */ - // Todo: Pull out class to seperate definition for Module "point-geometry" - export class Point { - x: number; - y: number; - - constructor(x: number, y: number); - - clone(): Point; - - add(p: Point): Point; - - sub(p: Point): Point; - - mult(k: number): Point; - - div(k: number): Point; - - rotate(a: number): Point; - - matMult(m: number): Point; - - unit(): Point; - - perp(): Point; - - round(): Point; - - mag(): number; - - equals(p: Point): boolean; - - dist(p: Point): number; - - distSqr(p: Point): number; - - angle(): number; - - angleTo(p: Point): number; - - angleWidth(p: Point): number; - - angleWithSep(x: number, y: number): number; - - static convert(a: PointLike): Point; - } - - /** - * MercatorCoordinate - */ - export class MercatorCoordinate { - /** The x component of the position. */ - x: number; - - /** The y component of the position. */ - y: number; - - /** - * The z component of the position. - * - * @default 0 - */ - z?: number | undefined; - - constructor(x: number, y: number, z?: number); - - /** Returns the altitude in meters of the coordinate. */ - toAltitude(): number; - - /** Returns the LngLat for the coordinate. */ - toLngLat(): LngLat; - - /** - * Returns the distance of 1 meter in MercatorCoordinate units at this latitude. - * - * For coordinates in real world units using meters, this naturally provides the - * scale to transform into MercatorCoordinates. - */ - meterInMercatorCoordinateUnits(): number; - - /** Project a LngLat to a MercatorCoordinate. */ - static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate; - } - - /** - * Marker - */ - export class Marker extends Evented { - constructor(options?: mapboxgl.MarkerOptions); - - constructor(element?: HTMLElement, options?: mapboxgl.MarkerOptions); - - addTo(map: Map): this; - - remove(): this; - - getLngLat(): LngLat; - - setLngLat(lngLat: LngLatLike): this; - - getElement(): HTMLElement; - - setPopup(popup?: Popup): this; - - getPopup(): Popup; - - togglePopup(): this; - - getOffset(): PointLike; - - setOffset(offset: PointLike): this; - - setDraggable(shouldBeDraggable: boolean): this; - - isDraggable(): boolean; - - getRotationAlignment(): Alignment; - - setRotationAlignment(alignment: Alignment): this; - - getPitchAlignment(): Alignment; - - setPitchAlignment(alignment: Alignment): this; - } - - type Alignment = "map" | "viewport" | "auto"; - - export interface MarkerOptions { - /** DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker */ - element?: HTMLElement | undefined; - - /** The offset in pixels as a PointLike object to apply relative to the element's center. Negatives indicate left and up. */ - offset?: PointLike | undefined; - - /** A string indicating the part of the Marker that should be positioned closest to the coordinate set via Marker.setLngLat. - * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`. - * The default value os `'center'` - */ - anchor?: Anchor | undefined; - - /** The color to use for the default marker if options.element is not provided. The default is light blue (#3FB1CE). */ - color?: string | undefined; - - /** A boolean indicating whether or not a marker is able to be dragged to a new position on the map. The default value is false */ - draggable?: boolean | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click on the marker for it to be considered a valid click - * (as opposed to a marker drag). The default (0) is to inherit map's clickTolerance. - */ - clickTolerance?: number | null | undefined; - - /** The rotation angle of the marker in degrees, relative to its `rotationAlignment` setting. A positive value will rotate the marker clockwise. - * The default value is 0. - */ - rotation?: number | undefined; - - /** `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates. - * `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations. - * `auto` is equivalent to `viewport`. - * The default value is `auto` - */ - rotationAlignment?: Alignment | undefined; - - /** `map` aligns the `Marker` to the plane of the map. - * `viewport` aligns the `Marker` to the plane of the viewport. - * `auto` automatically matches the value of `rotationAlignment`. - * The default value is `auto`. - */ - pitchAlignment?: Alignment | undefined; - - /** The scale to use for the default marker if options.element is not provided. - * The default scale (1) corresponds to a height of `41px` and a width of `27px`. - */ - scale?: number | undefined; - } - - /** - * Evented - */ - export class Evented { - on(type: string, listener: Function): this; - - off(type?: string | any, listener?: Function): this; - - once(type: string, listener: Function): this; - - // https://github.com/mapbox/mapbox-gl-js/issues/6522 - fire(type: string, properties?: { [key: string]: any }): this; - } - - /** - * StyleOptions - */ - export interface StyleOptions { - transition?: boolean | undefined; - } - - export type MapboxGeoJSONFeature = GeoJSON.Feature & { - layer: Layer; - source: string; - sourceLayer: string; - state: { [key: string]: any }; - }; - - export type EventData = { [key: string]: any }; - - export class MapboxEvent { - type: string; - target: Map; - originalEvent: TOrig; - } - - export class MapMouseEvent extends MapboxEvent { - type: - | "mousedown" - | "mouseup" - | "click" - | "dblclick" - | "mousemove" - | "mouseover" - | "mouseenter" - | "mouseleave" - | "mouseout" - | "contextmenu"; - - point: Point; - lngLat: LngLat; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerMouseEvent = MapMouseEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapTouchEvent extends MapboxEvent { - type: "touchstart" | "touchend" | "touchcancel"; - - point: Point; - lngLat: LngLat; - points: Point[]; - lngLats: LngLat[]; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerTouchEvent = MapTouchEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapWheelEvent extends MapboxEvent { - type: "wheel"; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export interface MapBoxZoomEvent extends MapboxEvent { - type: "boxzoomstart" | "boxzoomend" | "boxzoomcancel"; - - boxZoomBounds: LngLatBounds; - } - - export type MapDataEvent = MapSourceDataEvent | MapStyleDataEvent; - - export interface MapStyleDataEvent extends MapboxEvent { - dataType: "style"; - } - - export interface MapSourceDataEvent extends MapboxEvent { - dataType: "source"; - isSourceLoaded: boolean; - source: Source; - sourceId: string; - sourceDataType: "metadata" | "content"; - tile: any; - coord: Coordinate; - } - - export interface Coordinate { - canonical: CanonicalCoordinate; - wrap: number; - key: number; - } - - export interface CanonicalCoordinate { - x: number; - y: number; - z: number; - key: number; - equals(coord: CanonicalCoordinate): boolean; - } - - export interface MapContextEvent extends MapboxEvent { - type: "webglcontextlost" | "webglcontextrestored"; - } - - export class ErrorEvent extends MapboxEvent { - type: "error"; - error: Error; - } - - /** - * FilterOptions - */ - export interface FilterOptions { - /** - * Whether to check if the filter conforms to the Mapbox GL Style Specification. - * Disabling validation is a performance optimization that should only be used - * if you have previously validated the values you will be passing to this function. - */ - validate?: boolean | null | undefined; - } - - /** - * AnimationOptions - */ - export interface AnimationOptions { - /** Number in milliseconds */ - duration?: number | undefined; - /** - * A function taking a time in the range 0..1 and returning a number where 0 is the initial - * state and 1 is the final state. - */ - easing?: ((time: number) => number) | undefined; - /** point, origin of movement relative to map center */ - offset?: PointLike | undefined; - /** When set to false, no animation happens */ - animate?: boolean | undefined; - - /** If `true`, then the animation is considered essential and will not be affected by `prefers-reduced-motion`. - * Otherwise, the transition will happen instantly if the user has enabled the `reduced motion` accesibility feature in their operating system. - */ - essential?: boolean | undefined; - } - - /** - * CameraOptions - */ - export interface CameraOptions { - /** Map center */ - center?: LngLatLike | undefined; - /** Map zoom level */ - zoom?: number | undefined; - /** Map rotation bearing in degrees counter-clockwise from north */ - bearing?: number | undefined; - /** Map angle in degrees at which the camera is looking at the ground */ - pitch?: number | undefined; - /** If zooming, the zoom center (defaults to map center) */ - around?: LngLatLike | undefined; - } - - export interface CameraForBoundsOptions extends CameraOptions { - padding?: number | PaddingOptions | undefined; - offset?: PointLike | undefined; - maxZoom?: number | undefined; - } - - // The Mapbox docs say that if the result is defined, it will have zoom, center and bearing set. - // In practice center is always a {lat, lng} object. - export type CameraForBoundsResult = Required> & { - /** Map center */ - center: { lng: number; lat: number }; - }; - - /** - * FlyToOptions - */ - export interface FlyToOptions extends AnimationOptions, CameraOptions { - curve?: number | undefined; - minZoom?: number | undefined; - speed?: number | undefined; - screenSpeed?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * EaseToOptions - */ - export interface EaseToOptions extends AnimationOptions, CameraOptions { - delayEndEvents?: number | undefined; - } - - export interface FitBoundsOptions extends mapboxgl.FlyToOptions { - linear?: boolean | undefined; - padding?: number | mapboxgl.PaddingOptions | undefined; - offset?: mapboxgl.PointLike | undefined; - maxZoom?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * MapEvent - */ - export type MapEventType = { - error: ErrorEvent; - - load: MapboxEvent; - idle: MapboxEvent; - remove: MapboxEvent; - render: MapboxEvent; - resize: MapboxEvent; - - webglcontextlost: MapContextEvent; - webglcontextrestored: MapContextEvent; - - dataloading: MapDataEvent; - data: MapDataEvent; - tiledataloading: MapDataEvent; - sourcedataloading: MapSourceDataEvent; - styledataloading: MapStyleDataEvent; - sourcedata: MapSourceDataEvent; - styledata: MapStyleDataEvent; - - boxzoomcancel: MapBoxZoomEvent; - boxzoomstart: MapBoxZoomEvent; - boxzoomend: MapBoxZoomEvent; - - touchcancel: MapTouchEvent; - touchmove: MapTouchEvent; - touchend: MapTouchEvent; - touchstart: MapTouchEvent; - - click: MapMouseEvent; - contextmenu: MapMouseEvent; - dblclick: MapMouseEvent; - mousemove: MapMouseEvent; - mouseup: MapMouseEvent; - mousedown: MapMouseEvent; - mouseout: MapMouseEvent; - mouseover: MapMouseEvent; - - movestart: MapboxEvent; - move: MapboxEvent; - moveend: MapboxEvent; - - zoomstart: MapboxEvent; - zoom: MapboxEvent; - zoomend: MapboxEvent; - - rotatestart: MapboxEvent; - rotate: MapboxEvent; - rotateend: MapboxEvent; - - dragstart: MapboxEvent; - drag: MapboxEvent; - dragend: MapboxEvent; - - pitchstart: MapboxEvent; - pitch: MapboxEvent; - pitchend: MapboxEvent; - - wheel: MapWheelEvent; - }; - - export type MapLayerEventType = { - click: MapLayerMouseEvent; - dblclick: MapLayerMouseEvent; - mousedown: MapLayerMouseEvent; - mouseup: MapLayerMouseEvent; - mousemove: MapLayerMouseEvent; - mouseenter: MapLayerMouseEvent; - mouseleave: MapLayerMouseEvent; - mouseover: MapLayerMouseEvent; - mouseout: MapLayerMouseEvent; - contextmenu: MapLayerMouseEvent; - - touchstart: MapLayerTouchEvent; - touchend: MapLayerTouchEvent; - touchcancel: MapLayerTouchEvent; - }; - - export type AnyLayout = - | BackgroundLayout - | FillLayout - | FillExtrusionLayout - | LineLayout - | SymbolLayout - | RasterLayout - | CircleLayout - | HeatmapLayout - | HillshadeLayout; - - export type AnyPaint = - | BackgroundPaint - | FillPaint - | FillExtrusionPaint - | LinePaint - | SymbolPaint - | RasterPaint - | CirclePaint - | HeatmapPaint - | HillshadePaint; - - interface Layer { - id: string; - type: string; - - metadata?: any; - ref?: string | undefined; - - source?: string | AnySourceData | undefined; - - "source-layer"?: string | undefined; - - minzoom?: number | undefined; - maxzoom?: number | undefined; - - interactive?: boolean | undefined; - - filter?: any[] | undefined; - layout?: Layout | undefined; - paint?: object | undefined; - } - - interface BackgroundLayer extends Layer { - type: "background"; - layout?: BackgroundLayout | undefined; - paint?: BackgroundPaint | undefined; - } - - interface CircleLayer extends Layer { - type: "circle"; - layout?: CircleLayout | undefined; - paint?: CirclePaint | undefined; - } - - interface FillExtrusionLayer extends Layer { - type: "fill-extrusion"; - layout?: FillExtrusionLayout | undefined; - paint?: FillExtrusionPaint | undefined; - } - - interface FillLayer extends Layer { - type: "fill"; - layout?: FillLayout | undefined; - paint?: FillPaint | undefined; - } - - interface HeatmapLayer extends Layer { - type: "heatmap"; - layout?: HeatmapLayout | undefined; - paint?: HeatmapPaint | undefined; - } - - interface HillshadeLayer extends Layer { - type: "hillshade"; - layout?: HillshadeLayout | undefined; - paint?: HillshadePaint | undefined; - } - - interface LineLayer extends Layer { - type: "line"; - layout?: LineLayout | undefined; - paint?: LinePaint | undefined; - } - - interface RasterLayer extends Layer { - type: "raster"; - layout?: RasterLayout | undefined; - paint?: RasterPaint | undefined; - } - - interface SymbolLayer extends Layer { - type: "symbol"; - layout?: SymbolLayout | undefined; - paint?: SymbolPaint | undefined; - } - - export type AnyLayer = - | BackgroundLayer - | CircleLayer - | FillExtrusionLayer - | FillLayer - | HeatmapLayer - | HillshadeLayer - | LineLayer - | RasterLayer - | SymbolLayer - | CustomLayerInterface; - - // See https://docs.mapbox.com/mapbox-gl-js/api/#customlayerinterface - export interface CustomLayerInterface { - /** A unique layer id. */ - id: string; - - /* The layer's type. Must be "custom". */ - type: "custom"; - - /* Either "2d" or "3d". Defaults to "2d". */ - renderingMode?: "2d" | "3d" | undefined; - - /** - * Optional method called when the layer has been removed from the Map with Map#removeLayer. - * This gives the layer a chance to clean up gl resources and event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onRemove?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called when the layer has been added to the Map with Map#addLayer. - * This gives the layer a chance to initialize gl resources and register event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onAdd?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called during a render frame to allow a layer to prepare resources - * or render into a texture. - * - * The layer cannot make any assumptions about the current GL state and must bind a framebuffer - * before rendering. - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - prerender?(gl: WebGLRenderingContext, matrix: number[]): void; - - /** - * Called during a render frame allowing the layer to draw into the GL context. - * - * The layer can assume blending and depth state is set to allow the layer to properly blend - * and clip other layers. The layer cannot make any other assumptions about the current GL state. - * - * If the layer needs to render to a texture, it should implement the prerender method to do this - * and only use the render method for drawing directly into the main framebuffer. - * - * The blend function is set to gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA). This expects - * colors to be provided in premultiplied alpha form where the r, g and b values are already - * multiplied by the a value. If you are unable to provide colors in premultiplied form you may - * want to change the blend function to - * gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA). - * - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - render(gl: WebGLRenderingContext, matrix: number[]): void; - } - - export interface StyleFunction { - stops?: any[][] | undefined; - property?: string | undefined; - base?: number | undefined; - type?: "identity" | "exponential" | "interval" | "categorical" | undefined; - default?: any; - colorSpace?: "rgb" | "lab" | "hcl" | undefined; - } - - type Visibility = "visible" | "none"; - - export interface Layout { - visibility?: Visibility | undefined; - } - - export interface BackgroundLayout extends Layout {} - - export interface BackgroundPaint { - "background-color"?: string | Expression | undefined; - "background-color-transition"?: Transition | undefined; - "background-pattern"?: string | undefined; - "background-pattern-transition"?: Transition | undefined; - "background-opacity"?: number | Expression | undefined; - "background-opacity-transition"?: Transition | undefined; - } - - export interface FillLayout extends Layout { - "fill-sort-key"?: number | Expression | undefined; - } - - export interface FillPaint { - "fill-antialias"?: boolean | Expression | undefined; - "fill-opacity"?: number | StyleFunction | Expression | undefined; - "fill-opacity-transition"?: Transition | undefined; - "fill-color"?: string | StyleFunction | Expression | undefined; - "fill-color-transition"?: Transition | undefined; - "fill-outline-color"?: string | StyleFunction | Expression | undefined; - "fill-outline-color-transition"?: Transition | undefined; - "fill-translate"?: number[] | undefined; - "fill-translate-transition"?: Transition | undefined; - "fill-translate-anchor"?: "map" | "viewport" | undefined; - "fill-pattern"?: string | Expression | undefined; - "fill-pattern-transition"?: Transition | undefined; - } - - export interface FillExtrusionLayout extends Layout {} - - export interface FillExtrusionPaint { - "fill-extrusion-opacity"?: number | Expression | undefined; - "fill-extrusion-opacity-transition"?: Transition | undefined; - "fill-extrusion-color"?: string | StyleFunction | Expression | undefined; - "fill-extrusion-color-transition"?: Transition | undefined; - "fill-extrusion-translate"?: number[] | Expression | undefined; - "fill-extrusion-translate-transition"?: Transition | undefined; - "fill-extrusion-translate-anchor"?: "map" | "viewport" | undefined; - "fill-extrusion-pattern"?: string | Expression | undefined; - "fill-extrusion-pattern-transition"?: Transition | undefined; - "fill-extrusion-height"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-height-transition"?: Transition | undefined; - "fill-extrusion-base"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-base-transition"?: Transition | undefined; - "fill-extrusion-vertical-gradient"?: boolean | undefined; - } - - export interface LineLayout extends Layout { - "line-cap"?: "butt" | "round" | "square" | undefined; - "line-join"?: "bevel" | "round" | "miter" | Expression | undefined; - "line-miter-limit"?: number | Expression | undefined; - "line-round-limit"?: number | Expression | undefined; - "line-sort-key"?: number | Expression | undefined; - } - - export interface LinePaint { - "line-opacity"?: number | StyleFunction | Expression | undefined; - "line-opacity-transition"?: Transition | undefined; - "line-color"?: string | StyleFunction | Expression | undefined; - "line-color-transition"?: Transition | undefined; - "line-translate"?: number[] | Expression | undefined; - "line-translate-transition"?: Transition | undefined; - "line-translate-anchor"?: "map" | "viewport" | undefined; - "line-width"?: number | StyleFunction | Expression | undefined; - "line-width-transition"?: Transition | undefined; - "line-gap-width"?: number | StyleFunction | Expression | undefined; - "line-gap-width-transition"?: Transition | undefined; - "line-offset"?: number | StyleFunction | Expression | undefined; - "line-offset-transition"?: Transition | undefined; - "line-blur"?: number | StyleFunction | Expression | undefined; - "line-blur-transition"?: Transition | undefined; - "line-dasharray"?: number[] | Expression | undefined; - "line-dasharray-transition"?: Transition | undefined; - "line-pattern"?: string | Expression | undefined; - "line-pattern-transition"?: Transition | undefined; - "line-gradient"?: Expression | undefined; - } - - export interface SymbolLayout extends Layout { - "symbol-placement"?: "point" | "line" | "line-center" | undefined; - "symbol-spacing"?: number | Expression | undefined; - "symbol-avoid-edges"?: boolean | undefined; - "symbol-z-order"?: "viewport-y" | "source" | undefined; - "icon-allow-overlap"?: boolean | StyleFunction | Expression | undefined; - "icon-ignore-placement"?: boolean | Expression | undefined; - "icon-optional"?: boolean | undefined; - "icon-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "icon-size"?: number | StyleFunction | Expression | undefined; - "icon-text-fit"?: "none" | "both" | "width" | "height" | undefined; - "icon-text-fit-padding"?: number[] | Expression | undefined; - "icon-image"?: string | StyleFunction | Expression | undefined; - "icon-rotate"?: number | StyleFunction | Expression | undefined; - "icon-padding"?: number | Expression | undefined; - "icon-keep-upright"?: boolean | undefined; - "icon-offset"?: number[] | StyleFunction | Expression | undefined; - "icon-anchor"?: Anchor | StyleFunction | Expression | undefined; - "icon-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-field"?: string | StyleFunction | Expression | undefined; - "text-font"?: string | string[] | Expression | undefined; - "text-size"?: number | StyleFunction | Expression | undefined; - "text-max-width"?: number | StyleFunction | Expression | undefined; - "text-line-height"?: number | Expression | undefined; - "text-letter-spacing"?: number | Expression | undefined; - "text-justify"?: "auto" | "left" | "center" | "right" | Expression | undefined; - "text-anchor"?: Anchor | StyleFunction | Expression | undefined; - "text-max-angle"?: number | Expression | undefined; - "text-rotate"?: number | StyleFunction | Expression | undefined; - "text-padding"?: number | Expression | undefined; - "text-keep-upright"?: boolean | undefined; - "text-transform"?: "none" | "uppercase" | "lowercase" | StyleFunction | Expression | undefined; - "text-offset"?: number[] | Expression | undefined; - "text-allow-overlap"?: boolean | undefined; - "text-ignore-placement"?: boolean | undefined; - "text-optional"?: boolean | undefined; - "text-radial-offset"?: number | Expression | undefined; - "text-variable-anchor"?: Anchor[] | undefined; - "text-writing-mode"?: Array<"horizontal" | "vertical"> | undefined; - "symbol-sort-key"?: number | Expression | undefined; - } - - export interface SymbolPaint { - "icon-opacity"?: number | StyleFunction | Expression | undefined; - "icon-opacity-transition"?: Transition | undefined; - "icon-color"?: string | StyleFunction | Expression | undefined; - "icon-color-transition"?: Transition | undefined; - "icon-halo-color"?: string | StyleFunction | Expression | undefined; - "icon-halo-color-transition"?: Transition | undefined; - "icon-halo-width"?: number | StyleFunction | Expression | undefined; - "icon-halo-width-transition"?: Transition | undefined; - "icon-halo-blur"?: number | StyleFunction | Expression | undefined; - "icon-halo-blur-transition"?: Transition | undefined; - "icon-translate"?: number[] | Expression | undefined; - "icon-translate-transition"?: Transition | undefined; - "icon-translate-anchor"?: "map" | "viewport" | undefined; - "text-opacity"?: number | StyleFunction | Expression | undefined; - "text-opacity-transition"?: Transition | undefined; - "text-color"?: string | StyleFunction | Expression | undefined; - "text-color-transition"?: Transition | undefined; - "text-halo-color"?: string | StyleFunction | Expression | undefined; - "text-halo-color-transition"?: Transition | undefined; - "text-halo-width"?: number | StyleFunction | Expression | undefined; - "text-halo-width-transition"?: Transition | undefined; - "text-halo-blur"?: number | StyleFunction | Expression | undefined; - "text-halo-blur-transition"?: Transition | undefined; - "text-translate"?: number[] | Expression | undefined; - "text-translate-transition"?: Transition | undefined; - "text-translate-anchor"?: "map" | "viewport" | undefined; - } - - export interface RasterLayout extends Layout {} - - export interface RasterPaint { - "raster-opacity"?: number | Expression | undefined; - "raster-opacity-transition"?: Transition | undefined; - "raster-hue-rotate"?: number | Expression | undefined; - "raster-hue-rotate-transition"?: Transition | undefined; - "raster-brightness-min"?: number | Expression | undefined; - "raster-brightness-min-transition"?: Transition | undefined; - "raster-brightness-max"?: number | Expression | undefined; - "raster-brightness-max-transition"?: Transition | undefined; - "raster-saturation"?: number | Expression | undefined; - "raster-saturation-transition"?: Transition | undefined; - "raster-contrast"?: number | Expression | undefined; - "raster-contrast-transition"?: Transition | undefined; - "raster-fade-duration"?: number | Expression | undefined; - "raster-resampling"?: "linear" | "nearest" | undefined; - } - - export interface CircleLayout extends Layout { - "circle-sort-key"?: number | Expression | undefined; - } - - export interface CirclePaint { - "circle-radius"?: number | StyleFunction | Expression | undefined; - "circle-radius-transition"?: Transition | undefined; - "circle-color"?: string | StyleFunction | Expression | undefined; - "circle-color-transition"?: Transition | undefined; - "circle-blur"?: number | StyleFunction | Expression | undefined; - "circle-blur-transition"?: Transition | undefined; - "circle-opacity"?: number | StyleFunction | Expression | undefined; - "circle-opacity-transition"?: Transition | undefined; - "circle-translate"?: number[] | Expression | undefined; - "circle-translate-transition"?: Transition | undefined; - "circle-translate-anchor"?: "map" | "viewport" | undefined; - "circle-pitch-scale"?: "map" | "viewport" | undefined; - "circle-pitch-alignment"?: "map" | "viewport" | undefined; - "circle-stroke-width"?: number | StyleFunction | Expression | undefined; - "circle-stroke-width-transition"?: Transition | undefined; - "circle-stroke-color"?: string | StyleFunction | Expression | undefined; - "circle-stroke-color-transition"?: Transition | undefined; - "circle-stroke-opacity"?: number | StyleFunction | Expression | undefined; - "circle-stroke-opacity-transition"?: Transition | undefined; - } - - export interface HeatmapLayout extends Layout {} - - export interface HeatmapPaint { - "heatmap-radius"?: number | StyleFunction | Expression | undefined; - "heatmap-radius-transition"?: Transition | undefined; - "heatmap-weight"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity-transition"?: Transition | undefined; - "heatmap-color"?: string | StyleFunction | Expression | undefined; - "heatmap-opacity"?: number | StyleFunction | Expression | undefined; - "heatmap-opacity-transition"?: Transition | undefined; - } - - export interface HillshadeLayout extends Layout {} - - export interface HillshadePaint { - "hillshade-illumination-direction"?: number | Expression | undefined; - "hillshade-illumination-anchor"?: "map" | "viewport" | undefined; - "hillshade-exaggeration"?: number | Expression | undefined; - "hillshade-exaggeration-transition"?: Transition | undefined; - "hillshade-shadow-color"?: string | Expression | undefined; - "hillshade-shadow-color-transition"?: Transition | undefined; - "hillshade-highlight-color"?: string | Expression | undefined; - "hillshade-highlight-color-transition"?: Transition | undefined; - "hillshade-accent-color"?: string | Expression | undefined; - "hillshade-accent-color-transition"?: Transition | undefined; - } -} diff --git a/types/mapbox-gl/v1/mapbox-gl-tests.ts b/types/mapbox-gl/v1/mapbox-gl-tests.ts deleted file mode 100644 index 5e85215b759677..00000000000000 --- a/types/mapbox-gl/v1/mapbox-gl-tests.ts +++ /dev/null @@ -1,1790 +0,0 @@ -import { IControl } from "mapbox-gl"; -import mapboxgl = require("mapbox-gl"); - -// These examples adapted from Mapbox's examples (https://www.mapbox.com/mapbox-gl-js/examples) - -/** - * Set API Access Token - */ -mapboxgl.accessToken = "foo"; - -/** - * Set Base API URL - */ -mapboxgl.baseApiUrl = "https://example.com"; - -/** - * Set amount of workers - */ -mapboxgl.workerCount = 3; - -/** - * Set max amount of parallel images requests - */ -mapboxgl.maxParallelImageRequests = 10; - -/** - * Clears browser storage used by this library - */ -mapboxgl.clearStorage(() => {}); - -/** - * Get RTL Text Plugin Status - */ -expectType(mapboxgl.getRTLTextPluginStatus()); - -/** - * Set RTL Text Plugin - */ -// $ExpectType void -mapboxgl.setRTLTextPlugin("https://github.com", e => {}, false); - -// $ExpectType void -mapboxgl.prewarm(); - -// $ExpectType void -mapboxgl.clearPrewarmedResources(); - -/** - * Display a Map - */ -let map = new mapboxgl.Map({ - container: "map", - style: "mapbox://styles/mapbox/streets-v8", - center: [-50, 50], - zoom: 10, - minZoom: 1, - maxZoom: 2, - minPitch: 0, - maxPitch: 60, - interactive: true, - attributionControl: true, - customAttribution: "© YourCo", - bearingSnap: 7, - scrollZoom: true, - maxBounds: [ - [-100, -90], - [100, 90], - ], - boxZoom: true, - dragRotate: false, - dragPan: true, - antialias: true, - accessToken: "some-token", - locale: { - "FullscreenControl.Enter": "Розгорнути на весь екран", - "FullscreenControl.Exit": "Вийти з повоноеранного режиму", - }, -}); - -/** - * Initialize map with bounds - */ -expectType({ - container: "map", - bounds: new mapboxgl.LngLatBounds([-100, -90, 100, 90]), - fitBoundsOptions: { - padding: 0, - offset: new mapboxgl.Point(0, 0), - linear: true, - maxZoom: 22, - easing: time => time, - }, -}); -expectType({ - container: "map", - bounds: [ - [-100, -90], - [100, 90], - ], - fitBoundsOptions: { - offset: [0, 0], - }, -}); -expectType({ - container: "map", - bounds: [-100, -90, 100, 90], -}); - -expectType({ - container: "map", - touchPitch: true, -}); - -/** - * Check `touchPitch`, `touchZoomRotate`, `scrollZoom` to accept Object - */ -expectType({ - container: "map", - touchPitch: { around: "center" }, - touchZoomRotate: { around: "center" }, - scrollZoom: { around: "center" }, -}); - -/** - * Check `dragPan` to accept Object - */ -expectType({ - container: "map", - dragPan: { - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, - }, -}); - -/** - * Create and style marker clusters - */ -map.on("load", function() { - // Add a new source from our GeoJSON data and set the - // 'cluster' option to true. - map.addSource("data", { - type: "geojson", - data: "/data.geojson", - cluster: true, - clusterMaxZoom: 14, // Max zoom to cluster points on - clusterMinPoints: 8, - clusterRadius: 50, // Radius of each cluster when clustering points (defaults to 50) - clusterProperties: { sum: ["+", ["get", "property"]] }, - filter: "something", - }); - - map.addLayer({ - id: "layer", - type: "symbol", - source: "data", - layout: { - "icon-image": "marker-15", - "text-field": ["get", "property"], - "text-max-width": { - stops: [ - [10, 2], - [12, 5], - ], - }, - }, - }); - - var layers: Array<[number, string]> = [ - [150, "#f28cb1"], - [20, "#f1f075"], - [0, "#51bbd6"], - ]; - - layers.forEach(function(layer, i) { - map.addLayer({ - id: "cluster-" + i, - type: "circle", - source: "data", - paint: { - "circle-color": layer[1], - "circle-radius": 18, - }, - filter: i == 0 - ? [">=", "point_count", layer[0]] - : ["all", [">=", "point_count", layer[0]], ["<", "point_count", layers[i - 1][0]]], - }); - }); - - // Add a layer for the clusters' count labels - map.addLayer({ - id: "cluster-count", - type: "symbol", - source: "data", - layout: { - "text-field": "{point_count}", - "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"], - "text-size": 12, - }, - }); - - /** - * Add a GeoJSON line - */ - map.addSource("route", { - type: "geojson", - data: { - type: "Feature", - properties: {}, - geometry: { - type: "LineString", - coordinates: [ - [-122.48369693756104, 37.83381888486939], - [-122.48348236083984, 37.83317489144141], - [-122.48339653015138, 37.83270036637107], - [-122.48356819152832, 37.832056363179625], - [-122.48404026031496, 37.83114119107971], - [-122.48404026031496, 37.83049717427869], - [-122.48348236083984, 37.829920943955045], - [-122.48356819152832, 37.82954808664175], - [-122.48507022857666, 37.82944639795659], - [-122.48610019683838, 37.82880236636284], - [-122.48695850372314, 37.82931081282506], - [-122.48700141906738, 37.83080223556934], - [-122.48751640319824, 37.83168351665737], - [-122.48803138732912, 37.832158048267786], - [-122.48888969421387, 37.83297152392784], - [-122.48987674713133, 37.83263257682617], - [-122.49043464660643, 37.832937629287755], - [-122.49125003814696, 37.832429207817725], - [-122.49163627624512, 37.832564787218985], - [-122.49223709106445, 37.83337825839438], - [-122.49378204345702, 37.83368330777276], - ], - }, - }, - promoteId: { original: "COUNTY" }, - }); - - map.addLayer({ - id: "route", - type: "line", - source: "route", - layout: { - "line-join": "round", - "line-cap": "round", - }, - paint: { - "line-color": "#888", - "line-width": 8, - "line-dasharray": ["step", ["zoom"], ["literal", [1, 0]], 15, ["literal", [1.75, 1]]], - }, - }); - - // Add a vector source - map.addSource("vector-source", { - type: "vector", - promoteId: { original: "COUNTY" }, - }); - - // Add a custom layer - map.addLayer({ - id: "custom", - type: "custom", - renderingMode: "3d", - onRemove: function(map, gl) { - map; // $ExpectType Map - gl; // $ExpectType WebGLRenderingContext - }, - render: function(gl, matrix) { - gl; // $ExpectType WebGLRenderingContext - matrix; // $ExpectType number[] - }, - }); -}); - -// FlyTo -map.flyTo({ - center: [0, 0], - zoom: 10, - speed: 0.5, - curve: 1, - screenSpeed: 1, - easing: function(t: number) { - return t; - }, - maxDuration: 1, -}); - -// QueryRenderedFeatures -const features = map.queryRenderedFeatures([0, 0], { layers: ["custom"], validate: false }); -features; // $ExpectType MapboxGeoJSONFeature[] - -// querySourceFeatures -const features2 = map.querySourceFeatures("some_source", { - sourceLayer: "source_layer", - filter: ["all"], - validate: null, -}); -features2; // $ExpectType MapboxGeoJSONFeature[] - -/** - * GeoJSONSource - */ -var geoJSONSourceObj = new mapboxgl.GeoJSONSource({ - data: { - type: "FeatureCollection", - features: [ - { - type: "Feature", - properties: null, - geometry: { - type: "Point", - coordinates: [-50, 0], - }, - }, - ], - }, -}); -map.addSource("some id", geoJSONSourceObj); // add -map.removeSource("some id"); // remove - -/** - * ImageSource - */ -var imageSourceObj = new mapboxgl.ImageSource({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", imageSourceObj); // add -map.removeSource("some id"); // remove - -imageSourceObj.updateImage({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); - -imageSourceObj.setCoordinates([ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], -]); - -/** - * Video Source - */ -var videoSourceObj = new mapboxgl.VideoSource({ - urls: ["/blah.mp4", "/blah.webm"], - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", videoSourceObj); // add -map.removeSource("some id"); // remove - -/** - * Vector Source - */ -const vectorSource = map.getSource("tile-source") as mapboxgl.VectorSourceImpl; -// $ExpectType VectorSourceImpl -vectorSource.setTiles(["a", "b"]); -// $ExpectType VectorSourceImpl -vectorSource.setUrl("https://github.com"); - -/** - * Add Raster Source /// made URL optional to allow only tiles. - */ -map.addSource("radar", { - type: "raster", - tiles: [ - "https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WmsServer?bbox={bbox-epsg-3857}&service=WMS&request=GetMap&version=1.3.0&layers=1&styles=&format=image/png&transparent=true&height=256&width=256&crs=EPSG:3857", - ], - tileSize: 256, -}); - -map.addLayer({ - id: "radar", - type: "raster", - source: "radar", - paint: {}, -}); - -/** - * Manipulate feature state - */ -let featureIdentifier = { - id: 1337, - source: "source-id", - sourceLayer: "liam-was-here", -}; -expectType(featureIdentifier); -map.setFeatureState(featureIdentifier, { someState: true, someOtherState: 123 }); -map.getFeatureState(featureIdentifier); -map.removeFeatureState(featureIdentifier, "someState"); -map.removeFeatureState(featureIdentifier); - -/** - * Popup - */ -const popupOptions: mapboxgl.PopupOptions = { - closeOnClick: false, - closeOnMove: true, - closeButton: true, - focusAfterOpen: true, - anchor: "top-right", - offset: { - top: [0, 0] as [number, number], - bottom: [25, -50] as [number, number], - }, - className: "custom-class", - maxWidth: "400px", -}; - -const popup = new mapboxgl.Popup(popupOptions) - .setLngLat([-50, 50]) - .trackPointer() - .setHTML("

Hello World!

") - .setMaxWidth("none") - .addTo(map); -popup.getMaxWidth(); -popup.getElement(); // $ExpectType HTMLElement -popup.addClassName("class1"); -popup.removeClassName("class2"); -popup.toggleClassName("class3"); -// $ExpectType Popup -popup.setOffset([10, 20]); - -/** - * Add an image - */ -var mapStyle: mapboxgl.Style = { - version: 8, - name: "Dark", - sources: { - mapbox: { - type: "vector", - url: "mapbox://mapbox.mapbox-streets-v6", - }, - overlay: { - type: "image", - url: "/mapbox-gl-js/assets/radar.gif", - coordinates: [ - [-50, 40], - [0, 40], - [0, 0], - [-50, 0], - ], - }, - }, - sprite: "mapbox://sprites/mapbox/dark-v8", - glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", - layers: [ - { - id: "background", - type: "background", - paint: { "background-color": "#111" }, - }, - { - id: "water", - source: "mapbox", - "source-layer": "water", - type: "fill", - paint: { "fill-color": "#2c2c2c" }, - }, - { - id: "boundaries", - source: "mapbox", - "source-layer": "admin", - type: "line", - paint: { "line-color": "#797979", "line-dasharray": [2, 2, 6, 2] }, - filter: ["all", ["==", "maritime", 0]], - }, - { - id: "overlay", - source: "overlay", - type: "raster", - paint: { "raster-opacity": 0.85 }, - }, - { - id: "cities", - source: "mapbox", - "source-layer": "place_label", - type: "symbol", - layout: { - "text-field": "{name_en}", - "text-font": ["DIN Offc Pro Bold", "Arial Unicode MS Bold"], - "text-size": { - stops: [ - [4, 9], - [6, 12], - ], - }, - }, - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - { - id: "states", - source: "mapbox", - "source-layer": "state_label", - type: "symbol", - layout: { - "text-transform": "uppercase", - "text-field": "{name_en}", - "text-font": [ - "step", - ["zoom"], - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - 8, - [ - "step", - ["get", "symbolrank"], - ["literal", ["DIN Offc Pro Medium", "Arial Unicode MS Regular"]], - 11, - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - ], - ], - "text-justify": [ - "step", - ["zoom"], - [ - "match", - ["get", "text_anchor"], - ["bottom", "top"], - "center", - ["left", "bottom-left", "top-left"], - "left", - ["right", "bottom-right", "top-right"], - "right", - "center", - ], - 8, - "center", - ], - "text-letter-spacing": 0.15, - "text-max-width": 7, - "text-size": { - stops: [ - [4, 10], - [6, 14], - ], - }, - }, - filter: [">=", "area", 80000], - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - ], -}; - -/** - * Add video - */ -var videoStyle: mapboxgl.Style = { - version: 8, - sources: { - satellite: { - type: "raster", - url: "mapbox://mapbox.satellite", - tileSize: 256, - }, - video: { - type: "video", - urls: ["drone.mp4", "drone.webm"], - coordinates: [ - [-122.51596391201019, 37.56238816766053], - [-122.51467645168304, 37.56410183312965], - [-122.51309394836426, 37.563391708549425], - [-122.51423120498657, 37.56161849366671], - ], - }, - }, - layers: [ - { - id: "background", - type: "background", - paint: { - "background-color": "rgb(4,7,14)", - }, - }, - { - id: "satellite", - type: "raster", - source: "satellite", - }, - { - id: "video", - type: "raster", - source: "video", - }, - ], -}; - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: mapStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: videoStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - hash: "customHash", -}); - -/** - * Marker - */ -let marker = new mapboxgl.Marker(undefined, { - element: undefined, - offset: [10, 0], - anchor: "bottom-right", - color: "green", - draggable: false, - clickTolerance: 10, - rotation: 15, - rotationAlignment: "map", - pitchAlignment: "viewport", - scale: 5.5, -}) - .setLngLat([-50, 50]) - .setPitchAlignment("map") - .setRotationAlignment("viewport") - .addTo(map); - -// $ExpectType Alignment -marker.getPitchAlignment(); - -// $ExpectType Alignment -marker.getRotationAlignment(); - -marker.remove(); - -/* - * LngLatBounds - */ -let bool: boolean; -let bounds = new mapboxgl.LngLatBounds(); -bool = bounds.isEmpty(); -expectType(bounds.contains([37, 50])); - -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLat(45, 30)); -// $ExpectType LngLatBounds -bounds.extend({ lng: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend({ lon: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend([45, 30]); -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLatBounds()); -// $ExpectType LngLatBounds -bounds.extend([ - [45, 30], - [60, 60], -]); -// $ExpectType LngLatBounds -bounds.extend([45, 30, 60, 60]); - -// controls -// $ExpectType IControl -new mapboxgl.Control() as IControl; -// $ExpectType IControl -new mapboxgl.AttributionControl() as IControl; - -/* - * GeolocateControl - */ -const geolocateControl = new mapboxgl.GeolocateControl({ showAccuracyCircle: true }); - -/* - * AttributionControl - */ -let attributionControl = new mapboxgl.AttributionControl({ compact: false, customAttribution: "© YourCo" }); -attributionControl.on("click", () => {}); - -/* - * FullscreenControl - */ -new mapboxgl.FullscreenControl(); -new mapboxgl.FullscreenControl(null); -new mapboxgl.FullscreenControl({}); -new mapboxgl.FullscreenControl({ container: document.querySelector("body") }); - -// $ExpectType boolean -map.hasControl(attributionControl); - -declare var lnglat: mapboxgl.LngLat; -declare var lnglatlike: mapboxgl.LngLatLike; -declare var lnglatboundslike: mapboxgl.LngLatBoundsLike; -declare var mercatorcoordinate: mapboxgl.MercatorCoordinate; -declare var pointlike: mapboxgl.PointLike; - -function expectType(value: T) { - return value; -} - -// prettier-ignore -interface EitherType { -
(a: A): A; - (a: A, b: B): A | B; - (a: A, b: B, c: C): A | B | C; - (a: A, b: B, c: C, d: D): A | B | C | D; - (a: A, b: B, c: C, d: D, e: E): A | B | C | D | E; - (a: A, b: B, c: C, d: D, e: E, f: F): A | B | C | D | E | F; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G): A | B | C | D | E | F | G; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): A | B | C | D | E | F | G | H; - ( - a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - ): A | B | C | D | E | F | G | H | I; - /* Add more as needed */ -} - -/** - * Takes a variable amount of arguments and returns a new - * type that is a union of all the provided argument types. Useful to test properties - * that accept multiple types - */ -const eitherType: EitherType = () => { - /* let the compiler handle things */ -}; - -/* - * LngLatLike - */ - -expectType(new mapboxgl.LngLat(0, 0)); -expectType([0, 0]); -expectType({ lng: 0, lat: 0 }); -expectType({ lon: 0, lat: 0 }); - -/* - * LngLat - */ - -new mapboxgl.LngLat(0, 0); -expectType(mapboxgl.LngLat.convert(lnglatlike)); -expectType(new mapboxgl.LngLat(0, 0).distanceTo(new mapboxgl.LngLat(0, 0))); - -/* - * LngLatBoundsLike - */ - -expectType([lnglatlike, lnglatlike]); -expectType([0, 0, 1, 1]); -expectType(new mapboxgl.LngLatBounds()); - -/* - * LngLatBounds - */ - -new mapboxgl.LngLatBounds(); -new mapboxgl.LngLatBounds([0, 0, 1, 1]); -new mapboxgl.LngLatBounds([lnglatlike, lnglatlike]); -new mapboxgl.LngLatBounds(lnglat, lnglat); -new mapboxgl.LngLatBounds(lnglatlike, lnglatlike); -expectType(mapboxgl.LngLatBounds.convert(lnglatboundslike)); - -/* - * PointLike - */ - -expectType(new mapboxgl.Point(0, 0)); -expectType([0, 0]); - -/* - * Point - */ - -new mapboxgl.Point(0, 0); -expectType(mapboxgl.Point.convert(pointlike)); - -/* - * MercatorCoordinate - */ - -new mapboxgl.MercatorCoordinate(0, 0); -new mapboxgl.MercatorCoordinate(0, 0, 0); -mercatorcoordinate.toAltitude(); // $ExpectType number -mercatorcoordinate.toLngLat(); // $ExpectType LngLat -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike); // $ExpectType MercatorCoordinate -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike, 0); // $ExpectType MercatorCoordinate -mercatorcoordinate.meterInMercatorCoordinateUnits(); // $ExpectType number - -/* - * TransformRequestFunction - */ - -expectType((url: string) => ({ url })); -expectType((url: string, resourceType: mapboxgl.ResourceType) => ({ - url, - credentials: "same-origin", - headers: { "Accept-Encoding": "compress" }, - method: "POST", - collectResourceTiming: true, -})); - -/* - * Map - */ - -let padding: mapboxgl.PaddingOptions = { - top: 0, - bottom: 0, - left: 0, - right: 0, -}; -let animOpts: mapboxgl.AnimationOptions = { - essential: true, -}; -let cameraOpts: mapboxgl.CameraOptions = { - around: lnglatlike, - center: lnglatlike, - bearing: 0, - pitch: 0, - zoom: 0, -}; -let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = { - offset: pointlike, - maxZoom: 10, - padding, - ...cameraOpts, -}; - -expectType(map.cameraForBounds(lnglatboundslike)); -expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts)); - -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts, { key: "value" })); - -// $ExpectType void -map.triggerRepaint(); - -// $ExpectType PaddingOptions -map.getPadding(); - -// $ExpectType Map -map.setPadding({ top: 10, bottom: 20, left: 30, right: 40 }, { myData: "MY DATA" }); - -map.setPaintProperty("layerId", "layerName", null, { validate: true }); -map.setPaintProperty("layerId", "layerName", null, { validate: false }); -map.setPaintProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setPaintProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLayoutProperty("layerId", "layerName", null, { validate: true }); -map.setLayoutProperty("layerId", "layerName", null, { validate: false }); -map.setLayoutProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setLayoutProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: true }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: false }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, {}); -// @ts-expect-error -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { some_option: "some_string" }); - -// $ExpectType boolean -map.showPadding; -map.showPadding = false; - -expectType(map.setFilter("layerId", true)); -expectType(map.setFilter("layerId", false)); - -map.setFilter("layerId", true, { validate: true }); -map.setFilter("layerId", true, { validate: null }); -map.setFilter("layerId", true, {}); -// @ts-expect-error -map.setFilter("layerId", true, { some_option: "some_string" }); - -// $ExpectType Map -map.setMinZoom(5); -// $ExpectType Map -map.setMaxZoom(10); -// $ExpectType Map -map.setMinZoom(null); -// $ExpectType Map -map.setMinZoom(); -// $ExpectType Map -map.setMaxZoom(null); -// $ExpectType Map -map.setMaxZoom(); - -// $ExpectType number -map.getMinZoom(); -// $ExpectType number -map.getMaxZoom(); - -// $ExpectType Map -map.setMinPitch(5); -// $ExpectType Map -map.setMaxPitch(10); -// $ExpectType Map -map.setMinPitch(null); -// $ExpectType Map -map.setMinPitch(); -// $ExpectType Map -map.setMaxPitch(null); -// $ExpectType Map -map.setMaxPitch(); -// $ExpectType Map -map.resetNorthPitch(animOpts); - -// $ExpectType number -map.getMinPitch(); -// $ExpectType number -map.getMaxPitch(); - -/* - * Map Events - */ - -// General events -expectType( - map.on("load", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -// $ExpectType Map -map.on("idle", ev => { - ev; // $ExpectType MapboxEvent & EventData -}); -expectType( - map.on("remove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("render", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("resize", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Error event -expectType( - map.on("error", ev => { - expectType(ev); - expectType(ev.error); - expectType(ev.originalEvent); - }), -); - -// Mouse events -expectType( - map.on("mousedown", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseup", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("click", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("dblclick", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mousemove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseover", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseout", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("contextmenu", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Touch events -expectType( - map.on("touchcancel", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchmove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchend", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchstart", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Context events -expectType( - map.on("webglcontextlost", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("webglcontextrestored", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Data events -expectType( - map.on("dataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("data", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("tiledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("sourcedataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("sourcedata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("styledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); -expectType( - map.on("styledata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); - -// Layer events -expectType( - map.on("click", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("dblclick", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousedown", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseup", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousemove", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseenter", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseleave", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseover", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseout", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("contextmenu", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.on("touchstart", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchend", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchcancel", "text", ev => { - expectType(ev); - expectType(ev.features); - }), -); - -/* - * Expression - */ -expectType(["id"]); -expectType(["get", "property"]); -expectType([ - "format", - ["concat", ["get", "name"], "\n"], - {}, - ["concat", ["get", "area"], "foobar", { "font-scale": 0.8 }], -]); -const expression = expectType(["coalesce", ["get", "property"], ["get", "property"]]); - -/* - * ScrollZoomHandler - */ -// $ExpectType void -new mapboxgl.Map().scrollZoom.setZoomRate(1); - -// $ExpectType void -new mapboxgl.Map().scrollZoom.setWheelZoomRate(1); -new mapboxgl.Map().scrollZoom.enable({ around: "center" }); - -const touchPitchHandler = new mapboxgl.TouchPitchHandler(map); -// $ExpectType void -touchPitchHandler.enable(); -touchPitchHandler.enable({ around: "center" }); -// $ExpectType boolean -touchPitchHandler.isActive(); -// $ExpectType boolean -touchPitchHandler.isEnabled(); -// $ExpectType void -touchPitchHandler.disable(); - -new mapboxgl.Map().touchPitch = touchPitchHandler; - -/** - * `dragPan` - */ -// $ExpectType void -new mapboxgl.Map().dragPan.enable({ - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, -}); - -/** - * `touchZoomRotate` - */ -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({ - around: "center", -}); -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable(); - -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({}); - -/* - * Visibility - */ -expectType("visible"); -expectType("none"); - -/* - * Transition - */ - -expectType({ duration: 0 }); -expectType({ delay: 0 }); -const transition = expectType({ duration: 0, delay: 0 }); - -/* - * StyleFunction - */ - -expectType({ base: 1, type: "categorical" }); -const styleFunction = expectType({ - base: 1, - type: "exponential", - default: 0, - stops: [ - [1, 2], - [3, 4], - ], -}); - -/* - * Anchor - */ - -expectType( - eitherType("center", "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right"), -); -const anchor: mapboxgl.Anchor = "center"; - -/* - * Layouts and Paint options - */ - -const backgroundLayout: mapboxgl.BackgroundLayout = { - visibility: eitherType("visible", "none"), -}; - -const backgroundPaint: mapboxgl.BackgroundPaint = { - "background-color": eitherType("#000", expression), - "background-color-transition": transition, - "background-pattern": "pattern", - "background-pattern-transition": transition, - "background-opacity": eitherType(0, expression), - "background-opacity-transition": transition, -}; - -const fillLayout: mapboxgl.FillLayout = { - "fill-sort-key": eitherType(0, expression), -}; - -const fillPaint: mapboxgl.FillPaint = { - "fill-antialias": eitherType(false, expression), - "fill-opacity": eitherType(0, styleFunction, expression), - "fill-opacity-transition": transition, - "fill-color": eitherType("#000", styleFunction, expression), - "fill-color-transition": transition, - "fill-outline-color": eitherType("#000", styleFunction, expression), - "fill-outline-color-transition": transition, - "fill-translate": [1], - "fill-translate-transition": transition, - "fill-translate-anchor": eitherType("map", "viewport"), - "fill-pattern": eitherType("#000", expression), - "fill-pattern-transition": transition, -}; - -const fillExtrusionLayout: mapboxgl.FillExtrusionLayout = { - visibility: eitherType("visible", "none"), -}; - -const fillExtrusionPaint: mapboxgl.FillExtrusionPaint = { - "fill-extrusion-opacity": eitherType(0, expression), - "fill-extrusion-opacity-transition": transition, - "fill-extrusion-color": eitherType("#000", styleFunction, expression), - "fill-extrusion-color-transition": transition, - "fill-extrusion-translate": eitherType([0], expression), - "fill-extrusion-translate-transition": transition, - "fill-extrusion-translate-anchor": eitherType("map", "viewport"), - "fill-extrusion-pattern": eitherType("#000", expression), - "fill-extrusion-pattern-transition": transition, - "fill-extrusion-height": eitherType(0, styleFunction, expression), - "fill-extrusion-height-transition": transition, - "fill-extrusion-base": eitherType(0, styleFunction, expression), - "fill-extrusion-base-transition": transition, - "fill-extrusion-vertical-gradient": false, -}; - -const lineLayout: mapboxgl.LineLayout = { - "line-cap": eitherType("butt", "round", "square"), - "line-join": eitherType("bevel", "round", "miter", expression), - "line-miter-limit": eitherType(0, expression), - "line-round-limit": eitherType(0, expression), - "line-sort-key": eitherType(0, expression), -}; - -const linePaint: mapboxgl.LinePaint = { - "line-opacity": eitherType(0, styleFunction, expression), - "line-opacity-transition": transition, - "line-color": eitherType("#000", styleFunction, expression), - "line-color-transition": transition, - "line-translate": eitherType([0], expression), - "line-translate-transition": transition, - "line-translate-anchor": eitherType("map", "viewport"), - "line-width": eitherType(0, styleFunction, expression), - "line-width-transition": transition, - "line-gap-width": eitherType(0, styleFunction, expression), - "line-gap-width-transition": transition, - "line-offset": eitherType(0, styleFunction, expression), - "line-offset-transition": transition, - "line-blur": eitherType(0, styleFunction, expression), - "line-blur-transition": transition, - "line-dasharray": eitherType([0], expression), - "line-dasharray-transition": transition, - "line-pattern": eitherType("#000", expression), - "line-pattern-transition": transition, - "line-gradient": expression, -}; - -const symbolLayout: mapboxgl.SymbolLayout = { - "symbol-placement": eitherType("point", "line", "line-center"), - "symbol-spacing": eitherType(0, expression), - "symbol-avoid-edges": false, - "symbol-z-order": eitherType("viewport-y", "source"), - "icon-allow-overlap": eitherType(false, styleFunction, expression), - "icon-ignore-placement": eitherType(false, expression), - "icon-optional": false, - "icon-rotation-alignment": eitherType("map", "viewport", "auto"), - "icon-size": eitherType(0, styleFunction, expression), - "icon-text-fit": eitherType("none", "both", "width", "height"), - "icon-text-fit-padding": eitherType([0], expression), - "icon-image": eitherType("#000", styleFunction, expression), - "icon-rotate": eitherType(0, styleFunction, expression), - "icon-padding": eitherType(0, expression), - "icon-keep-upright": false, - "icon-offset": eitherType([0], styleFunction, expression), - "icon-anchor": eitherType("center", styleFunction, expression), - "icon-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-rotation-alignment": eitherType("map", "viewport", "auto"), - "text-field": eitherType("#000", styleFunction, expression), - "text-font": eitherType("arial", ["arial"], expression), - "text-size": eitherType(0, styleFunction, expression), - "text-max-width": eitherType(0, styleFunction, expression), - "text-line-height": eitherType(0, expression), - "text-letter-spacing": eitherType(0, expression), - "text-justify": eitherType("auto", "left", "center", "right", expression), - "text-anchor": eitherType("center", styleFunction, expression), - "text-max-angle": eitherType(0, expression), - "text-rotate": eitherType(0, styleFunction, expression), - "text-padding": eitherType(0, expression), - "text-keep-upright": false, - "text-transform": eitherType("none", "uppercase", "lowercase", styleFunction, expression), - "text-offset": eitherType([0], expression), - "text-allow-overlap": false, - "text-ignore-placement": false, - "text-optional": false, - "text-radial-offset": eitherType(0, expression), - "text-variable-anchor": [anchor], - "text-writing-mode": eitherType< - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical"> - >(["horizontal"], ["vertical"], ["horizontal", "vertical"]), - "symbol-sort-key": eitherType(0, expression), -}; - -const symbolPaint: mapboxgl.SymbolPaint = { - "icon-opacity": eitherType(0, styleFunction, expression), - "icon-opacity-transition": transition, - "icon-color": eitherType("#000", styleFunction, expression), - "icon-color-transition": transition, - "icon-halo-color": eitherType("#000", styleFunction, expression), - "icon-halo-color-transition": transition, - "icon-halo-width": eitherType(0, styleFunction, expression), - "icon-halo-width-transition": transition, - "icon-halo-blur": eitherType(0, styleFunction, expression), - "icon-halo-blur-transition": transition, - "icon-translate": eitherType([0], expression), - "icon-translate-transition": transition, - "icon-translate-anchor": eitherType("map", "viewport"), - "text-opacity": eitherType(0, styleFunction, expression), - "text-opacity-transition": transition, - "text-color": eitherType("#000", styleFunction, expression), - "text-color-transition": transition, - "text-halo-color": eitherType("#000", styleFunction, expression), - "text-halo-color-transition": transition, - "text-halo-width": eitherType(0, styleFunction, expression), - "text-halo-width-transition": transition, - "text-halo-blur": eitherType(0, styleFunction, expression), - "text-halo-blur-transition": transition, - "text-translate": eitherType([0], expression), - "text-translate-transition": transition, - "text-translate-anchor": eitherType("map", "viewport"), -}; - -const rasterLayout: mapboxgl.RasterLayout = { - visibility: eitherType("visible", "none"), -}; - -const rasterPaint: mapboxgl.RasterPaint = { - "raster-opacity": eitherType(0, expression), - "raster-opacity-transition": transition, - "raster-hue-rotate": eitherType(0, expression), - "raster-hue-rotate-transition": transition, - "raster-brightness-min": eitherType(0, expression), - "raster-brightness-min-transition": transition, - "raster-brightness-max": eitherType(0, expression), - "raster-brightness-max-transition": transition, - "raster-saturation": eitherType(0, expression), - "raster-saturation-transition": transition, - "raster-contrast": eitherType(0, expression), - "raster-contrast-transition": transition, - "raster-fade-duration": eitherType(0, expression), - "raster-resampling": eitherType("linear", "nearest"), -}; - -const circleLayout: mapboxgl.CircleLayout = { - visibility: eitherType("visible", "none"), - "circle-sort-key": eitherType(0, expression), -}; - -const circlePaint: mapboxgl.CirclePaint = { - "circle-radius": eitherType(0, styleFunction, expression), - "circle-radius-transition": transition, - "circle-color": eitherType("#000", styleFunction, expression), - "circle-color-transition": transition, - "circle-blur": eitherType(0, styleFunction, expression), - "circle-blur-transition": transition, - "circle-opacity": eitherType(0, styleFunction, expression), - "circle-opacity-transition": transition, - "circle-translate": eitherType([0], expression), - "circle-translate-transition": transition, - "circle-translate-anchor": eitherType("map", "viewport"), - "circle-pitch-scale": eitherType("map", "viewport"), - "circle-pitch-alignment": eitherType("map", "viewport"), - "circle-stroke-width": eitherType(0, styleFunction, expression), - "circle-stroke-width-transition": transition, - "circle-stroke-color": eitherType("#000", styleFunction, expression), - "circle-stroke-color-transition": transition, - "circle-stroke-opacity": eitherType(0, styleFunction, expression), - "circle-stroke-opacity-transition": transition, -}; - -const heatmapLayout: mapboxgl.HeatmapLayout = { - visibility: eitherType("visible", "none"), -}; - -const heatmapPaint: mapboxgl.HeatmapPaint = { - "heatmap-radius": eitherType(0, styleFunction, expression), - "heatmap-radius-transition": transition, - "heatmap-weight": eitherType(0, styleFunction, expression), - "heatmap-intensity": eitherType(0, styleFunction, expression), - "heatmap-intensity-transition": transition, - "heatmap-color": eitherType("#000", styleFunction, expression), - "heatmap-opacity": eitherType(0, styleFunction, expression), - "heatmap-opacity-transition": transition, -}; - -const hillshadeLayout: mapboxgl.HillshadeLayout = { - visibility: eitherType("visible", "none"), -}; - -const hillshadePaint: mapboxgl.HillshadePaint = { - "hillshade-illumination-direction": eitherType(0, expression), - "hillshade-illumination-anchor": eitherType("map", "viewport"), - "hillshade-exaggeration": eitherType(0, expression), - "hillshade-exaggeration-transition": transition, - "hillshade-shadow-color": eitherType("#000", expression), - "hillshade-shadow-color-transition": transition, - "hillshade-highlight-color": eitherType("#000", expression), - "hillshade-highlight-color-transition": transition, - "hillshade-accent-color": eitherType("#000", expression), - "hillshade-accent-color-transition": transition, -}; - -/* Make sure every layout has all properties optional */ -eitherType< - mapboxgl.BackgroundLayout, - mapboxgl.FillLayout, - mapboxgl.FillExtrusionLayout, - mapboxgl.LineLayout, - mapboxgl.SymbolLayout, - mapboxgl.RasterLayout, - mapboxgl.CircleLayout, - mapboxgl.HeatmapLayout, - mapboxgl.HillshadeLayout ->({}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* Make sure every paint has all properties optional */ -eitherType< - mapboxgl.BackgroundPaint, - mapboxgl.FillPaint, - mapboxgl.FillExtrusionPaint, - mapboxgl.LinePaint, - mapboxgl.SymbolPaint, - mapboxgl.RasterPaint, - mapboxgl.CirclePaint, - mapboxgl.HeatmapPaint, - mapboxgl.HillshadePaint ->({}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* - * AnyLayout - */ -expectType( - eitherType( - backgroundLayout, - fillLayout, - fillExtrusionLayout, - lineLayout, - symbolLayout, - rasterLayout, - circleLayout, - heatmapLayout, - hillshadeLayout, - ), -); - -/* - * AnyPaint - */ -expectType( - eitherType( - backgroundPaint, - fillPaint, - fillExtrusionPaint, - linePaint, - symbolPaint, - rasterPaint, - circlePaint, - heatmapPaint, - hillshadePaint, - ), -); - -/* - * Make sure layer gets proper Paint, corresponding to layer's type - */ - -expectType({ id: "unique", type: "background", paint: { "background-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "background", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "fill", paint: { "fill-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "fill", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "line", paint: { "line-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "line", paint: { "fill-opacity": 1 } }); - -/** - * Test map.addImage() - */ - -// HTMLImageElement -const fooHTMLImageElement = document.createElement("img"); -map.addImage("foo", fooHTMLImageElement); - -// ImageData -const fooImageData = new ImageData(8, 8); -map.addImage("foo", fooImageData); - -// ImageData like -const fooImageDataLike1 = { - width: 10, - height: 10, - data: new Uint8ClampedArray(8), -}; -map.addImage("foo", fooImageDataLike1); - -const fooImageDataLike2 = { - width: 10, - height: 10, - data: new Uint8Array(8), -}; -map.addImage("foo", fooImageDataLike2); - -// ArrayBufferView -const fooArrayBufferView: ArrayBufferView = new Uint8Array(8); -map.addImage("foo", fooArrayBufferView); - -// ImageBitmap -createImageBitmap(fooHTMLImageElement).then(fooImageBitmap => { - map.addImage("foo", fooImageBitmap); -}); - -// KeyboardHandler -var keyboardHandler = new mapboxgl.KeyboardHandler(map); -// $ExpectType void -keyboardHandler.enableRotation(); -// $ExpectType void -keyboardHandler.disableRotation(); diff --git a/types/mapbox-gl/v1/package.json b/types/mapbox-gl/v1/package.json deleted file mode 100644 index 3bdbb2c5c53db1..00000000000000 --- a/types/mapbox-gl/v1/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "private": true, - "name": "@types/mapbox-gl", - "version": "1.13.9999", - "projects": [ - "https://github.com/mapbox/mapbox-gl-js" - ], - "dependencies": { - "@types/geojson": "*" - }, - "devDependencies": { - "@types/mapbox-gl": "workspace:." - }, - "owners": [ - { - "name": "Dominik Bruderer", - "githubUsername": "dobrud" - }, - { - "name": "Karl-Aksel Puulmann", - "githubUsername": "macobo" - }, - { - "name": "Dmytro Gokun", - "githubUsername": "dmytro-gokun" - }, - { - "name": "Liam Clarke", - "githubUsername": "LiamAttClarke" - }, - { - "name": "Vladimir Dashukevich", - "githubUsername": "life777" - }, - { - "name": "Marko Klopets", - "githubUsername": "mklopets" - }, - { - "name": "André Fonseca", - "githubUsername": "amxfonseca" - }, - { - "name": "Olivier Pascal", - "githubUsername": "pascaloliv" - } - ] -} diff --git a/types/mapbox-gl/v1/tsconfig.json b/types/mapbox-gl/v1/tsconfig.json deleted file mode 100644 index f69bcb46d0e49f..00000000000000 --- a/types/mapbox-gl/v1/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "module": "node16", - "lib": [ - "es6", - "dom" - ], - "strictNullChecks": true, - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "mapbox-gl-tests.ts" - ] -} diff --git a/types/mapbox-gl/v2/.eslintrc.json b/types/mapbox-gl/v2/.eslintrc.json deleted file mode 100644 index 0fe3c8d6ec5898..00000000000000 --- a/types/mapbox-gl/v2/.eslintrc.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "rules": { - "@definitelytyped/export-just-namespace": "off", - "@definitelytyped/no-any-union": "off", - "@definitelytyped/no-unnecessary-generics": "off", - "@definitelytyped/strict-export-declare-modifiers": "off", - "@typescript-eslint/no-unsafe-function-type": "off", - "@typescript-eslint/no-wrapper-object-types": "off", - "@typescript-eslint/no-empty-interface": "off", - "@typescript-eslint/naming-convention": "off", - "@typescript-eslint/consistent-type-definitions": "off" - } -} diff --git a/types/mapbox-gl/v2/.npmignore b/types/mapbox-gl/v2/.npmignore deleted file mode 100644 index 93e307400a5456..00000000000000 --- a/types/mapbox-gl/v2/.npmignore +++ /dev/null @@ -1,5 +0,0 @@ -* -!**/*.d.ts -!**/*.d.cts -!**/*.d.mts -!**/*.d.*.ts diff --git a/types/mapbox-gl/v2/index.d.ts b/types/mapbox-gl/v2/index.d.ts deleted file mode 100644 index 59c090cbc65b1b..00000000000000 --- a/types/mapbox-gl/v2/index.d.ts +++ /dev/null @@ -1,2708 +0,0 @@ -/// - -export = mapboxgl; -export as namespace mapboxgl; - -declare namespace mapboxgl { - let accessToken: string; - let version: string; - let baseApiUrl: string; - - /** - * Number of web workers instantiated on a page with GL JS maps. - * By default, it is set to half the number of CPU cores (capped at 6). - */ - let workerCount: number; - - /** - * Maximum number of images (raster tiles, sprites, icons) to load in parallel, which affects performance in raster-heavy maps. - * 16 by default. - */ - let maxParallelImageRequests: number; - - export function supported(options?: { failIfMajorPerformanceCaveat?: boolean | undefined }): boolean; - - /** - * Clears browser storage used by this library. Using this method flushes the Mapbox tile cache that is managed by this library. - * Tiles may still be cached by the browser in some cases. - */ - export function clearStorage(callback?: (err?: Error) => void): void; - - export function setRTLTextPlugin(pluginURL: string, callback: (error: Error) => void, deferred?: boolean): void; - export function getRTLTextPluginStatus(): PluginStatus; - - /** - * Initializes resources like WebWorkers that can be shared across maps to lower load - * times in some situations. `mapboxgl.workerUrl` and `mapboxgl.workerCount`, if being - * used, must be set before `prewarm()` is called to have an effect. - * - * By default, the lifecycle of these resources is managed automatically, and they are - * lazily initialized when a Map is first created. By invoking `prewarm()`, these - * resources will be created ahead of time, and will not be cleared when the last Map - * is removed from the page. This allows them to be re-used by new Map instances that - * are created later. They can be manually cleared by calling - * `mapboxgl.clearPrewarmedResources()`. This is only necessary if your web page remains - * active but stops using maps altogether. - * - * This is primarily useful when using GL-JS maps in a single page app, wherein a user - * would navigate between various views that can cause Map instances to constantly be - * created and destroyed. - */ - export function prewarm(): void; - - /** - * Clears up resources that have previously been created by `mapboxgl.prewarm()`. - * Note that this is typically not necessary. You should only call this function - * if you expect the user of your app to not return to a Map view at any point - * in your application. - */ - export function clearPrewarmedResources(): void; - - type PluginStatus = "unavailable" | "loading" | "loaded" | "error"; - - type LngLatLike = [number, number] | LngLat | { lng: number; lat: number } | { lon: number; lat: number }; - - type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number] | LngLatLike; - type PointLike = Point | [number, number]; - type Offset = number | PointLike | { [_: string]: PointLike }; - - type ExpressionName = - // Types - | "array" - | "boolean" - | "collator" - | "format" - | "literal" - | "number" - | "number-format" - | "object" - | "string" - | "image" - | "to-boolean" - | "to-color" - | "to-number" - | "to-string" - | "typeof" - // Feature data - | "feature-state" - | "geometry-type" - | "id" - | "line-progress" - | "properties" - // Lookup - | "at" - | "get" - | "has" - | "in" - | "index-of" - | "length" - | "slice" - // Decision - | "!" - | "!=" - | "<" - | "<=" - | "==" - | ">" - | ">=" - | "all" - | "any" - | "case" - | "match" - | "coalesce" - | "within" - // Ramps, scales, curves - | "interpolate" - | "interpolate-hcl" - | "interpolate-lab" - | "step" - // Variable binding - | "let" - | "var" - // String - | "concat" - | "downcase" - | "is-supported-script" - | "resolved-locale" - | "upcase" - // Color - | "rgb" - | "rgba" - | "to-rgba" - // Math - | "-" - | "*" - | "/" - | "%" - | "^" - | "+" - | "abs" - | "acos" - | "asin" - | "atan" - | "ceil" - | "cos" - | "e" - | "floor" - | "ln" - | "ln2" - | "log10" - | "log2" - | "max" - | "min" - | "pi" - | "round" - | "sin" - | "sqrt" - | "tan" - // Zoom, Heatmap - | "zoom" - | "heatmap-density"; - - type Expression = [ExpressionName, ...any[]]; - - type Anchor = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; - - type DragPanOptions = { - linearity?: number; - easing?: (t: number) => number; - deceleration?: number; - maxSpeed?: number; - }; - - type InteractiveOptions = { around?: "center" }; - - /** - * Map - */ - export class Map extends Evented { - constructor(options?: MapboxOptions); - - addControl( - control: Control | IControl, - position?: "top-right" | "top-left" | "bottom-right" | "bottom-left", - ): this; - - removeControl(control: Control | IControl): this; - - /** - * Checks if a control exists on the map. - * - * @param {IControl} control The {@link IControl} to check. - * @returns {boolean} True if map contains control. - * @example - */ - hasControl(control: IControl): boolean; - - resize(eventData?: EventData): this; - - getBounds(): LngLatBounds; - - getMaxBounds(): LngLatBounds | null; - - setMaxBounds(lnglatbounds?: LngLatBoundsLike): this; - - setMinZoom(minZoom?: number | null): this; - - getMinZoom(): number; - - setMaxZoom(maxZoom?: number | null): this; - - getMaxZoom(): number; - - setMinPitch(minPitch?: number | null): this; - - getMinPitch(): number; - - setMaxPitch(maxPitch?: number | null): this; - - getMaxPitch(): number; - - getRenderWorldCopies(): boolean; - - setRenderWorldCopies(renderWorldCopies?: boolean): this; - - project(lnglat: LngLatLike): mapboxgl.Point; - - unproject(point: PointLike): mapboxgl.LngLat; - - isMoving(): boolean; - - isZooming(): boolean; - - isRotating(): boolean; - - /** - * Returns an array of GeoJSON Feature objects representing visible features that satisfy the query parameters. - * - * The properties value of each returned feature object contains the properties of its source feature. For GeoJSON sources, only string and numeric property values are supported (i.e. null, Array, and Object values are not supported). - * - * Each feature includes top-level layer, source, and sourceLayer properties. The layer property is an object representing the style layer to which the feature belongs. Layout and paint properties in this object contain values which are fully evaluated for the given zoom level and feature. - * - * Only features that are currently rendered are included. Some features will not be included, like: - * - * - Features from layers whose visibility property is "none". - * - Features from layers whose zoom range excludes the current zoom level. - * - Symbol features that have been hidden due to text or icon collision. - * - * Features from all other layers are included, including features that may have no visible contribution to the rendered result; for example, because the layer's opacity or color alpha component is set to 0. - * - * The topmost rendered feature appears first in the returned array, and subsequent features are sorted by descending z-order. Features that are rendered multiple times (due to wrapping across the antimeridian at low zoom levels) are returned only once (though subject to the following caveat). - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param pointOrBox The geometry of the query region: either a single point or southwest and northeast points describing a bounding box. Omitting this parameter (i.e. calling Map#queryRenderedFeatures with zero arguments, or with only a options argument) is equivalent to passing a bounding box encompassing the entire map viewport. - * @param options - */ - queryRenderedFeatures( - pointOrBox?: PointLike | [PointLike, PointLike], - options?: { layers?: string[] | undefined; filter?: any[] | undefined } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - /** - * Returns an array of GeoJSON Feature objects representing features within the specified vector tile or GeoJSON source that satisfy the query parameters. - * - * In contrast to Map#queryRenderedFeatures, this function returns all features matching the query parameters, whether or not they are rendered by the current style (i.e. visible). The domain of the query includes all currently-loaded vector tiles and GeoJSON source tiles: this function does not check tiles outside the currently visible viewport. - * - * Because features come from tiled vector data or GeoJSON data that is converted to tiles internally, feature geometries may be split or duplicated across tile boundaries and, as a result, features may appear multiple times in query results. For example, suppose there is a highway running through the bounding rectangle of a query. The results of the query will be those parts of the highway that lie within the map tiles covering the bounding rectangle, even if the highway extends into other tiles, and the portion of the highway within each map tile will be returned as a separate feature. Similarly, a point feature near a tile boundary may appear in multiple tiles due to tile buffering. - * - * @param sourceID The ID of the vector tile or GeoJSON source to query. - * @param parameters - */ - querySourceFeatures( - sourceID: string, - parameters?: { - sourceLayer?: string | undefined; - filter?: any[] | undefined; - } & FilterOptions, - ): MapboxGeoJSONFeature[]; - - setStyle( - style: mapboxgl.Style | string, - options?: { diff?: boolean | undefined; localIdeographFontFamily?: string | undefined }, - ): this; - - getStyle(): mapboxgl.Style; - - isStyleLoaded(): boolean; - - addSource(id: string, source: AnySourceData): this; - - isSourceLoaded(id: string): boolean; - - areTilesLoaded(): boolean; - - removeSource(id: string): this; - - getSource(id: string): AnySourceImpl; - - addImage( - name: string, - image: - | HTMLImageElement - | ArrayBufferView - | { width: number; height: number; data: Uint8Array | Uint8ClampedArray } - | ImageData - | ImageBitmap, - options?: { - pixelRatio?: number | undefined; - sdf?: boolean | undefined; - stretchX?: Array<[number, number]> | undefined; - stretchY?: Array<[number, number]> | undefined; - content?: [number, number, number, number] | undefined; - }, - ): void; - - updateImage( - name: string, - image: - | HTMLImageElement - | ArrayBufferView - | { width: number; height: number; data: Uint8Array | Uint8ClampedArray } - | ImageData - | ImageBitmap, - ): void; - - hasImage(name: string): boolean; - - removeImage(name: string): void; - - loadImage(url: string, callback: (error?: Error, result?: HTMLImageElement | ImageBitmap) => void): void; - - listImages(): string[]; - - addLayer(layer: mapboxgl.AnyLayer, before?: string): this; - - moveLayer(id: string, beforeId?: string): this; - - removeLayer(id: string): this; - - getLayer(id: string): mapboxgl.AnyLayer; - - setFilter(layer: string, filter?: any[] | boolean | null, options?: FilterOptions | null): this; - - setLayerZoomRange(layerId: string, minzoom: number, maxzoom: number): this; - - getFilter(layer: string): any[]; - - setPaintProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getPaintProperty(layer: string, name: string): any; - - setLayoutProperty(layer: string, name: string, value: any, options?: FilterOptions): this; - - getLayoutProperty(layer: string, name: string): any; - - setLight(light: mapboxgl.Light, options?: FilterOptions): this; - - getLight(): mapboxgl.Light; - - /** - * Sets the terrain property of the style. - * - * @param terrain Terrain properties to set. Must conform to the [Mapbox Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#terrain). - * If `null` or `undefined` is provided, function removes terrain. - * @returns {Map} `this` - * @example - * map.addSource('mapbox-dem', { - * 'type': 'raster-dem', - * 'url': 'mapbox://mapbox.mapbox-terrain-dem-v1', - * 'tileSize': 512, - * 'maxzoom': 14 - * }); - * // add the DEM source as a terrain layer with exaggerated height - * map.setTerrain({ 'source': 'mapbox-dem', 'exaggeration': 1.5 }); - */ - setTerrain(terrain?: TerrainSpecification | null): this; - - getTerrain(): TerrainSpecification | null; - - showTerrainWireframe: boolean; - - /** - * @param lngLat The coordinate to query - * @param options Optional {ElevationQueryOptions} - * @returns The elevation in meters at mean sea level or null - */ - queryTerrainElevation(lngLat: mapboxgl.LngLatLike, options?: ElevationQueryOptions): number | null; - - setFeatureState( - feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, - state: { [key: string]: any }, - ): void; - - getFeatureState(feature: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature): { [key: string]: any }; - - removeFeatureState(target: FeatureIdentifier | mapboxgl.MapboxGeoJSONFeature, key?: string): void; - - getContainer(): HTMLElement; - - getCanvasContainer(): HTMLElement; - - getCanvas(): HTMLCanvasElement; - - loaded(): boolean; - - remove(): void; - - triggerRepaint(): void; - - showTileBoundaries: boolean; - - showCollisionBoxes: boolean; - - /** - * Gets and sets a Boolean indicating whether the map will visualize - * the padding offsets. - * - * @name showPadding - * @instance - * @memberof Map - */ - showPadding: boolean; - - repaint: boolean; - - getCenter(): mapboxgl.LngLat; - - setCenter(center: LngLatLike, eventData?: mapboxgl.EventData): this; - - panBy(offset: PointLike, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - panTo(lnglat: LngLatLike, options?: mapboxgl.AnimationOptions, eventdata?: mapboxgl.EventData): this; - - getZoom(): number; - - setZoom(zoom: number, eventData?: mapboxgl.EventData): this; - - zoomTo(zoom: number, options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomIn(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - zoomOut(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getBearing(): number; - - setBearing(bearing: number, eventData?: mapboxgl.EventData): this; - - /** - * Returns the current padding applied around the map viewport. - * - * @memberof Map# - * @returns The current padding around the map viewport. - */ - getPadding(): PaddingOptions; - - /** - * Sets the padding in pixels around the viewport. - * - * Equivalent to `jumpTo({padding: padding})`. - * - * @memberof Map# - * @param padding The desired padding. Format: { left: number, right: number, top: number, bottom: number } - * @param eventData Additional properties to be added to event objects of events triggered by this method. - * @fires movestart - * @fires moveend - * @returns {Map} `this` - * @example - * // Sets a left padding of 300px, and a top padding of 50px - * map.setPadding({ left: 300, top: 50 }); - */ - setPadding(padding: PaddingOptions, eventData?: EventData): this; - - rotateTo(bearing: number, options?: AnimationOptions & CameraOptions, eventData?: EventData): this; - - resetNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - resetNorthPitch(options?: mapboxgl.AnimationOptions | null, eventData?: mapboxgl.EventData | null): this; - - snapToNorth(options?: mapboxgl.AnimationOptions, eventData?: mapboxgl.EventData): this; - - getPitch(): number; - - setPitch(pitch: number, eventData?: EventData): this; - - cameraForBounds(bounds: LngLatBoundsLike, options?: CameraForBoundsOptions): CameraForBoundsResult | undefined; - - fitBounds(bounds: LngLatBoundsLike, options?: mapboxgl.FitBoundsOptions, eventData?: mapboxgl.EventData): this; - - fitScreenCoordinates( - p0: PointLike, - p1: PointLike, - bearing: number, - options?: AnimationOptions & CameraOptions, - eventData?: EventData, - ): this; - - jumpTo(options: mapboxgl.CameraOptions, eventData?: mapboxgl.EventData): this; - - /** - * Returns position and orientation of the camera entity. - * - * @memberof Map# - * @returns {FreeCameraOptions} The camera state - */ - getFreeCameraOptions(): FreeCameraOptions; - - /** - * FreeCameraOptions provides more direct access to the underlying camera entity. - * For backwards compatibility the state set using this API must be representable with - * `CameraOptions` as well. Parameters are clamped into a valid range or discarded as invalid - * if the conversion to the pitch and bearing presentation is ambiguous. For example orientation - * can be invalid if it leads to the camera being upside down, the quaternion has zero length, - * or the pitch is over the maximum pitch limit. - * - * @memberof Map# - * @param {FreeCameraOptions} options FreeCameraOptions object - * @param eventData Additional properties to be added to event objects of events triggered by this method. - * @fires movestart - * @fires zoomstart - * @fires pitchstart - * @fires rotate - * @fires move - * @fires zoom - * @fires pitch - * @fires moveend - * @fires zoomend - * @fires pitchend - * @returns {Map} `this` - */ - setFreeCameraOptions(options: FreeCameraOptions, eventData?: Object): this; - - easeTo(options: mapboxgl.EaseToOptions, eventData?: mapboxgl.EventData): this; - - flyTo(options: mapboxgl.FlyToOptions, eventData?: mapboxgl.EventData): this; - - isEasing(): boolean; - - stop(): this; - - on( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - on(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - on(type: string, listener: (ev: any) => void): this; - - once( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - once(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - once(type: string, listener: (ev: any) => void): this; - once(type: T): Promise; - - off( - type: T, - layer: string | readonly string[], - listener: (ev: MapLayerEventType[T] & EventData) => void, - ): this; - off(type: T, listener: (ev: MapEventType[T] & EventData) => void): this; - off(type: string, listener: (ev: any) => void): this; - - scrollZoom: ScrollZoomHandler; - - boxZoom: BoxZoomHandler; - - dragRotate: DragRotateHandler; - - dragPan: DragPanHandler; - - keyboard: KeyboardHandler; - - doubleClickZoom: DoubleClickZoomHandler; - - touchZoomRotate: TouchZoomRotateHandler; - - touchPitch: TouchPitchHandler; - - getFog(): Fog | null; - /** - * @param fog If `null` or `undefined` is provided, function removes fog from - * the map. - */ - setFog(fog: Fog | null | undefined): this; - - getProjection(): Projection; - setProjection(projection: Projection | string): this; - } - - export interface MapboxOptions { - /** - * If true, the gl context will be created with MSA antialiasing, which can be useful for antialiasing custom layers. - * This is false by default as a performance optimization. - */ - antialias?: boolean | undefined; - - /** If true, an attribution control will be added to the map. */ - attributionControl?: boolean | undefined; - - bearing?: number | undefined; - - /** Snap to north threshold in degrees. */ - bearingSnap?: number | undefined; - - /** The initial bounds of the map. If bounds is specified, it overrides center and zoom constructor options. */ - bounds?: LngLatBoundsLike | undefined; - - /** If true, enable the "box zoom" interaction (see BoxZoomHandler) */ - boxZoom?: boolean | undefined; - - /** initial map center */ - center?: LngLatLike | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click for it to be - * considered a valid click (as opposed to a mouse drag). - * - * @default 3 - */ - clickTolerance?: number | undefined; - - /** - * If `true`, Resource Timing API information will be collected for requests made by GeoJSON - * and Vector Tile web workers (this information is normally inaccessible from the main - * Javascript thread). Information will be returned in a `resourceTiming` property of - * relevant `data` events. - * - * @default false - */ - collectResourceTiming?: boolean | undefined; - - /** - * If `true`, symbols from multiple sources can collide with each other during collision - * detection. If `false`, collision detection is run separately for the symbols in each source. - * - * @default true - */ - crossSourceCollisions?: boolean | undefined; - - /** ID of the container element */ - container: string | HTMLElement; - - /** - * If `true` , scroll zoom will require pressing the ctrl or ⌘ key while scrolling to zoom map, - * and touch pan will require using two fingers while panning to move the map. - * Touch pitch will require three fingers to activate if enabled. - */ - cooperativeGestures?: boolean; - - /** String or strings to show in an AttributionControl. - * Only applicable if options.attributionControl is `true`. */ - customAttribution?: string | string[] | undefined; - - /** - * If `true`, the "drag to pan" interaction is enabled. - * An `Object` value is passed as options to {@link DragPanHandler#enable}. - */ - dragPan?: boolean | DragPanOptions | undefined; - - /** If true, enable the "drag to rotate" interaction (see DragRotateHandler). */ - dragRotate?: boolean | undefined; - - /** If true, enable the "double click to zoom" interaction (see DoubleClickZoomHandler). */ - doubleClickZoom?: boolean | undefined; - - /** If `true`, the map's position (zoom, center latitude, center longitude, bearing, and pitch) will be synced with the hash fragment of the page's URL. - * For example, `http://path/to/my/page.html#2.59/39.26/53.07/-24.1/60`. - * An additional string may optionally be provided to indicate a parameter-styled hash, - * e.g. http://path/to/my/page.html#map=2.59/39.26/53.07/-24.1/60&foo=bar, where foo - * is a custom parameter and bar is an arbitrary hash distinct from the map hash. - */ - hash?: boolean | string | undefined; - - /** - * Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. - * This setting affects all symbol layers. This setting does not affect the duration of runtime - * styling transitions or raster tile cross-fading. - * - * @default 300 - */ - fadeDuration?: number | undefined; - - /** If true, map creation will fail if the implementation determines that the performance of the created WebGL context would be dramatically lower than expected. */ - failIfMajorPerformanceCaveat?: boolean | undefined; - - /** A fitBounds options object to use only when setting the bounds option. */ - fitBoundsOptions?: FitBoundsOptions | undefined; - - /** If false, no mouse, touch, or keyboard listeners are attached to the map, so it will not respond to input */ - interactive?: boolean | undefined; - - /** If true, enable keyboard shortcuts (see KeyboardHandler). */ - keyboard?: boolean | undefined; - - /** A patch to apply to the default localization table for UI strings, e.g. control tooltips. - * The `locale` object maps namespaced UI string IDs to translated strings in the target language; - * see `src/ui/default_locale.js` for an example with all supported string IDs. - * The object may specify all UI strings (thereby adding support for a new translation) or - * only a subset of strings (thereby patching the default translation table). - */ - locale?: { [key: string]: string } | undefined; - - /** - * Overrides the generation of all glyphs and font settings except font-weight keywords - * Also overrides localIdeographFontFamily - * @default null - */ - localFontFamily?: string | undefined; - - /** - * If specified, defines a CSS font-family for locally overriding generation of glyphs in the - * 'CJK Unified Ideographs' and 'Hangul Syllables' ranges. In these ranges, font settings from - * the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold). - * The purpose of this option is to avoid bandwidth-intensive glyph server requests. - * - * @default null - */ - localIdeographFontFamily?: string | undefined; - - /** - * A string representing the position of the Mapbox wordmark on the map. - * - * @default "bottom-left" - */ - logoPosition?: "top-left" | "top-right" | "bottom-left" | "bottom-right" | undefined; - - /** If set, the map is constrained to the given bounds. */ - maxBounds?: LngLatBoundsLike | undefined; - - /** Maximum pitch of the map. */ - maxPitch?: number | undefined; - - /** Maximum zoom of the map. */ - maxZoom?: number | undefined; - - /** Minimum pitch of the map. */ - minPitch?: number | undefined; - - /** Minimum zoom of the map. */ - minZoom?: number | undefined; - - /** - * If true, map will prioritize rendering for performance by reordering layers - * If false, layers will always be drawn in the specified order - * - * @default true - */ - optimizeForTerrain?: boolean | undefined; - - /** If true, The maps canvas can be exported to a PNG using map.getCanvas().toDataURL();. This is false by default as a performance optimization. */ - preserveDrawingBuffer?: boolean | undefined; - - /** - * The initial pitch (tilt) of the map, measured in degrees away from the plane of the - * screen (0-60). - * - * @default 0 - */ - pitch?: number | undefined; - - /** - * A style's projection property sets which projection a map is rendered in. - * - * @default 'mercator' - */ - projection?: Projection; - - /** - * If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled. - * - * @default true - */ - pitchWithRotate?: boolean | undefined; - - /** - * If `false`, the map won't attempt to re-request tiles once they expire per their HTTP - * `cacheControl`/`expires` headers. - * - * @default true - */ - refreshExpiredTiles?: boolean | undefined; - - /** - * If `true`, multiple copies of the world will be rendered, when zoomed out. - * - * @default true - */ - renderWorldCopies?: boolean | undefined; - - /** - * If `true`, the "scroll to zoom" interaction is enabled. - * An `Object` value is passed as options to {@link ScrollZoomHandler#enable}. - */ - scrollZoom?: boolean | InteractiveOptions | undefined; - - /** stylesheet location */ - style?: mapboxgl.Style | string | undefined; - - /** If true, the map will automatically resize when the browser window resizes */ - trackResize?: boolean | undefined; - - /** - * A callback run before the Map makes a request for an external URL. The callback can be - * used to modify the url, set headers, or set the credentials property for cross-origin requests. - * - * @default null - */ - transformRequest?: TransformRequestFunction | undefined; - - /** - * If `true`, the "pinch to rotate and zoom" interaction is enabled. - * An `Object` value is passed as options to {@link TouchZoomRotateHandler#enable}. - */ - touchZoomRotate?: boolean | InteractiveOptions | undefined; - - /** - * If `true`, the "drag to pitch" interaction is enabled. - * An `Object` value is passed as options to {@link TouchPitchHandler#enable}. - */ - touchPitch?: boolean | InteractiveOptions | undefined; - - /** Initial zoom level */ - zoom?: number | undefined; - - /** - * The maximum number of tiles stored in the tile cache for a given source. If omitted, the - * cache will be dynamically sized based on the current viewport. - * - * @default null - */ - maxTileCacheSize?: number | undefined; - - /** - * If specified, map will use this token instead of the one defined in mapboxgl.accessToken. - * - * @default null - */ - accessToken?: string | undefined; - - /** - * Allows for the usage of the map in automated tests without an accessToken with custom self-hosted test fixtures. - * - * @default null - */ - testMode?: boolean | undefined; - /** - * Sets the map's worldview. A worldview determines the way that certain disputed boundaries are rendered. - * By default, GL JS will not set a worldview so that the worldview of Mapbox tiles will be determined by - * the vector tile source's TileJSON. Valid worldview strings must be an ISO alpha-2 country code. - * - * @default null - */ - worldview?: string | undefined; - } - - type quat = number[]; - type vec3 = number[]; - - /** - * Various options for accessing physical properties of the underlying camera entity. - * A direct access to these properties allows more flexible and precise controlling of the camera - * while also being fully compatible and interchangeable with CameraOptions. All fields are optional. - * See {@Link Camera#setFreeCameraOptions} and {@Link Camera#getFreeCameraOptions} - * - * @param {MercatorCoordinate} position Position of the camera in slightly modified web mercator coordinates - - The size of 1 unit is the width of the projected world instead of the "mercator meter". - Coordinate [0, 0, 0] is the north-west corner and [1, 1, 0] is the south-east corner. - - Z coordinate is conformal and must respect minimum and maximum zoom values. - - Zoom is automatically computed from the altitude (z) - * @param {quat} orientation Orientation of the camera represented as a unit quaternion [x, y, z, w] - in a left-handed coordinate space. Direction of the rotation is clockwise around the respective axis. - The default pose of the camera is such that the forward vector is looking up the -Z axis and - the up vector is aligned with north orientation of the map: - forward: [0, 0, -1] - up: [0, -1, 0] - right [1, 0, 0] - Orientation can be set freely but certain constraints still apply - - Orientation must be representable with only pitch and bearing. - - Pitch has an upper limit - */ - export class FreeCameraOptions { - constructor(position?: MercatorCoordinate, orientation?: quat); - - position: MercatorCoordinate | undefined; - - /** - * Helper function for setting orientation of the camera by defining a focus point - * on the map. - * - * @param {LngLatLike} location Location of the focus point on the map - * @param {vec3} up Up vector of the camera is required in certain scenarios where bearing can't be deduced - * from the viewing direction. - */ - lookAtPoint(location: LngLatLike, up?: vec3): void; - - /** - * Helper function for setting the orientation of the camera as a pitch and a bearing. - * - * @param {number} pitch Pitch angle in degrees - * @param {number} bearing Bearing angle in degrees - */ - setPitchBearing(pitch: number, bearing: number): void; - } - - export type ResourceType = - | "Unknown" - | "Style" - | "Source" - | "Tile" - | "Glyphs" - | "SpriteImage" - | "SpriteJSON" - | "Image"; - - export interface RequestParameters { - /** - * The URL to be requested. - */ - url: string; - - /** - * Use `'include'` to send cookies with cross-origin requests. - */ - credentials?: "same-origin" | "include" | undefined; - - /** - * The headers to be sent with the request. - */ - headers?: { [header: string]: any } | undefined; - - method?: "GET" | "POST" | "PUT" | undefined; - - collectResourceTiming?: boolean | undefined; - } - - export type TransformRequestFunction = (url: string, resourceType: ResourceType) => RequestParameters; - - export interface PaddingOptions { - top: number; - bottom: number; - left: number; - right: number; - } - - export interface FeatureIdentifier { - id?: string | number | undefined; - source: string; - sourceLayer?: string | undefined; - } - - /** - * BoxZoomHandler - */ - export class BoxZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * ScrollZoomHandler - */ - export class ScrollZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - setZoomRate(zoomRate: number): void; - - setWheelZoomRate(wheelZoomRate: number): void; - } - - /** - * DragPenHandler - */ - export class DragPanHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(options?: DragPanOptions): void; - - disable(): void; - } - - /** - * DragRotateHandler - */ - export class DragRotateHandler { - constructor( - map: mapboxgl.Map, - options?: { bearingSnap?: number | undefined; pitchWithRotate?: boolean | undefined }, - ); - - isEnabled(): boolean; - - isActive(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * KeyboardHandler - */ - export class KeyboardHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - - /** - * Returns true if the handler is enabled and has detected the start of a - * zoom/rotate gesture. - * - * @returns {boolean} `true` if the handler is enabled and has detected the - * start of a zoom/rotate gesture. - */ - isActive(): boolean; - - /** - * Disables the "keyboard pan/rotate" interaction, leaving the - * "keyboard zoom" interaction enabled. - * - * @example - * map.keyboard.disableRotation(); - */ - disableRotation(): void; - - /** - * Enables the "keyboard pan/rotate" interaction. - * - * @example - * map.keyboard.enable(); - * map.keyboard.enableRotation(); - */ - enableRotation(): void; - } - - /** - * DoubleClickZoomHandler - */ - export class DoubleClickZoomHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(): void; - - disable(): void; - } - - /** - * TouchZoomRotateHandler - */ - export class TouchZoomRotateHandler { - constructor(map: mapboxgl.Map); - - isEnabled(): boolean; - - enable(options?: InteractiveOptions): void; - - disable(): void; - - disableRotation(): void; - - enableRotation(): void; - } - - export class TouchPitchHandler { - constructor(map: mapboxgl.Map); - - enable(options?: InteractiveOptions): void; - - isActive(): boolean; - - isEnabled(): boolean; - - disable(): void; - } - - export interface IControl { - onAdd(map: Map): HTMLElement; - - onRemove(map: Map): void; - - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Control - */ - export class Control extends Evented implements IControl { - onAdd(map: Map): HTMLElement; - onRemove(map: Map): void; - getDefaultPosition?: (() => string) | undefined; - } - - /** - * Navigation - */ - export class NavigationControl extends Control { - constructor(options?: { - showCompass?: boolean | undefined; - showZoom?: boolean | undefined; - visualizePitch?: boolean | undefined; - }); - } - - export class PositionOptions { - enableHighAccuracy?: boolean | undefined; - timeout?: number | undefined; - maximumAge?: number | undefined; - } - - /** - * Geolocate - */ - export class GeolocateControl extends Control { - constructor(options?: { - positionOptions?: PositionOptions | undefined; - fitBoundsOptions?: FitBoundsOptions | undefined; - trackUserLocation?: boolean | undefined; - showAccuracyCircle?: boolean | undefined; - showUserLocation?: boolean | undefined; - showUserHeading?: boolean | undefined; - geolocation?: Geolocation | undefined; - }); - trigger(): boolean; - } - - /** - * Attribution - */ - export class AttributionControl extends Control { - constructor(options?: { compact?: boolean | undefined; customAttribution?: string | string[] | undefined }); - } - - /** - * Scale - */ - export class ScaleControl extends Control { - constructor(options?: { maxWidth?: number | undefined; unit?: string | undefined }); - - setUnit(unit: "imperial" | "metric" | "nautical"): void; - } - - /** - * FullscreenControl - */ - export class FullscreenControl extends Control { - constructor(options?: FullscreenControlOptions | null); - } - - export interface FullscreenControlOptions { - /** - * A compatible DOM element which should be made full screen. - * By default, the map container element will be made full screen. - */ - container?: HTMLElement | null | undefined; - } - - /** - * Popup - */ - export class Popup extends Evented { - constructor(options?: mapboxgl.PopupOptions); - - addTo(map: mapboxgl.Map): this; - - isOpen(): boolean; - - remove(): this; - - getLngLat(): mapboxgl.LngLat; - - /** - * Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior. - * - * @param lnglat The geographical location to set as the popup's anchor. - */ - setLngLat(lnglat: LngLatLike): this; - - /** - * Tracks the popup anchor to the cursor position, on screens with a pointer device (will be hidden on touchscreens). Replaces the setLngLat behavior. - * For most use cases, `closeOnClick` and `closeButton` should also be set to `false` here. - */ - trackPointer(): this; - - /** Returns the `Popup`'s HTML element. */ - getElement(): HTMLElement; - - setText(text: string): this; - - setHTML(html: string): this; - - setDOMContent(htmlNode: Node): this; - - getMaxWidth(): string; - - setMaxWidth(maxWidth: string): this; - - /** - * Adds a CSS class to the popup container element. - * - * @param {string} className Non-empty string with CSS class name to add to popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.addClassName('some-class') - */ - addClassName(className: string): void; - - /** - * Removes a CSS class from the popup container element. - * - * @param {string} className Non-empty string with CSS class name to remove from popup container - * - * @example - * let popup = new mapboxgl.Popup() - * popup.removeClassName('some-class') - */ - removeClassName(className: string): void; - - /** - * Sets the popup's offset. - * - * @param offset Sets the popup's offset. - * @returns {Popup} `this` - */ - setOffset(offset?: Offset | null): this; - - /** - * Add or remove the given CSS class on the popup container, depending on whether the container currently has that class. - * - * @param {string} className Non-empty string with CSS class name to add/remove - * - * @returns {boolean} if the class was removed return false, if class was added, then return true - * - * @example - * let popup = new mapboxgl.Popup() - * popup.toggleClassName('toggleClass') - */ - toggleClassName(className: string): void; - } - - export interface PopupOptions { - closeButton?: boolean | undefined; - - closeOnClick?: boolean | undefined; - - /** - * @param {boolean} [options.closeOnMove=false] If `true`, the popup will closed when the map moves. - */ - closeOnMove?: boolean | undefined; - - /** - * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the - * first focusable element inside the popup. - */ - focusAfterOpen?: boolean | null | undefined; - - anchor?: Anchor | undefined; - - offset?: Offset | null | undefined; - - className?: string | undefined; - - maxWidth?: string | undefined; - } - - export interface Style { - layers: AnyLayer[]; - sources: Sources; - - bearing?: number | undefined; - center?: number[] | undefined; - fog?: Fog | undefined; - glyphs?: string | undefined; - metadata?: any; - name?: string | undefined; - pitch?: number | undefined; - light?: Light | undefined; - sprite?: string | undefined; - terrain?: TerrainSpecification | undefined; - transition?: Transition | undefined; - version: number; - zoom?: number | undefined; - } - - export interface Transition { - delay?: number | undefined; - duration?: number | undefined; - } - - export interface Light { - anchor?: "map" | "viewport" | undefined; - position?: number[] | undefined; - "position-transition"?: Transition | undefined; - color?: string | undefined; - "color-transition"?: Transition | undefined; - intensity?: number | undefined; - "intensity-transition"?: Transition | undefined; - } - - export interface Fog { - color?: string | Expression | undefined; - "horizon-blend"?: number | Expression | undefined; - range?: number[] | Expression | undefined; - "high-color"?: string | Expression | undefined; - "space-color"?: string | Expression | undefined; - "star-intensity"?: number | Expression | undefined; - } - - export interface Sources { - [sourceName: string]: AnySourceData; - } - - export type PromoteIdSpecification = { [key: string]: string } | string; - - export type AnySourceData = - | GeoJSONSourceRaw - | VideoSourceRaw - | ImageSourceRaw - | CanvasSourceRaw - | VectorSource - | RasterSource - | RasterDemSource - | CustomSourceInterface; - - interface RasterSourceImpl extends RasterSource { - /** - * Reloads the source data and re-renders the map. - */ - reload(): void; - - /** - * Sets the source `tiles` property and re-renders the map. - * - * @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec. - * @returns {RasterTileSource} this - */ - setTiles(tiles: readonly string[]): RasterSourceImpl; - - /** - * Sets the source `url` property and re-renders the map. - * - * @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://`. - * @returns {RasterTileSource} this - */ - setUrl(url: string): RasterSourceImpl; - } - - interface VectorSourceImpl extends VectorSource { - /** - * Reloads the source data and re-renders the map. - */ - reload(): void; - - /** - * Sets the source `tiles` property and re-renders the map. - * - * @param {string[]} tiles An array of one or more tile source URLs, as in the TileJSON spec. - * @returns {VectorTileSource} this - */ - setTiles(tiles: readonly string[]): VectorSourceImpl; - - /** - * Sets the source `url` property and re-renders the map. - * - * @param {string} url A URL to a TileJSON resource. Supported protocols are `http:`, `https:`, and `mapbox://`. - * @returns {VectorTileSource} this - */ - setUrl(url: string): VectorSourceImpl; - } - - export type AnySourceImpl = - | GeoJSONSource - | VideoSource - | ImageSource - | CanvasSource - | VectorSourceImpl - | RasterSourceImpl - | RasterDemSource - | CustomSource; - - export interface Source { - type: "vector" | "raster" | "raster-dem" | "geojson" | "image" | "video" | "canvas" | "custom"; - } - - /** - * GeoJSONSource - */ - - export interface GeoJSONSourceRaw extends Source, GeoJSONSourceOptions { - type: "geojson"; - } - - export class GeoJSONSource implements GeoJSONSourceRaw { - type: "geojson"; - - constructor(options?: mapboxgl.GeoJSONSourceOptions); - - setData(data: GeoJSON.Feature | GeoJSON.FeatureCollection | String): this; - - getClusterExpansionZoom(clusterId: number, callback: (error: any, zoom: number) => void): this; - - getClusterChildren( - clusterId: number, - callback: (error: any, features: Array>) => void, - ): this; - - getClusterLeaves( - cluserId: number, - limit: number, - offset: number, - callback: (error: any, features: Array>) => void, - ): this; - } - - export interface GeoJSONSourceOptions { - data?: - | GeoJSON.Feature - | GeoJSON.FeatureCollection - | GeoJSON.Geometry - | string - | undefined; - - maxzoom?: number | undefined; - - attribution?: string | undefined; - - buffer?: number | undefined; - - tolerance?: number | undefined; - - cluster?: number | boolean | undefined; - - clusterRadius?: number | undefined; - - clusterMaxZoom?: number | undefined; - - /** - * Minimum number of points necessary to form a cluster if clustering is enabled. Defaults to `2`. - */ - clusterMinPoints?: number | undefined; - - clusterProperties?: object | undefined; - - lineMetrics?: boolean | undefined; - - generateId?: boolean | undefined; - - promoteId?: PromoteIdSpecification | undefined; - - filter?: any; - } - - /** - * VideoSource - */ - export interface VideoSourceRaw extends Source, VideoSourceOptions { - type: "video"; - } - - export class VideoSource implements VideoSourceRaw { - type: "video"; - - constructor(options?: mapboxgl.VideoSourceOptions); - - getVideo(): HTMLVideoElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface VideoSourceOptions { - urls?: string[] | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * ImageSource - */ - export interface ImageSourceRaw extends Source, ImageSourceOptions { - type: "image"; - } - - export class ImageSource implements ImageSourceRaw { - type: "image"; - - constructor(options?: mapboxgl.ImageSourceOptions); - - updateImage(options: ImageSourceOptions): this; - - setCoordinates(coordinates: number[][]): this; - } - - export interface ImageSourceOptions { - url?: string | undefined; - - coordinates?: number[][] | undefined; - } - - /** - * CanvasSource - */ - export interface CanvasSourceRaw extends Source, CanvasSourceOptions { - type: "canvas"; - } - - export class CanvasSource implements CanvasSourceRaw { - type: "canvas"; - - coordinates: number[][]; - - canvas: string | HTMLCanvasElement; - - play(): void; - - pause(): void; - - getCanvas(): HTMLCanvasElement; - - setCoordinates(coordinates: number[][]): this; - } - - export interface CanvasSourceOptions { - coordinates: number[][]; - - animate?: boolean | undefined; - - canvas: string | HTMLCanvasElement; - } - - export type CameraFunctionSpecification = - | { type: "exponential"; stops: Array<[number, T]> } - | { type: "interval"; stops: Array<[number, T]> }; - - export type ExpressionSpecification = unknown[]; - - export type PropertyValueSpecification = T | CameraFunctionSpecification | ExpressionSpecification; - - export interface TerrainSpecification { - source: string; - exaggeration?: PropertyValueSpecification | undefined; - } - - /** - * @see https://github.com/mapbox/tilejson-spec/tree/master/3.0.0#33-vector_layers - */ - type SourceVectorLayer = { - id: string; - fields?: Record; - description?: string; - minzoom?: number; - maxzoom?: number; - - // Non standard extensions that are valid in a Mapbox context. - source?: string; - source_name?: string; - }; - - interface VectorSource extends Source { - type: "vector"; - format?: "pbf"; - - url?: string | undefined; - id?: string; - name?: string; - - tiles?: string[] | undefined; - bounds?: number[] | undefined; - scheme?: "xyz" | "tms" | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - attribution?: string | undefined; - promoteId?: PromoteIdSpecification | undefined; - - vector_layers?: SourceVectorLayer[]; - } - - interface RasterSource extends Source { - name?: string; - type: "raster"; - id?: string; - format?: "webp" | string; - - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - scheme?: "xyz" | "tms" | undefined; - attribution?: string | undefined; - } - - interface RasterDemSource extends Source { - name?: string; - type: "raster-dem"; - id?: string; - - url?: string | undefined; - tiles?: string[] | undefined; - bounds?: number[] | undefined; - minzoom?: number | undefined; - maxzoom?: number | undefined; - tileSize?: number | undefined; - attribution?: string | undefined; - encoding?: "terrarium" | "mapbox" | undefined; - } - - interface CustomSourceInterface { - id: string; - type: "custom"; - dataType: "raster"; - minzoom?: number; - maxzoom?: number; - scheme?: string; - tileSize?: number; - attribution?: string; - bounds?: [number, number, number, number]; - hasTile?: (tileID: { z: number; x: number; y: number }) => boolean; - loadTile: (tileID: { z: number; x: number; y: number }, options: { signal: AbortSignal }) => Promise; - prepareTile?: (tileID: { z: number; x: number; y: number }) => T | undefined; - unloadTile?: (tileID: { z: number; x: number; y: number }) => void; - onAdd?: (map: Map) => void; - onRemove?: (map: Map) => void; - } - - interface CustomSource extends Source { - id: string; - type: "custom"; - scheme: string; - minzoom: number; - maxzoom: number; - tileSize: number; - attribution: string; - - _implementation: CustomSourceInterface; - } - - /** - * LngLat - */ - export class LngLat { - lng: number; - lat: number; - - constructor(lng: number, lat: number); - - /** Return a new LngLat object whose longitude is wrapped to the range (-180, 180). */ - wrap(): mapboxgl.LngLat; - - /** Return a LngLat as an array */ - toArray(): number[]; - - /** Return a LngLat as a string */ - toString(): string; - - /** Returns the approximate distance between a pair of coordinates in meters - * Uses the Haversine Formula (from R.W. Sinnott, "Virtues of the Haversine", Sky and Telescope, vol. 68, no. 2, 1984, p. 159) */ - distanceTo(lngLat: LngLat): number; - - toBounds(radius: number): LngLatBounds; - - static convert(input: LngLatLike): mapboxgl.LngLat; - } - - /** - * LngLatBounds - */ - export class LngLatBounds { - sw: LngLatLike; - ne: LngLatLike; - _sw: LngLat; - _ne: LngLat; - - constructor(boundsLike?: [LngLatLike, LngLatLike] | [number, number, number, number]); - constructor(sw: LngLatLike, ne: LngLatLike); - - setNorthEast(ne: LngLatLike): this; - - setSouthWest(sw: LngLatLike): this; - - /** Check if the point is within the bounding box. */ - contains(lnglat: LngLatLike): boolean; - - /** Extend the bounds to include a given LngLat or LngLatBounds. */ - extend(obj: mapboxgl.LngLatLike | mapboxgl.LngLatBoundsLike): this; - - /** Get the point equidistant from this box's corners */ - getCenter(): mapboxgl.LngLat; - - /** Get southwest corner */ - getSouthWest(): mapboxgl.LngLat; - - /** Get northeast corner */ - getNorthEast(): mapboxgl.LngLat; - - /** Get northwest corner */ - getNorthWest(): mapboxgl.LngLat; - - /** Get southeast corner */ - getSouthEast(): mapboxgl.LngLat; - - /** Get west edge longitude */ - getWest(): number; - - /** Get south edge latitude */ - getSouth(): number; - - /** Get east edge longitude */ - getEast(): number; - - /** Get north edge latitude */ - getNorth(): number; - - /** Returns a LngLatBounds as an array */ - toArray(): number[][]; - - /** Return a LngLatBounds as a string */ - toString(): string; - - /** Returns a boolean */ - isEmpty(): boolean; - - /** Convert an array to a LngLatBounds object, or return an existing LngLatBounds object unchanged. */ - static convert(input: LngLatBoundsLike): mapboxgl.LngLatBounds; - } - - /** - * Point - */ - // Todo: Pull out class to seperate definition for Module "point-geometry" - export class Point { - x: number; - y: number; - - constructor(x: number, y: number); - - clone(): Point; - - add(p: Point): Point; - - sub(p: Point): Point; - - mult(k: number): Point; - - div(k: number): Point; - - rotate(a: number): Point; - - matMult(m: number): Point; - - unit(): Point; - - perp(): Point; - - round(): Point; - - mag(): number; - - equals(p: Point): boolean; - - dist(p: Point): number; - - distSqr(p: Point): number; - - angle(): number; - - angleTo(p: Point): number; - - angleWidth(p: Point): number; - - angleWithSep(x: number, y: number): number; - - static convert(a: PointLike): Point; - } - - /** - * MercatorCoordinate - */ - export class MercatorCoordinate { - /** The x component of the position. */ - x: number; - - /** The y component of the position. */ - y: number; - - /** - * The z component of the position. - * - * @default 0 - */ - z?: number | undefined; - - constructor(x: number, y: number, z?: number); - - /** Returns the altitude in meters of the coordinate. */ - toAltitude(): number; - - /** Returns the LngLat for the coordinate. */ - toLngLat(): LngLat; - - /** - * Returns the distance of 1 meter in MercatorCoordinate units at this latitude. - * - * For coordinates in real world units using meters, this naturally provides the - * scale to transform into MercatorCoordinates. - */ - meterInMercatorCoordinateUnits(): number; - - /** Project a LngLat to a MercatorCoordinate. */ - static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate; - } - - /** - * Marker - */ - export class Marker extends Evented { - constructor(options?: mapboxgl.MarkerOptions); - - constructor(element?: HTMLElement, options?: mapboxgl.MarkerOptions); - - addTo(map: Map): this; - - remove(): this; - - getLngLat(): LngLat; - - setLngLat(lngLat: LngLatLike): this; - - getElement(): HTMLElement; - - setPopup(popup?: Popup): this; - - getPopup(): Popup; - - togglePopup(): this; - - getOffset(): PointLike; - - setOffset(offset: PointLike): this; - - setDraggable(shouldBeDraggable: boolean): this; - - isDraggable(): boolean; - - getRotation(): number; - - setRotation(rotation: number): this; - - getRotationAlignment(): Alignment; - - setRotationAlignment(alignment: Alignment): this; - - getPitchAlignment(): Alignment; - - setPitchAlignment(alignment: Alignment): this; - - getOccludedOpacity(): number; - - setOccludedOpacity(opacity: number): this; - } - - type Alignment = "map" | "viewport" | "auto"; - - export interface MarkerOptions { - /** DOM element to use as a marker. The default is a light blue, droplet-shaped SVG marker */ - element?: HTMLElement | undefined; - - /** The offset in pixels as a PointLike object to apply relative to the element's center. Negatives indicate left and up. */ - offset?: PointLike | undefined; - - /** A string indicating the part of the Marker that should be positioned closest to the coordinate set via Marker.setLngLat. - * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`, `'top-right'`, `'bottom-left'`, and `'bottom-right'`. - * The default value os `'center'` - */ - anchor?: Anchor | undefined; - - /** The color to use for the default marker if options.element is not provided. The default is light blue (#3FB1CE). */ - color?: string | undefined; - - /** A boolean indicating whether or not a marker is able to be dragged to a new position on the map. The default value is false */ - draggable?: boolean | undefined; - - /** - * The max number of pixels a user can shift the mouse pointer during a click on the marker for it to be considered a valid click - * (as opposed to a marker drag). The default (0) is to inherit map's clickTolerance. - */ - clickTolerance?: number | null | undefined; - - /** The rotation angle of the marker in degrees, relative to its `rotationAlignment` setting. A positive value will rotate the marker clockwise. - * The default value is 0. - */ - rotation?: number | undefined; - - /** `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates. - * `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations. - * `auto` is equivalent to `viewport`. - * The default value is `auto` - */ - rotationAlignment?: Alignment | undefined; - - /** `map` aligns the `Marker` to the plane of the map. - * `viewport` aligns the `Marker` to the plane of the viewport. - * `auto` automatically matches the value of `rotationAlignment`. - * The default value is `auto`. - */ - pitchAlignment?: Alignment | undefined; - - /** The scale to use for the default marker if options.element is not provided. - * The default scale (1) corresponds to a height of `41px` and a width of `27px`. - */ - scale?: number | undefined; - - /** - * The opacity of a marker that's occluded by 3D terrain. Number between 0 and 1. - */ - occludedOpacity?: number | undefined; - } - - type EventedListener = (object?: Object) => any; - /** - * Evented - */ - export class Evented { - on(type: string, listener: EventedListener): this; - - off(type?: string | any, listener?: EventedListener): this; - - once(type: string, listener: EventedListener): this; - - // https://github.com/mapbox/mapbox-gl-js/issues/6522 - fire(type: string, properties?: { [key: string]: any }): this; - } - - /** - * StyleOptions - */ - export interface StyleOptions { - transition?: boolean | undefined; - } - - export type MapboxGeoJSONFeature = GeoJSON.Feature & { - layer: Layer; - source: string; - sourceLayer: string; - state: { [key: string]: any }; - }; - - export type EventData = { [key: string]: any }; - - export class MapboxEvent { - type: string; - target: Map; - originalEvent: TOrig; - } - - export class MapMouseEvent extends MapboxEvent { - type: - | "mousedown" - | "mouseup" - | "click" - | "dblclick" - | "mousemove" - | "mouseover" - | "mouseenter" - | "mouseleave" - | "mouseout" - | "contextmenu"; - - point: Point; - lngLat: LngLat; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerMouseEvent = MapMouseEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapTouchEvent extends MapboxEvent { - type: "touchstart" | "touchend" | "touchcancel"; - - point: Point; - lngLat: LngLat; - points: Point[]; - lngLats: LngLat[]; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export type MapLayerTouchEvent = MapTouchEvent & { features?: MapboxGeoJSONFeature[] | undefined }; - - export class MapWheelEvent extends MapboxEvent { - type: "wheel"; - - preventDefault(): void; - defaultPrevented: boolean; - } - - export interface MapBoxZoomEvent extends MapboxEvent { - type: "boxzoomstart" | "boxzoomend" | "boxzoomcancel"; - - boxZoomBounds: LngLatBounds; - } - - export type MapDataEvent = MapSourceDataEvent | MapStyleDataEvent; - - export interface MapStyleDataEvent extends MapboxEvent { - dataType: "style"; - } - - export interface MapSourceDataEvent extends MapboxEvent { - dataType: "source"; - isSourceLoaded: boolean; - source: Source; - sourceId: string; - sourceDataType: "metadata" | "content"; - tile: any; - coord: Coordinate; - } - - export interface Coordinate { - canonical: CanonicalCoordinate; - wrap: number; - key: number; - } - - export interface CanonicalCoordinate { - x: number; - y: number; - z: number; - key: number; - equals(coord: CanonicalCoordinate): boolean; - } - - export interface MapContextEvent extends MapboxEvent { - type: "webglcontextlost" | "webglcontextrestored"; - } - - export class ErrorEvent extends MapboxEvent { - type: "error"; - error: Error; - } - - /** - * FilterOptions - */ - export interface FilterOptions { - /** - * Whether to check if the filter conforms to the Mapbox GL Style Specification. - * Disabling validation is a performance optimization that should only be used - * if you have previously validated the values you will be passing to this function. - */ - validate?: boolean | null | undefined; - } - - /** - * AnimationOptions - */ - export interface AnimationOptions { - /** Number in milliseconds */ - duration?: number | undefined; - /** - * A function taking a time in the range 0..1 and returning a number where 0 is the initial - * state and 1 is the final state. - */ - easing?: ((time: number) => number) | undefined; - /** point, origin of movement relative to map center */ - offset?: PointLike | undefined; - /** When set to false, no animation happens */ - animate?: boolean | undefined; - - /** If `true`, then the animation is considered essential and will not be affected by `prefers-reduced-motion`. - * Otherwise, the transition will happen instantly if the user has enabled the `reduced motion` accesibility feature in their operating system. - */ - essential?: boolean | undefined; - } - - /** - * CameraOptions - */ - export interface CameraOptions { - /** Map center */ - center?: LngLatLike | undefined; - /** Map zoom level */ - zoom?: number | undefined; - /** Map rotation bearing in degrees counter-clockwise from north */ - bearing?: number | undefined; - /** Map angle in degrees at which the camera is looking at the ground */ - pitch?: number | undefined; - /** If zooming, the zoom center (defaults to map center) */ - around?: LngLatLike | undefined; - /** Dimensions in pixels applied on each side of the viewport for shifting the vanishing point. */ - padding?: number | PaddingOptions | undefined; - } - - export interface CameraForBoundsOptions extends CameraOptions { - offset?: PointLike | undefined; - maxZoom?: number | undefined; - } - - // The Mapbox docs say that if the result is defined, it will have zoom, center and bearing set. - // In practice center is always a {lat, lng} object. - export type CameraForBoundsResult = Required> & { - /** Map center */ - center: { lng: number; lat: number }; - }; - - /** - * FlyToOptions - */ - export interface FlyToOptions extends AnimationOptions, CameraOptions { - curve?: number | undefined; - minZoom?: number | undefined; - speed?: number | undefined; - screenSpeed?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * EaseToOptions - */ - export interface EaseToOptions extends AnimationOptions, CameraOptions { - delayEndEvents?: number | undefined; - } - - export interface FitBoundsOptions extends mapboxgl.FlyToOptions { - linear?: boolean | undefined; - offset?: mapboxgl.PointLike | undefined; - maxZoom?: number | undefined; - maxDuration?: number | undefined; - } - - /** - * MapEvent - */ - export type MapEventType = { - error: ErrorEvent; - - load: MapboxEvent; - idle: MapboxEvent; - remove: MapboxEvent; - render: MapboxEvent; - resize: MapboxEvent; - - webglcontextlost: MapContextEvent; - webglcontextrestored: MapContextEvent; - - dataloading: MapDataEvent; - data: MapDataEvent; - tiledataloading: MapDataEvent; - sourcedataloading: MapSourceDataEvent; - styledataloading: MapStyleDataEvent; - sourcedata: MapSourceDataEvent; - styledata: MapStyleDataEvent; - - boxzoomcancel: MapBoxZoomEvent; - boxzoomstart: MapBoxZoomEvent; - boxzoomend: MapBoxZoomEvent; - - touchcancel: MapTouchEvent; - touchmove: MapTouchEvent; - touchend: MapTouchEvent; - touchstart: MapTouchEvent; - - click: MapMouseEvent; - contextmenu: MapMouseEvent; - dblclick: MapMouseEvent; - mousemove: MapMouseEvent; - mouseup: MapMouseEvent; - mousedown: MapMouseEvent; - mouseout: MapMouseEvent; - mouseover: MapMouseEvent; - - movestart: MapboxEvent; - move: MapboxEvent; - moveend: MapboxEvent; - - zoomstart: MapboxEvent; - zoom: MapboxEvent; - zoomend: MapboxEvent; - - rotatestart: MapboxEvent; - rotate: MapboxEvent; - rotateend: MapboxEvent; - - dragstart: MapboxEvent; - drag: MapboxEvent; - dragend: MapboxEvent; - - pitchstart: MapboxEvent; - pitch: MapboxEvent; - pitchend: MapboxEvent; - - wheel: MapWheelEvent; - }; - - export type MapLayerEventType = { - click: MapLayerMouseEvent; - dblclick: MapLayerMouseEvent; - mousedown: MapLayerMouseEvent; - mouseup: MapLayerMouseEvent; - mousemove: MapLayerMouseEvent; - mouseenter: MapLayerMouseEvent; - mouseleave: MapLayerMouseEvent; - mouseover: MapLayerMouseEvent; - mouseout: MapLayerMouseEvent; - contextmenu: MapLayerMouseEvent; - - touchstart: MapLayerTouchEvent; - touchend: MapLayerTouchEvent; - touchcancel: MapLayerTouchEvent; - }; - - export type AnyLayout = - | BackgroundLayout - | FillLayout - | FillExtrusionLayout - | LineLayout - | SymbolLayout - | RasterLayout - | CircleLayout - | HeatmapLayout - | HillshadeLayout - | SkyLayout; - - export type AnyPaint = - | BackgroundPaint - | FillPaint - | FillExtrusionPaint - | LinePaint - | SymbolPaint - | RasterPaint - | CirclePaint - | HeatmapPaint - | HillshadePaint - | SkyPaint; - - interface Layer { - id: string; - type: string; - - metadata?: any; - ref?: string | undefined; - - source?: string | AnySourceData | undefined; - - "source-layer"?: string | undefined; - - minzoom?: number | undefined; - maxzoom?: number | undefined; - - interactive?: boolean | undefined; - - filter?: any[] | undefined; - layout?: AnyLayout | undefined; - paint?: AnyPaint | undefined; - } - - interface BackgroundLayer extends Layer { - type: "background"; - layout?: BackgroundLayout | undefined; - paint?: BackgroundPaint | undefined; - } - - interface CircleLayer extends Layer { - type: "circle"; - layout?: CircleLayout | undefined; - paint?: CirclePaint | undefined; - } - - interface FillExtrusionLayer extends Layer { - type: "fill-extrusion"; - layout?: FillExtrusionLayout | undefined; - paint?: FillExtrusionPaint | undefined; - } - - interface FillLayer extends Layer { - type: "fill"; - layout?: FillLayout | undefined; - paint?: FillPaint | undefined; - } - - interface HeatmapLayer extends Layer { - type: "heatmap"; - layout?: HeatmapLayout | undefined; - paint?: HeatmapPaint | undefined; - } - - interface HillshadeLayer extends Layer { - type: "hillshade"; - layout?: HillshadeLayout | undefined; - paint?: HillshadePaint | undefined; - } - - interface LineLayer extends Layer { - type: "line"; - layout?: LineLayout | undefined; - paint?: LinePaint | undefined; - } - - interface RasterLayer extends Layer { - type: "raster"; - layout?: RasterLayout | undefined; - paint?: RasterPaint | undefined; - } - - interface SymbolLayer extends Layer { - type: "symbol"; - layout?: SymbolLayout | undefined; - paint?: SymbolPaint | undefined; - } - - interface SkyLayer extends Layer { - type: "sky"; - layout?: SkyLayout | undefined; - paint?: SkyPaint | undefined; - } - - export type AnyLayer = - | BackgroundLayer - | CircleLayer - | FillExtrusionLayer - | FillLayer - | HeatmapLayer - | HillshadeLayer - | LineLayer - | RasterLayer - | SymbolLayer - | CustomLayerInterface - | SkyLayer; - - // See https://docs.mapbox.com/mapbox-gl-js/api/#customlayerinterface - export interface CustomLayerInterface { - /** A unique layer id. */ - id: string; - - /* The layer's type. Must be "custom". */ - type: "custom"; - - /* Either "2d" or "3d". Defaults to "2d". */ - renderingMode?: "2d" | "3d" | undefined; - - /** - * Optional method called when the layer has been removed from the Map with Map#removeLayer. - * This gives the layer a chance to clean up gl resources and event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onRemove?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called when the layer has been added to the Map with Map#addLayer. - * This gives the layer a chance to initialize gl resources and register event listeners. - * @param map The Map this custom layer was just added to. - * @param gl The gl context for the map. - */ - onAdd?(map: mapboxgl.Map, gl: WebGLRenderingContext): void; - - /** - * Optional method called during a render frame to allow a layer to prepare resources - * or render into a texture. - * - * The layer cannot make any assumptions about the current GL state and must bind a framebuffer - * before rendering. - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - prerender?(gl: WebGLRenderingContext, matrix: number[]): void; - - /** - * Called during a render frame allowing the layer to draw into the GL context. - * - * The layer can assume blending and depth state is set to allow the layer to properly blend - * and clip other layers. The layer cannot make any other assumptions about the current GL state. - * - * If the layer needs to render to a texture, it should implement the prerender method to do this - * and only use the render method for drawing directly into the main framebuffer. - * - * The blend function is set to gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA). This expects - * colors to be provided in premultiplied alpha form where the r, g and b values are already - * multiplied by the a value. If you are unable to provide colors in premultiplied form you may - * want to change the blend function to - * gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA). - * - * @param gl The map's gl context. - * @param matrix The map's camera matrix. It projects spherical mercator coordinates to gl - * coordinates. The mercator coordinate [0, 0] represents the top left corner of - * the mercator world and [1, 1] represents the bottom right corner. When the - * renderingMode is "3d" , the z coordinate is conformal. A box with identical - * x, y, and z lengths in mercator units would be rendered as a cube. - * MercatorCoordinate .fromLatLng can be used to project a LngLat to a mercator - * coordinate. - */ - render(gl: WebGLRenderingContext, matrix: number[]): void; - } - - export interface StyleFunction { - stops?: any[][] | undefined; - property?: string | undefined; - base?: number | undefined; - type?: "identity" | "exponential" | "interval" | "categorical" | undefined; - default?: any; - colorSpace?: "rgb" | "lab" | "hcl" | undefined; - } - - type Visibility = "visible" | "none"; - - export interface Layout { - visibility?: Visibility | undefined; - } - - export interface BackgroundLayout extends Layout {} - - export interface BackgroundPaint { - "background-color"?: string | Expression | undefined; - "background-color-transition"?: Transition | undefined; - "background-pattern"?: string | undefined; - "background-pattern-transition"?: Transition | undefined; - "background-opacity"?: number | Expression | undefined; - "background-opacity-transition"?: Transition | undefined; - } - - export interface FillLayout extends Layout { - "fill-sort-key"?: number | Expression | undefined; - } - - export interface FillPaint { - "fill-antialias"?: boolean | Expression | undefined; - "fill-opacity"?: number | StyleFunction | Expression | undefined; - "fill-opacity-transition"?: Transition | undefined; - "fill-color"?: string | StyleFunction | Expression | undefined; - "fill-color-transition"?: Transition | undefined; - "fill-outline-color"?: string | StyleFunction | Expression | undefined; - "fill-outline-color-transition"?: Transition | undefined; - "fill-translate"?: number[] | undefined; - "fill-translate-transition"?: Transition | undefined; - "fill-translate-anchor"?: "map" | "viewport" | undefined; - "fill-pattern"?: string | Expression | undefined; - "fill-pattern-transition"?: Transition | undefined; - } - - export interface FillExtrusionLayout extends Layout {} - - export interface FillExtrusionPaint { - "fill-extrusion-opacity"?: number | Expression | undefined; - "fill-extrusion-opacity-transition"?: Transition | undefined; - "fill-extrusion-color"?: string | StyleFunction | Expression | undefined; - "fill-extrusion-color-transition"?: Transition | undefined; - "fill-extrusion-translate"?: number[] | Expression | undefined; - "fill-extrusion-translate-transition"?: Transition | undefined; - "fill-extrusion-translate-anchor"?: "map" | "viewport" | undefined; - "fill-extrusion-pattern"?: string | Expression | undefined; - "fill-extrusion-pattern-transition"?: Transition | undefined; - "fill-extrusion-height"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-height-transition"?: Transition | undefined; - "fill-extrusion-base"?: number | StyleFunction | Expression | undefined; - "fill-extrusion-base-transition"?: Transition | undefined; - "fill-extrusion-vertical-gradient"?: boolean | undefined; - } - - export interface LineLayout extends Layout { - "line-cap"?: "butt" | "round" | "square" | Expression | undefined; - "line-join"?: "bevel" | "round" | "miter" | Expression | undefined; - "line-miter-limit"?: number | Expression | undefined; - "line-round-limit"?: number | Expression | undefined; - "line-sort-key"?: number | Expression | undefined; - } - - export interface LinePaint { - "line-opacity"?: number | StyleFunction | Expression | undefined; - "line-opacity-transition"?: Transition | undefined; - "line-color"?: string | StyleFunction | Expression | undefined; - "line-color-transition"?: Transition | undefined; - "line-translate"?: number[] | Expression | undefined; - "line-translate-transition"?: Transition | undefined; - "line-translate-anchor"?: "map" | "viewport" | undefined; - "line-width"?: number | StyleFunction | Expression | undefined; - "line-width-transition"?: Transition | undefined; - "line-gap-width"?: number | StyleFunction | Expression | undefined; - "line-gap-width-transition"?: Transition | undefined; - "line-offset"?: number | StyleFunction | Expression | undefined; - "line-offset-transition"?: Transition | undefined; - "line-blur"?: number | StyleFunction | Expression | undefined; - "line-blur-transition"?: Transition | undefined; - "line-dasharray"?: number[] | Expression | undefined; - "line-dasharray-transition"?: Transition | undefined; - "line-pattern"?: string | Expression | undefined; - "line-pattern-transition"?: Transition | undefined; - "line-gradient"?: Expression | undefined; - } - - export interface SymbolLayout extends Layout { - "symbol-placement"?: "point" | "line" | "line-center" | undefined; - "symbol-spacing"?: number | Expression | undefined; - "symbol-avoid-edges"?: boolean | undefined; - "symbol-z-order"?: "viewport-y" | "source" | undefined; - "icon-allow-overlap"?: boolean | StyleFunction | Expression | undefined; - "icon-ignore-placement"?: boolean | Expression | undefined; - "icon-optional"?: boolean | undefined; - "icon-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "icon-size"?: number | StyleFunction | Expression | undefined; - "icon-text-fit"?: "none" | "both" | "width" | "height" | undefined; - "icon-text-fit-padding"?: number[] | Expression | undefined; - "icon-image"?: string | StyleFunction | Expression | undefined; - "icon-rotate"?: number | StyleFunction | Expression | undefined; - "icon-padding"?: number | Expression | undefined; - "icon-keep-upright"?: boolean | undefined; - "icon-offset"?: number[] | StyleFunction | Expression | undefined; - "icon-anchor"?: Anchor | StyleFunction | Expression | undefined; - "icon-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-pitch-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-rotation-alignment"?: "map" | "viewport" | "auto" | undefined; - "text-field"?: string | StyleFunction | Expression | undefined; - "text-font"?: string[] | Expression | undefined; - "text-size"?: number | StyleFunction | Expression | undefined; - "text-max-width"?: number | StyleFunction | Expression | undefined; - "text-line-height"?: number | Expression | undefined; - "text-letter-spacing"?: number | Expression | undefined; - "text-justify"?: "auto" | "left" | "center" | "right" | Expression | undefined; - "text-anchor"?: Anchor | StyleFunction | Expression | undefined; - "text-max-angle"?: number | Expression | undefined; - "text-rotate"?: number | StyleFunction | Expression | undefined; - "text-padding"?: number | Expression | undefined; - "text-keep-upright"?: boolean | undefined; - "text-transform"?: "none" | "uppercase" | "lowercase" | StyleFunction | Expression | undefined; - "text-offset"?: number[] | Expression | undefined; - "text-allow-overlap"?: boolean | undefined; - "text-ignore-placement"?: boolean | undefined; - "text-optional"?: boolean | undefined; - "text-radial-offset"?: number | Expression | undefined; - "text-variable-anchor"?: Anchor[] | undefined; - "text-writing-mode"?: Array<"horizontal" | "vertical"> | undefined; - "symbol-sort-key"?: number | Expression | undefined; - } - - export interface SymbolPaint { - "icon-opacity"?: number | StyleFunction | Expression | undefined; - "icon-opacity-transition"?: Transition | undefined; - "icon-color"?: string | StyleFunction | Expression | undefined; - "icon-color-transition"?: Transition | undefined; - "icon-halo-color"?: string | StyleFunction | Expression | undefined; - "icon-halo-color-transition"?: Transition | undefined; - "icon-halo-width"?: number | StyleFunction | Expression | undefined; - "icon-halo-width-transition"?: Transition | undefined; - "icon-halo-blur"?: number | StyleFunction | Expression | undefined; - "icon-halo-blur-transition"?: Transition | undefined; - "icon-translate"?: number[] | Expression | undefined; - "icon-translate-transition"?: Transition | undefined; - "icon-translate-anchor"?: "map" | "viewport" | undefined; - "text-opacity"?: number | StyleFunction | Expression | undefined; - "text-opacity-transition"?: Transition | undefined; - "text-color"?: string | StyleFunction | Expression | undefined; - "text-color-transition"?: Transition | undefined; - "text-halo-color"?: string | StyleFunction | Expression | undefined; - "text-halo-color-transition"?: Transition | undefined; - "text-halo-width"?: number | StyleFunction | Expression | undefined; - "text-halo-width-transition"?: Transition | undefined; - "text-halo-blur"?: number | StyleFunction | Expression | undefined; - "text-halo-blur-transition"?: Transition | undefined; - "text-translate"?: number[] | Expression | undefined; - "text-translate-transition"?: Transition | undefined; - "text-translate-anchor"?: "map" | "viewport" | undefined; - } - - export interface RasterLayout extends Layout {} - - export interface RasterPaint { - "raster-opacity"?: number | Expression | undefined; - "raster-opacity-transition"?: Transition | undefined; - "raster-hue-rotate"?: number | Expression | undefined; - "raster-hue-rotate-transition"?: Transition | undefined; - "raster-brightness-min"?: number | Expression | undefined; - "raster-brightness-min-transition"?: Transition | undefined; - "raster-brightness-max"?: number | Expression | undefined; - "raster-brightness-max-transition"?: Transition | undefined; - "raster-saturation"?: number | Expression | undefined; - "raster-saturation-transition"?: Transition | undefined; - "raster-contrast"?: number | Expression | undefined; - "raster-contrast-transition"?: Transition | undefined; - "raster-fade-duration"?: number | Expression | undefined; - "raster-resampling"?: "linear" | "nearest" | undefined; - } - - export interface CircleLayout extends Layout { - "circle-sort-key"?: number | Expression | undefined; - } - - export interface CirclePaint { - "circle-radius"?: number | StyleFunction | Expression | undefined; - "circle-radius-transition"?: Transition | undefined; - "circle-color"?: string | StyleFunction | Expression | undefined; - "circle-color-transition"?: Transition | undefined; - "circle-blur"?: number | StyleFunction | Expression | undefined; - "circle-blur-transition"?: Transition | undefined; - "circle-opacity"?: number | StyleFunction | Expression | undefined; - "circle-opacity-transition"?: Transition | undefined; - "circle-translate"?: number[] | Expression | undefined; - "circle-translate-transition"?: Transition | undefined; - "circle-translate-anchor"?: "map" | "viewport" | undefined; - "circle-pitch-scale"?: "map" | "viewport" | undefined; - "circle-pitch-alignment"?: "map" | "viewport" | undefined; - "circle-stroke-width"?: number | StyleFunction | Expression | undefined; - "circle-stroke-width-transition"?: Transition | undefined; - "circle-stroke-color"?: string | StyleFunction | Expression | undefined; - "circle-stroke-color-transition"?: Transition | undefined; - "circle-stroke-opacity"?: number | StyleFunction | Expression | undefined; - "circle-stroke-opacity-transition"?: Transition | undefined; - } - - export interface HeatmapLayout extends Layout {} - - export interface HeatmapPaint { - "heatmap-radius"?: number | StyleFunction | Expression | undefined; - "heatmap-radius-transition"?: Transition | undefined; - "heatmap-weight"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity"?: number | StyleFunction | Expression | undefined; - "heatmap-intensity-transition"?: Transition | undefined; - "heatmap-color"?: string | StyleFunction | Expression | undefined; - "heatmap-opacity"?: number | StyleFunction | Expression | undefined; - "heatmap-opacity-transition"?: Transition | undefined; - } - - export interface HillshadeLayout extends Layout {} - - export interface HillshadePaint { - "hillshade-illumination-direction"?: number | Expression | undefined; - "hillshade-illumination-anchor"?: "map" | "viewport" | undefined; - "hillshade-exaggeration"?: number | Expression | undefined; - "hillshade-exaggeration-transition"?: Transition | undefined; - "hillshade-shadow-color"?: string | Expression | undefined; - "hillshade-shadow-color-transition"?: Transition | undefined; - "hillshade-highlight-color"?: string | Expression | undefined; - "hillshade-highlight-color-transition"?: Transition | undefined; - "hillshade-accent-color"?: string | Expression | undefined; - "hillshade-accent-color-transition"?: Transition | undefined; - } - - export interface SkyLayout extends Layout {} - - export interface SkyPaint { - "sky-atmosphere-color"?: string | Expression | undefined; - "sky-atmosphere-halo-color"?: string | Expression | undefined; - "sky-atmosphere-sun"?: number[] | Expression | undefined; - "sky-atmosphere-sun-intensity"?: number | Expression | undefined; - "sky-gradient"?: string | Expression | undefined; - "sky-gradient-center"?: number[] | Expression | undefined; - "sky-gradient-radius"?: number | Expression | undefined; - "sky-opacity"?: number | Expression | undefined; - "sky-type"?: "gradient" | "atmosphere" | undefined; - } - - export type ElevationQueryOptions = { - exaggerated: boolean; - }; - - export interface Projection { - name: - | "albers" - | "equalEarth" - | "equirectangular" - | "lambertConformalConic" - | "mercator" - | "naturalEarth" - | "winkelTripel" - | "globe"; - center?: [number, number]; - parallels?: [number, number]; - } -} diff --git a/types/mapbox-gl/v2/mapbox-gl-tests.ts b/types/mapbox-gl/v2/mapbox-gl-tests.ts deleted file mode 100644 index 56219a4ad741f1..00000000000000 --- a/types/mapbox-gl/v2/mapbox-gl-tests.ts +++ /dev/null @@ -1,2055 +0,0 @@ -import { IControl } from "mapbox-gl"; -import mapboxgl = require("mapbox-gl"); - -// These examples adapted from Mapbox's examples (https://www.mapbox.com/mapbox-gl-js/examples) - -/** - * Set API Access Token - */ -mapboxgl.accessToken = "foo"; - -/** - * Set Base API URL - */ -mapboxgl.baseApiUrl = "https://example.com"; - -/** - * Set amount of workers - */ -mapboxgl.workerCount = 3; - -/** - * Set max amount of parallel images requests - */ -mapboxgl.maxParallelImageRequests = 10; - -/** - * Clears browser storage used by this library - */ -mapboxgl.clearStorage(() => {}); - -/** - * Get RTL Text Plugin Status - */ -expectType(mapboxgl.getRTLTextPluginStatus()); - -/** - * Set RTL Text Plugin - */ -// $ExpectType void -mapboxgl.setRTLTextPlugin("https://github.com", e => {}, false); - -// $ExpectType void -mapboxgl.prewarm(); - -// $ExpectType void -mapboxgl.clearPrewarmedResources(); - -/** - * Display a Map - */ -let map = new mapboxgl.Map({ - container: "map", - style: "mapbox://styles/mapbox/streets-v8", - center: [-50, 50], - zoom: 10, - minZoom: 1, - maxZoom: 2, - minPitch: 0, - maxPitch: 60, - interactive: true, - attributionControl: true, - customAttribution: "© YourCo", - bearingSnap: 7, - scrollZoom: true, - maxBounds: [ - [-100, -90], - [100, 90], - ], - boxZoom: true, - dragRotate: false, - dragPan: true, - antialias: true, - accessToken: "some-token", - locale: { - "FullscreenControl.Enter": "Розгорнути на весь екран", - "FullscreenControl.Exit": "Вийти з повоноеранного режиму", - }, - optimizeForTerrain: false, -}); - -/** - * Initialize map with bounds - */ -expectType({ - container: "map", - bounds: new mapboxgl.LngLatBounds([-100, -90, 100, 90]), - fitBoundsOptions: { - padding: 0, - offset: new mapboxgl.Point(0, 0), - linear: true, - maxZoom: 22, - easing: time => time, - }, -}); -expectType({ - container: "map", - bounds: [ - [-100, -90], - [100, 90], - ], - fitBoundsOptions: { - offset: [0, 0], - }, -}); -expectType({ - container: "map", - bounds: [-100, -90, 100, 90], -}); - -expectType({ - container: "map", - touchPitch: true, -}); - -/** - * Check `touchPitch`, `touchZoomRotate`, `scrollZoom` to accept Object - */ -expectType({ - container: "map", - touchPitch: { around: "center" }, - touchZoomRotate: { around: "center" }, - scrollZoom: { around: "center" }, -}); - -/** - * Check `dragPan` to accept Object - */ -expectType({ - container: "map", - dragPan: { - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, - }, -}); - -/** - * Check `cooperativeGestures` - */ -expectType({ - container: "map", - cooperativeGestures: true, -}); - -/** - * Create and style marker clusters - */ -map.on("load", function() { - // Add a new source from our GeoJSON data and set the - // 'cluster' option to true. - map.addSource("data", { - type: "geojson", - data: "/data.geojson", - cluster: true, - clusterMaxZoom: 14, // Max zoom to cluster points on - clusterMinPoints: 8, - clusterRadius: 50, // Radius of each cluster when clustering points (defaults to 50) - clusterProperties: { sum: ["+", ["get", "property"]] }, - filter: "something", - }); - - map.addLayer({ - id: "layer", - type: "symbol", - source: "data", - layout: { - "icon-image": "marker-15", - "text-field": ["get", "property"], - "text-max-width": { - stops: [ - [10, 2], - [12, 5], - ], - }, - }, - }); - - var layers: Array<[number, string]> = [ - [150, "#f28cb1"], - [20, "#f1f075"], - [0, "#51bbd6"], - ]; - - layers.forEach(function(layer, i) { - map.addLayer({ - id: "cluster-" + i, - type: "circle", - source: "data", - paint: { - "circle-color": layer[1], - "circle-radius": 18, - }, - filter: i == 0 - ? [">=", "point_count", layer[0]] - : ["all", [">=", "point_count", layer[0]], ["<", "point_count", layers[i - 1][0]]], - }); - }); - - // Add a layer for the clusters' count labels - map.addLayer({ - id: "cluster-count", - type: "symbol", - source: "data", - layout: { - "text-field": "{point_count}", - "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"], - "text-size": 12, - }, - }); - - /** - * Add a GeoJSON line - */ - map.addSource("route", { - type: "geojson", - data: { - type: "Feature", - properties: {}, - geometry: { - type: "LineString", - coordinates: [ - [-122.48369693756104, 37.83381888486939], - [-122.48348236083984, 37.83317489144141], - [-122.48339653015138, 37.83270036637107], - [-122.48356819152832, 37.832056363179625], - [-122.48404026031496, 37.83114119107971], - [-122.48404026031496, 37.83049717427869], - [-122.48348236083984, 37.829920943955045], - [-122.48356819152832, 37.82954808664175], - [-122.48507022857666, 37.82944639795659], - [-122.48610019683838, 37.82880236636284], - [-122.48695850372314, 37.82931081282506], - [-122.48700141906738, 37.83080223556934], - [-122.48751640319824, 37.83168351665737], - [-122.48803138732912, 37.832158048267786], - [-122.48888969421387, 37.83297152392784], - [-122.48987674713133, 37.83263257682617], - [-122.49043464660643, 37.832937629287755], - [-122.49125003814696, 37.832429207817725], - [-122.49163627624512, 37.832564787218985], - [-122.49223709106445, 37.83337825839438], - [-122.49378204345702, 37.83368330777276], - ], - }, - }, - promoteId: { original: "COUNTY" }, - }); - - map.addLayer({ - id: "route", - type: "line", - source: "route", - layout: { - "line-join": "round", - "line-cap": "round", - }, - paint: { - "line-color": "#888", - "line-width": 8, - "line-dasharray": ["step", ["zoom"], ["literal", [1, 0]], 15, ["literal", [1.75, 1]]], - }, - }); - - // Add a vector source - map.addSource("vector-source", { - type: "vector", - promoteId: { original: "COUNTY" }, - }); - - // Add a custom layer - map.addLayer({ - id: "custom", - type: "custom", - renderingMode: "3d", - onRemove: function(map, gl) { - map; // $ExpectType Map - gl; // $ExpectType WebGLRenderingContext - }, - render: function(gl, matrix) { - gl; // $ExpectType WebGLRenderingContext - matrix; // $ExpectType number[] - }, - }); -}); - -// -// setTerrain -// - -// $ExpectType Map -map.setTerrain(); -// $ExpectType Map -map.setTerrain(null); -// $ExpectType Map -map.setTerrain(undefined); -// $ExpectType Map -map.setTerrain({ - source: "something", - exaggeration: 10, -}); - -// -// getFreeCameraOptions -// - -// $ExpectType FreeCameraOptions -map.getFreeCameraOptions(); - -// -// setFreeCameraOptions -// - -// $ExpectType Map -map.setFreeCameraOptions(new mapboxgl.FreeCameraOptions()); - -// FlyTo -map.flyTo({ - center: [0, 0], - zoom: 10, - speed: 0.5, - curve: 1, - screenSpeed: 1, - easing: function(t: number) { - return t; - }, - maxDuration: 1, -}); - -// RotateTo -map.rotateTo(45, { - duration: 2000, - animate: true, - easing: (t) => t, - center: [-122.3085, 47.5505], - zoom: 10, - pitch: 60, -}); - -// QueryRenderedFeatures -const features = map.queryRenderedFeatures([0, 0], { layers: ["custom"], validate: false }); -features; // $ExpectType MapboxGeoJSONFeature[] - -// querySourceFeatures -const features2 = map.querySourceFeatures("some_source", { - sourceLayer: "source_layer", - filter: ["all"], - validate: null, -}); -features2; // $ExpectType MapboxGeoJSONFeature[] - -/** - * GeoJSONSource - */ -var geoJSONSourceObj = new mapboxgl.GeoJSONSource({ - data: { - type: "FeatureCollection", - features: [ - { - type: "Feature", - properties: null, - geometry: { - type: "Point", - coordinates: [-50, 0], - }, - }, - ], - }, -}); -map.addSource("some id", geoJSONSourceObj); // add -map.removeSource("some id"); // remove - -/** - * ImageSource - */ -var imageSourceObj = new mapboxgl.ImageSource({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", imageSourceObj); // add -map.removeSource("some id"); // remove - -imageSourceObj.updateImage({ - url: "/foo.png", - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); - -imageSourceObj.setCoordinates([ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], -]); - -/** - * Video Source - */ -var videoSourceObj = new mapboxgl.VideoSource({ - urls: ["/blah.mp4", "/blah.webm"], - coordinates: [ - [-76.54335737228394, 39.18579907229748], - [-76.52803659439087, 39.1838364847587], - [-76.5295386314392, 39.17683392507606], - [-76.54520273208618, 39.17876344106642], - ], -}); -map.addSource("some id", videoSourceObj); // add -map.removeSource("some id"); // remove - -/** - * Raster Source - */ -const rasterSource = map.getSource("tile-source") as mapboxgl.RasterSourceImpl; -// $ExpectType void -rasterSource.reload(); -// $ExpectType RasterSourceImpl -rasterSource.setTiles(["a", "b"]); -// $ExpectType RasterSourceImpl -rasterSource.setUrl("https://github.com"); - -/** - * Vector Source - */ -const vectorSource = map.getSource("tile-source") as mapboxgl.VectorSourceImpl; -// $ExpectType void -vectorSource.reload(); -// $ExpectType VectorSourceImpl -vectorSource.setTiles(["a", "b"]); -// $ExpectType VectorSourceImpl -vectorSource.setUrl("https://github.com"); - -/** - * Add Raster Source /// made URL optional to allow only tiles. - */ -map.addSource("radar", { - type: "raster", - tiles: [ - "https://nowcoast.noaa.gov/arcgis/services/nowcoast/radar_meteo_imagery_nexrad_time/MapServer/WmsServer?bbox={bbox-epsg-3857}&service=WMS&request=GetMap&version=1.3.0&layers=1&styles=&format=image/png&transparent=true&height=256&width=256&crs=EPSG:3857", - ], - tileSize: 256, -}); - -map.addLayer({ - id: "radar", - type: "raster", - source: "radar", - paint: {}, -}); - -/** - * Manipulate feature state - */ -let featureIdentifier = { - id: 1337, - source: "source-id", - sourceLayer: "liam-was-here", -}; -expectType(featureIdentifier); -map.setFeatureState(featureIdentifier, { someState: true, someOtherState: 123 }); -map.getFeatureState(featureIdentifier); -map.removeFeatureState(featureIdentifier, "someState"); -map.removeFeatureState(featureIdentifier); - -/** - * Popup - */ -const popupOptions: mapboxgl.PopupOptions = { - closeOnClick: false, - closeOnMove: true, - closeButton: true, - focusAfterOpen: true, - anchor: "top-right", - offset: { - top: [0, 0] as [number, number], - bottom: [25, -50] as [number, number], - }, - className: "custom-class", - maxWidth: "400px", -}; - -const popup = new mapboxgl.Popup(popupOptions) - .setLngLat([-50, 50]) - .trackPointer() - .setHTML("

Hello World!

") - .setMaxWidth("none") - .addTo(map); -popup.getMaxWidth(); -popup.getElement(); // $ExpectType HTMLElement -popup.addClassName("class1"); -popup.removeClassName("class2"); -popup.toggleClassName("class3"); -// $ExpectType Popup -popup.setOffset([10, 20]); - -/** - * Add terrain - */ -const terrainStyle: mapboxgl.Style = { - version: 8, - name: "terrain", - sources: { - dem: { - type: "raster-dem", - url: "mapbox://mapbox.mapbox-terrain-dem-v1", - }, - }, - layers: [], - terrain: { - source: "dem", - exaggeration: 1.5, - }, -}; - -/** - * Add an image - */ -var mapStyle: mapboxgl.Style = { - version: 8, - name: "Dark", - sources: { - mapbox: { - type: "vector", - url: "mapbox://mapbox.mapbox-streets-v6", - }, - overlay: { - type: "image", - url: "/mapbox-gl-js/assets/radar.gif", - coordinates: [ - [-50, 40], - [0, 40], - [0, 0], - [-50, 0], - ], - }, - }, - sprite: "mapbox://sprites/mapbox/dark-v8", - glyphs: "mapbox://fonts/mapbox/{fontstack}/{range}.pbf", - layers: [ - { - id: "background", - type: "background", - paint: { "background-color": "#111" }, - }, - { - id: "water", - source: "mapbox", - "source-layer": "water", - type: "fill", - paint: { "fill-color": "#2c2c2c" }, - }, - { - id: "boundaries", - source: "mapbox", - "source-layer": "admin", - type: "line", - paint: { "line-color": "#797979", "line-dasharray": [2, 2, 6, 2] }, - filter: ["all", ["==", "maritime", 0]], - }, - { - id: "overlay", - source: "overlay", - type: "raster", - paint: { "raster-opacity": 0.85 }, - }, - { - id: "cities", - source: "mapbox", - "source-layer": "place_label", - type: "symbol", - layout: { - "text-field": "{name_en}", - "text-font": ["DIN Offc Pro Bold", "Arial Unicode MS Bold"], - "text-size": { - stops: [ - [4, 9], - [6, 12], - ], - }, - }, - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - { - id: "states", - source: "mapbox", - "source-layer": "state_label", - type: "symbol", - layout: { - "text-transform": "uppercase", - "text-field": "{name_en}", - "text-font": [ - "step", - ["zoom"], - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - 8, - [ - "step", - ["get", "symbolrank"], - ["literal", ["DIN Offc Pro Medium", "Arial Unicode MS Regular"]], - 11, - ["literal", ["DIN Offc Pro Regular", "Arial Unicode MS Regular"]], - ], - ], - "text-justify": [ - "step", - ["zoom"], - [ - "match", - ["get", "text_anchor"], - ["bottom", "top"], - "center", - ["left", "bottom-left", "top-left"], - "left", - ["right", "bottom-right", "top-right"], - "right", - "center", - ], - 8, - "center", - ], - "text-letter-spacing": 0.15, - "text-max-width": 7, - "text-size": { - stops: [ - [4, 10], - [6, 14], - ], - }, - }, - filter: [">=", "area", 80000], - paint: { - "text-color": "#969696", - "text-halo-width": 2, - "text-halo-color": "rgba(0, 0, 0, 0.85)", - }, - }, - ], -}; - -/** - * Add video - */ -var videoStyle: mapboxgl.Style = { - version: 8, - sources: { - satellite: { - type: "raster", - url: "mapbox://mapbox.satellite", - tileSize: 256, - }, - video: { - type: "video", - urls: ["drone.mp4", "drone.webm"], - coordinates: [ - [-122.51596391201019, 37.56238816766053], - [-122.51467645168304, 37.56410183312965], - [-122.51309394836426, 37.563391708549425], - [-122.51423120498657, 37.56161849366671], - ], - }, - }, - layers: [ - { - id: "background", - type: "background", - paint: { - "background-color": "rgb(4,7,14)", - }, - }, - { - id: "satellite", - type: "raster", - source: "satellite", - }, - { - id: "video", - type: "raster", - source: "video", - }, - ], -}; - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: mapStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - minZoom: 14, - zoom: 17, - center: [-122.514426, 37.562984], - bearing: -96, - style: videoStyle, - hash: false, -}); - -map = new mapboxgl.Map({ - container: "map", - hash: "customHash", -}); - -const syncOnce: mapboxgl.Map = map.once("load", () => {}); -const asyncOnce: Promise = map.once("load"); - -/** - * Marker - */ -let marker = new mapboxgl.Marker(undefined, { - element: undefined, - offset: [10, 0], - anchor: "bottom-right", - color: "green", - draggable: false, - clickTolerance: 10, - rotation: 15, - rotationAlignment: "map", - pitchAlignment: "viewport", - scale: 5.5, - occludedOpacity: 0.5, -}) - .setLngLat([-50, 50]) - .setPitchAlignment("map") - .setRotation(100) - .setRotationAlignment("viewport") - .addTo(map); - -// $ExpectType Alignment -marker.getPitchAlignment(); - -// $ExpectType number -marker.getRotation(); - -// $ExpectType Alignment -marker.getRotationAlignment(); - -// $ExpectType number -marker.getOccludedOpacity(); - -// $ExpectType Marker -marker.setOccludedOpacity(1); - -marker.remove(); - -/* - * LngLatBounds - */ -let bool: boolean; -let bounds = new mapboxgl.LngLatBounds(); -bool = bounds.isEmpty(); -expectType(bounds.contains([37, 50])); - -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLat(45, 30)); -// $ExpectType LngLatBounds -bounds.extend({ lng: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend({ lon: 45, lat: 30 }); -// $ExpectType LngLatBounds -bounds.extend([45, 30]); -// $ExpectType LngLatBounds -bounds.extend(new mapboxgl.LngLatBounds()); -// $ExpectType LngLatBounds -bounds.extend([ - [45, 30], - [60, 60], -]); -// $ExpectType LngLatBounds -bounds.extend([45, 30, 60, 60]); - -// controls -// $ExpectType IControl -new mapboxgl.Control() as IControl; -// $ExpectType IControl -new mapboxgl.AttributionControl() as IControl; - -/* - * GeolocateControl - */ -const geolocateControl = new mapboxgl.GeolocateControl({ showAccuracyCircle: true }); - -/* - * AttributionControl - */ -let attributionControl = new mapboxgl.AttributionControl({ compact: false, customAttribution: "© YourCo" }); -attributionControl.on("click", () => {}); - -/* - * FullscreenControl - */ -new mapboxgl.FullscreenControl(); -new mapboxgl.FullscreenControl(null); -new mapboxgl.FullscreenControl({}); -new mapboxgl.FullscreenControl({ container: document.querySelector("body") }); - -// $ExpectType boolean -map.hasControl(attributionControl); - -declare var lnglat: mapboxgl.LngLat; -declare var lnglatlike: mapboxgl.LngLatLike; -declare var lnglatboundslike: mapboxgl.LngLatBoundsLike; -declare var mercatorcoordinate: mapboxgl.MercatorCoordinate; -declare var pointlike: mapboxgl.PointLike; - -function expectType(value: T) { - return value; -} - -// prettier-ignore -interface EitherType { -
(a: A): A; - (a: A, b: B): A | B; - (a: A, b: B, c: C): A | B | C; - (a: A, b: B, c: C, d: D): A | B | C | D; - (a: A, b: B, c: C, d: D, e: E): A | B | C | D | E; - (a: A, b: B, c: C, d: D, e: E, f: F): A | B | C | D | E | F; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G): A | B | C | D | E | F | G; - (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H): A | B | C | D | E | F | G | H; - ( - a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - ): A | B | C | D | E | F | G | H | I; - ( - a: A, - b: B, - c: C, - d: D, - e: E, - f: F, - g: G, - h: H, - i: I, - j: J, - ): A | B | C | D | E | F | G | H | I | J; - /* Add more as needed */ -} - -/** - * Takes a variable amount of arguments and returns a new - * type that is a union of all the provided argument types. Useful to test properties - * that accept multiple types - */ -const eitherType: EitherType = () => { - /* let the compiler handle things */ -}; - -/* - * LngLatLike - */ - -expectType(new mapboxgl.LngLat(0, 0)); -expectType([0, 0]); -expectType({ lng: 0, lat: 0 }); -expectType({ lon: 0, lat: 0 }); - -/* - * LngLat - */ - -new mapboxgl.LngLat(0, 0); -expectType(mapboxgl.LngLat.convert(lnglatlike)); -expectType(new mapboxgl.LngLat(0, 0).distanceTo(new mapboxgl.LngLat(0, 0))); - -/* - * LngLatBoundsLike - */ - -expectType([lnglatlike, lnglatlike]); -expectType([0, 0, 1, 1]); -expectType(new mapboxgl.LngLatBounds()); - -/* - * LngLatBounds - */ - -new mapboxgl.LngLatBounds(); -new mapboxgl.LngLatBounds([0, 0, 1, 1]); -new mapboxgl.LngLatBounds([lnglatlike, lnglatlike]); -new mapboxgl.LngLatBounds(lnglat, lnglat); -new mapboxgl.LngLatBounds(lnglatlike, lnglatlike); -expectType(mapboxgl.LngLatBounds.convert(lnglatboundslike)); - -/* - * PointLike - */ - -expectType(new mapboxgl.Point(0, 0)); -expectType([0, 0]); - -/* - * Point - */ - -new mapboxgl.Point(0, 0); -expectType(mapboxgl.Point.convert(pointlike)); - -/* - * MercatorCoordinate - */ - -new mapboxgl.MercatorCoordinate(0, 0); -new mapboxgl.MercatorCoordinate(0, 0, 0); -mercatorcoordinate.toAltitude(); // $ExpectType number -mercatorcoordinate.toLngLat(); // $ExpectType LngLat -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike); // $ExpectType MercatorCoordinate -mapboxgl.MercatorCoordinate.fromLngLat(lnglatlike, 0); // $ExpectType MercatorCoordinate -mercatorcoordinate.meterInMercatorCoordinateUnits(); // $ExpectType number - -/* - * TransformRequestFunction - */ - -expectType((url: string) => ({ url })); -expectType((url: string, resourceType: mapboxgl.ResourceType) => ({ - url, - credentials: "same-origin", - headers: { "Accept-Encoding": "compress" }, - method: "POST", - collectResourceTiming: true, -})); - -/* - * Map - */ - -let padding: mapboxgl.PaddingOptions = { - top: 0, - bottom: 0, - left: 0, - right: 0, -}; -let animOpts: mapboxgl.AnimationOptions = { - essential: true, -}; -let cameraOpts: mapboxgl.CameraOptions = { - around: lnglatlike, - center: lnglatlike, - bearing: 0, - pitch: 0, - zoom: 0, - padding, -}; -let cameraForBoundsOpts: mapboxgl.CameraForBoundsOptions = { - offset: pointlike, - maxZoom: 10, - ...cameraOpts, -}; - -expectType(map.cameraForBounds(lnglatboundslike)); -expectType(map.cameraForBounds(lnglatboundslike, cameraForBoundsOpts)); - -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts)); -expectType(map.fitScreenCoordinates([0, 0], pointlike, 1, cameraOpts, { key: "value" })); - -// $ExpectType void -map.triggerRepaint(); - -// $ExpectType PaddingOptions -map.getPadding(); - -// $ExpectType Map -map.setPadding({ top: 10, bottom: 20, left: 30, right: 40 }, { myData: "MY DATA" }); - -map.setPaintProperty("layerId", "layerName", null, { validate: true }); -map.setPaintProperty("layerId", "layerName", null, { validate: false }); -map.setPaintProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setPaintProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLayoutProperty("layerId", "layerName", null, { validate: true }); -map.setLayoutProperty("layerId", "layerName", null, { validate: false }); -map.setLayoutProperty("layerId", "layerName", null, {}); -// @ts-expect-error -map.setLayoutProperty("layerId", "layerName", null, { some_option: "some_string" }); - -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: true }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { validate: false }); -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, {}); -// @ts-expect-error -map.setLight({ anchor: "viewport", color: "blue", intensity: 0.5 }, { some_option: "some_string" }); - -// $ExpectType boolean -map.showPadding; -map.showPadding = false; - -expectType(map.setFilter("layerId", true)); -expectType(map.setFilter("layerId", false)); - -map.setFilter("layerId", true, { validate: true }); -map.setFilter("layerId", true, { validate: null }); -map.setFilter("layerId", true, {}); -// @ts-expect-error -map.setFilter("layerId", true, { some_option: "some_string" }); - -// $ExpectType Map -map.setMinZoom(5); -// $ExpectType Map -map.setMaxZoom(10); -// $ExpectType Map -map.setMinZoom(null); -// $ExpectType Map -map.setMinZoom(); -// $ExpectType Map -map.setMaxZoom(null); -// $ExpectType Map -map.setMaxZoom(); - -// $ExpectType number -map.getMinZoom(); -// $ExpectType number -map.getMaxZoom(); - -// $ExpectType Map -map.setMinPitch(5); -// $ExpectType Map -map.setMaxPitch(10); -// $ExpectType Map -map.setMinPitch(null); -// $ExpectType Map -map.setMinPitch(); -// $ExpectType Map -map.setMaxPitch(null); -// $ExpectType Map -map.setMaxPitch(); -// $ExpectType Map -map.resetNorthPitch(animOpts); - -// $ExpectType number -map.getMinPitch(); -// $ExpectType number -map.getMaxPitch(); - -// $ExpectType Map -map.setFog({ - color: "blue", - "horizon-blend": 0.5, - range: [4, 15], - "high-color": "red", - "space-color": "black", - "star-intensity": 0.5, -}); -// $ExpectType Map -map.setFog(null); -// $ExpectType Map -map.setFog(undefined); - -// $ExpectType Fog | null -map.getFog(); - -/* - * Map Events - */ - -// General events -expectType( - map.on("load", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -// $ExpectType Map -map.on("idle", ev => { - ev; // $ExpectType MapboxEvent & EventData -}); -expectType( - map.on("remove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("render", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("resize", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Error event -expectType( - map.on("error", ev => { - expectType(ev); - expectType(ev.error); - expectType(ev.originalEvent); - }), -); - -// Mouse events -expectType( - map.on("mousedown", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseup", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("click", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("dblclick", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mousemove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseover", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("mouseout", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("contextmenu", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.point); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Touch events -expectType( - map.on("touchcancel", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchmove", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchend", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); -expectType( - map.on("touchstart", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.lngLat); - expectType(ev.lngLats); - expectType(ev.point); - expectType(ev.points); - - // $ExpectType void - ev.preventDefault(); - expectType(ev.defaultPrevented); - - expectType(ev.originalEvent); - }), -); - -// Context events -expectType( - map.on("webglcontextlost", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("webglcontextrestored", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); - -// Data events -expectType( - map.on("dataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("data", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("tiledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - }), -); -expectType( - map.on("sourcedataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("sourcedata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"source">(ev.dataType); - }), -); -expectType( - map.on("styledataloading", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); -expectType( - map.on("styledata", ev => { - expectType(ev); - expectType(ev.target); - expectType(ev.originalEvent); - expectType<"style">(ev.dataType); - }), -); - -// Layer events -expectType( - map.on("click", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("dblclick", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousedown", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseup", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mousemove", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseenter", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseleave", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseover", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("mouseout", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("contextmenu", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.on("touchstart", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchend", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.on("touchcancel", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.once("click", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("dblclick", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mousedown", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseup", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mousemove", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseenter", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseleave", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseover", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("mouseout", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("contextmenu", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType( - map.once("touchstart", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("touchend", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); -expectType( - map.once("touchcancel", eitherType("text", ["text1", "text2"]), ev => { - expectType(ev); - expectType(ev.features); - }), -); - -expectType(map.off("click", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("dblclick", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mousedown", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseup", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mousemove", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseenter", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseleave", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseover", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("mouseout", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("contextmenu", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchstart", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchend", eitherType("text", ["text1", "text2"]), () => {})); -expectType(map.off("touchcancel", eitherType("text", ["text1", "text2"]), () => {})); - -/* - * Expression - */ -expectType(["id"]); -expectType(["get", "property"]); -expectType([ - "format", - ["concat", ["get", "name"], "\n"], - {}, - ["concat", ["get", "area"], "foobar", { "font-scale": 0.8 }], -]); -expectType([ - "number-format", - ["get", "quantity"], - { "min-fraction-digits": 1, "max-fraction-digits": 1 }, -]); -const expression = expectType(["coalesce", ["get", "property"], ["get", "property"]]); - -/* - * ScrollZoomHandler - */ -// $ExpectType void -new mapboxgl.Map().scrollZoom.setZoomRate(1); - -// $ExpectType void -new mapboxgl.Map().scrollZoom.setWheelZoomRate(1); -new mapboxgl.Map().scrollZoom.enable({ around: "center" }); - -const touchPitchHandler = new mapboxgl.TouchPitchHandler(map); -// $ExpectType void -touchPitchHandler.enable(); -touchPitchHandler.enable({ around: "center" }); -// $ExpectType boolean -touchPitchHandler.isActive(); -// $ExpectType boolean -touchPitchHandler.isEnabled(); -// $ExpectType void -touchPitchHandler.disable(); - -new mapboxgl.Map().touchPitch = touchPitchHandler; - -/** - * `dragPan` - */ -// $ExpectType void -new mapboxgl.Map().dragPan.enable({ - linearity: 0.3, - easing: t => t, - maxSpeed: 1400, - deceleration: 2500, -}); - -/** - * `touchZoomRotate` - */ -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({ - around: "center", -}); -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable(); - -// $ExpectType void -new mapboxgl.Map().touchZoomRotate.enable({}); - -/* - * Visibility - */ -expectType("visible"); -expectType("none"); - -/* - * Transition - */ - -expectType({ duration: 0 }); -expectType({ delay: 0 }); -const transition = expectType({ duration: 0, delay: 0 }); - -/* - * StyleFunction - */ - -expectType({ base: 1, type: "categorical" }); -const styleFunction = expectType({ - base: 1, - type: "exponential", - default: 0, - stops: [ - [1, 2], - [3, 4], - ], -}); - -/* - * Anchor - */ - -expectType( - eitherType("center", "left", "right", "top", "bottom", "top-left", "top-right", "bottom-left", "bottom-right"), -); -const anchor: mapboxgl.Anchor = "center"; - -/* - * Layouts and Paint options - */ - -const backgroundLayout: mapboxgl.BackgroundLayout = { - visibility: eitherType("visible", "none"), -}; - -const backgroundPaint: mapboxgl.BackgroundPaint = { - "background-color": eitherType("#000", expression), - "background-color-transition": transition, - "background-pattern": "pattern", - "background-pattern-transition": transition, - "background-opacity": eitherType(0, expression), - "background-opacity-transition": transition, -}; - -const fillLayout: mapboxgl.FillLayout = { - "fill-sort-key": eitherType(0, expression), -}; - -const fillPaint: mapboxgl.FillPaint = { - "fill-antialias": eitherType(false, expression), - "fill-opacity": eitherType(0, styleFunction, expression), - "fill-opacity-transition": transition, - "fill-color": eitherType("#000", styleFunction, expression), - "fill-color-transition": transition, - "fill-outline-color": eitherType("#000", styleFunction, expression), - "fill-outline-color-transition": transition, - "fill-translate": [1], - "fill-translate-transition": transition, - "fill-translate-anchor": eitherType("map", "viewport"), - "fill-pattern": eitherType("#000", expression), - "fill-pattern-transition": transition, -}; - -const fillExtrusionLayout: mapboxgl.FillExtrusionLayout = { - visibility: eitherType("visible", "none"), -}; - -const fillExtrusionPaint: mapboxgl.FillExtrusionPaint = { - "fill-extrusion-opacity": eitherType(0, expression), - "fill-extrusion-opacity-transition": transition, - "fill-extrusion-color": eitherType("#000", styleFunction, expression), - "fill-extrusion-color-transition": transition, - "fill-extrusion-translate": eitherType([0], expression), - "fill-extrusion-translate-transition": transition, - "fill-extrusion-translate-anchor": eitherType("map", "viewport"), - "fill-extrusion-pattern": eitherType("#000", expression), - "fill-extrusion-pattern-transition": transition, - "fill-extrusion-height": eitherType(0, styleFunction, expression), - "fill-extrusion-height-transition": transition, - "fill-extrusion-base": eitherType(0, styleFunction, expression), - "fill-extrusion-base-transition": transition, - "fill-extrusion-vertical-gradient": false, -}; - -const lineLayout: mapboxgl.LineLayout = { - "line-cap": eitherType("butt", "round", "square"), - "line-join": eitherType("bevel", "round", "miter", expression), - "line-miter-limit": eitherType(0, expression), - "line-round-limit": eitherType(0, expression), - "line-sort-key": eitherType(0, expression), -}; - -const linePaint: mapboxgl.LinePaint = { - "line-opacity": eitherType(0, styleFunction, expression), - "line-opacity-transition": transition, - "line-color": eitherType("#000", styleFunction, expression), - "line-color-transition": transition, - "line-translate": eitherType([0], expression), - "line-translate-transition": transition, - "line-translate-anchor": eitherType("map", "viewport"), - "line-width": eitherType(0, styleFunction, expression), - "line-width-transition": transition, - "line-gap-width": eitherType(0, styleFunction, expression), - "line-gap-width-transition": transition, - "line-offset": eitherType(0, styleFunction, expression), - "line-offset-transition": transition, - "line-blur": eitherType(0, styleFunction, expression), - "line-blur-transition": transition, - "line-dasharray": eitherType([0], expression), - "line-dasharray-transition": transition, - "line-pattern": eitherType("#000", expression), - "line-pattern-transition": transition, - "line-gradient": expression, -}; - -const symbolLayout: mapboxgl.SymbolLayout = { - "symbol-placement": eitherType("point", "line", "line-center"), - "symbol-spacing": eitherType(0, expression), - "symbol-avoid-edges": false, - "symbol-z-order": eitherType("viewport-y", "source"), - "icon-allow-overlap": eitherType(false, styleFunction, expression), - "icon-ignore-placement": eitherType(false, expression), - "icon-optional": false, - "icon-rotation-alignment": eitherType("map", "viewport", "auto"), - "icon-size": eitherType(0, styleFunction, expression), - "icon-text-fit": eitherType("none", "both", "width", "height"), - "icon-text-fit-padding": eitherType([0], expression), - "icon-image": eitherType("#000", styleFunction, expression), - "icon-rotate": eitherType(0, styleFunction, expression), - "icon-padding": eitherType(0, expression), - "icon-keep-upright": false, - "icon-offset": eitherType([0], styleFunction, expression), - "icon-anchor": eitherType("center", styleFunction, expression), - "icon-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-pitch-alignment": eitherType("map", "viewport", "auto"), - "text-rotation-alignment": eitherType("map", "viewport", "auto"), - "text-field": eitherType("#000", styleFunction, expression), - "text-font": eitherType(["arial"], expression), - "text-size": eitherType(0, styleFunction, expression), - "text-max-width": eitherType(0, styleFunction, expression), - "text-line-height": eitherType(0, expression), - "text-letter-spacing": eitherType(0, expression), - "text-justify": eitherType("auto", "left", "center", "right", expression), - "text-anchor": eitherType("center", styleFunction, expression), - "text-max-angle": eitherType(0, expression), - "text-rotate": eitherType(0, styleFunction, expression), - "text-padding": eitherType(0, expression), - "text-keep-upright": false, - "text-transform": eitherType("none", "uppercase", "lowercase", styleFunction, expression), - "text-offset": eitherType([0], expression), - "text-allow-overlap": false, - "text-ignore-placement": false, - "text-optional": false, - "text-radial-offset": eitherType(0, expression), - "text-variable-anchor": [anchor], - "text-writing-mode": eitherType< - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical">, - Array<"horizontal" | "vertical"> - >(["horizontal"], ["vertical"], ["horizontal", "vertical"]), - "symbol-sort-key": eitherType(0, expression), -}; - -const symbolPaint: mapboxgl.SymbolPaint = { - "icon-opacity": eitherType(0, styleFunction, expression), - "icon-opacity-transition": transition, - "icon-color": eitherType("#000", styleFunction, expression), - "icon-color-transition": transition, - "icon-halo-color": eitherType("#000", styleFunction, expression), - "icon-halo-color-transition": transition, - "icon-halo-width": eitherType(0, styleFunction, expression), - "icon-halo-width-transition": transition, - "icon-halo-blur": eitherType(0, styleFunction, expression), - "icon-halo-blur-transition": transition, - "icon-translate": eitherType([0], expression), - "icon-translate-transition": transition, - "icon-translate-anchor": eitherType("map", "viewport"), - "text-opacity": eitherType(0, styleFunction, expression), - "text-opacity-transition": transition, - "text-color": eitherType("#000", styleFunction, expression), - "text-color-transition": transition, - "text-halo-color": eitherType("#000", styleFunction, expression), - "text-halo-color-transition": transition, - "text-halo-width": eitherType(0, styleFunction, expression), - "text-halo-width-transition": transition, - "text-halo-blur": eitherType(0, styleFunction, expression), - "text-halo-blur-transition": transition, - "text-translate": eitherType([0], expression), - "text-translate-transition": transition, - "text-translate-anchor": eitherType("map", "viewport"), -}; - -const rasterLayout: mapboxgl.RasterLayout = { - visibility: eitherType("visible", "none"), -}; - -const rasterPaint: mapboxgl.RasterPaint = { - "raster-opacity": eitherType(0, expression), - "raster-opacity-transition": transition, - "raster-hue-rotate": eitherType(0, expression), - "raster-hue-rotate-transition": transition, - "raster-brightness-min": eitherType(0, expression), - "raster-brightness-min-transition": transition, - "raster-brightness-max": eitherType(0, expression), - "raster-brightness-max-transition": transition, - "raster-saturation": eitherType(0, expression), - "raster-saturation-transition": transition, - "raster-contrast": eitherType(0, expression), - "raster-contrast-transition": transition, - "raster-fade-duration": eitherType(0, expression), - "raster-resampling": eitherType("linear", "nearest"), -}; - -const circleLayout: mapboxgl.CircleLayout = { - visibility: eitherType("visible", "none"), - "circle-sort-key": eitherType(0, expression), -}; - -const circlePaint: mapboxgl.CirclePaint = { - "circle-radius": eitherType(0, styleFunction, expression), - "circle-radius-transition": transition, - "circle-color": eitherType("#000", styleFunction, expression), - "circle-color-transition": transition, - "circle-blur": eitherType(0, styleFunction, expression), - "circle-blur-transition": transition, - "circle-opacity": eitherType(0, styleFunction, expression), - "circle-opacity-transition": transition, - "circle-translate": eitherType([0], expression), - "circle-translate-transition": transition, - "circle-translate-anchor": eitherType("map", "viewport"), - "circle-pitch-scale": eitherType("map", "viewport"), - "circle-pitch-alignment": eitherType("map", "viewport"), - "circle-stroke-width": eitherType(0, styleFunction, expression), - "circle-stroke-width-transition": transition, - "circle-stroke-color": eitherType("#000", styleFunction, expression), - "circle-stroke-color-transition": transition, - "circle-stroke-opacity": eitherType(0, styleFunction, expression), - "circle-stroke-opacity-transition": transition, -}; - -const heatmapLayout: mapboxgl.HeatmapLayout = { - visibility: eitherType("visible", "none"), -}; - -const heatmapPaint: mapboxgl.HeatmapPaint = { - "heatmap-radius": eitherType(0, styleFunction, expression), - "heatmap-radius-transition": transition, - "heatmap-weight": eitherType(0, styleFunction, expression), - "heatmap-intensity": eitherType(0, styleFunction, expression), - "heatmap-intensity-transition": transition, - "heatmap-color": eitherType("#000", styleFunction, expression), - "heatmap-opacity": eitherType(0, styleFunction, expression), - "heatmap-opacity-transition": transition, -}; - -const hillshadeLayout: mapboxgl.HillshadeLayout = { - visibility: eitherType("visible", "none"), -}; - -const hillshadePaint: mapboxgl.HillshadePaint = { - "hillshade-illumination-direction": eitherType(0, expression), - "hillshade-illumination-anchor": eitherType("map", "viewport"), - "hillshade-exaggeration": eitherType(0, expression), - "hillshade-exaggeration-transition": transition, - "hillshade-shadow-color": eitherType("#000", expression), - "hillshade-shadow-color-transition": transition, - "hillshade-highlight-color": eitherType("#000", expression), - "hillshade-highlight-color-transition": transition, - "hillshade-accent-color": eitherType("#000", expression), - "hillshade-accent-color-transition": transition, -}; - -const skyLayout: mapboxgl.SkyLayout = { - visibility: eitherType("visible", "none"), -}; - -const skyPaint: mapboxgl.SkyPaint = { - "sky-atmosphere-color": eitherType("white", expression), - "sky-atmosphere-halo-color": eitherType("white", expression), - "sky-atmosphere-sun": eitherType([0], expression), - "sky-atmosphere-sun-intensity": eitherType(0, expression), - "sky-gradient": eitherType("#000", expression), - "sky-gradient-center": eitherType([0], expression), - "sky-gradient-radius": eitherType(0, expression), - "sky-opacity": eitherType(0, expression), - "sky-type": eitherType("gradient", "atmosphere"), -}; - -/* Make sure every layout has all properties optional */ -eitherType< - mapboxgl.BackgroundLayout, - mapboxgl.FillLayout, - mapboxgl.FillExtrusionLayout, - mapboxgl.LineLayout, - mapboxgl.SymbolLayout, - mapboxgl.RasterLayout, - mapboxgl.CircleLayout, - mapboxgl.HeatmapLayout, - mapboxgl.HillshadeLayout, - mapboxgl.SkyLayout ->({}, {}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* Make sure every paint has all properties optional */ -eitherType< - mapboxgl.BackgroundPaint, - mapboxgl.FillPaint, - mapboxgl.FillExtrusionPaint, - mapboxgl.LinePaint, - mapboxgl.SymbolPaint, - mapboxgl.RasterPaint, - mapboxgl.CirclePaint, - mapboxgl.HeatmapPaint, - mapboxgl.HillshadePaint, - mapboxgl.SkyPaint ->({}, {}, {}, {}, {}, {}, {}, {}, {}, {}); - -/* - * AnyLayout - */ -expectType( - eitherType( - backgroundLayout, - fillLayout, - fillExtrusionLayout, - lineLayout, - symbolLayout, - rasterLayout, - circleLayout, - heatmapLayout, - hillshadeLayout, - skyLayout, - ), -); - -/* - * AnyPaint - */ -expectType( - eitherType( - backgroundPaint, - fillPaint, - fillExtrusionPaint, - linePaint, - symbolPaint, - rasterPaint, - circlePaint, - heatmapPaint, - hillshadePaint, - skyPaint, - ), -); - -/* - * Make sure layer gets proper Paint, corresponding to layer's type - */ - -expectType({ id: "unique", type: "background", paint: { "background-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "background", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "fill", paint: { "fill-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "fill", paint: { "line-opacity": 1 } }); - -expectType({ id: "unique", type: "line", paint: { "line-opacity": 1 } }); -// @ts-expect-error -expectType({ id: "unique", type: "line", paint: { "fill-opacity": 1 } }); - -/** - * Test map.addImage() - */ - -// HTMLImageElement -const fooHTMLImageElement = document.createElement("img"); -map.addImage("foo", fooHTMLImageElement); - -// ImageData -const fooImageData = new ImageData(8, 8); -map.addImage("foo", fooImageData); - -// ImageData like -const fooImageDataLike1 = { - width: 10, - height: 10, - data: new Uint8ClampedArray(8), -}; -map.addImage("foo", fooImageDataLike1); - -const fooImageDataLike2 = { - width: 10, - height: 10, - data: new Uint8Array(8), -}; -map.addImage("foo", fooImageDataLike2); - -// ArrayBufferView -const fooArrayBufferView: ArrayBufferView = new Uint8Array(8); -map.addImage("foo", fooArrayBufferView); - -// ImageBitmap -createImageBitmap(fooHTMLImageElement).then(fooImageBitmap => { - map.addImage("foo", fooImageBitmap); -}); - -// $ExpectType void -map.loadImage("foo", (error, result) => {}); - -// KeyboardHandler -var keyboardHandler = new mapboxgl.KeyboardHandler(map); -// $ExpectType void -keyboardHandler.enableRotation(); -// $ExpectType void -keyboardHandler.disableRotation(); - -/** - * Test projections - */ - -// projection config: name only -expectType({ name: "mercator" }); - -// projection config: with center and parallels -expectType({ name: "lambertConformalConic", center: [0, 0], parallels: [30, 60] }); - -// set projection with string -map.setProjection("mercator"); - -// set projection with config -map.setProjection({ name: "globe" }); - -// get projections -expectType(map.getProjection()); diff --git a/types/mapbox-gl/v2/package.json b/types/mapbox-gl/v2/package.json deleted file mode 100644 index f7ce8ca77e39e6..00000000000000 --- a/types/mapbox-gl/v2/package.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "private": true, - "name": "@types/mapbox-gl", - "version": "2.7.9999", - "projects": [ - "https://github.com/mapbox/mapbox-gl-js" - ], - "dependencies": { - "@types/geojson": "*" - }, - "devDependencies": { - "@types/mapbox-gl": "workspace:." - }, - "owners": [ - { - "name": "Dominik Bruderer", - "githubUsername": "dobrud" - }, - { - "name": "Karl-Aksel Puulmann", - "githubUsername": "macobo" - }, - { - "name": "Dmytro Gokun", - "githubUsername": "dmytro-gokun" - }, - { - "name": "Liam Clarke", - "githubUsername": "LiamAttClarke" - }, - { - "name": "Vladimir Dashukevich", - "githubUsername": "life777" - }, - { - "name": "André Fonseca", - "githubUsername": "amxfonseca" - }, - { - "name": "makspetrov", - "githubUsername": "Nosfit" - }, - { - "name": "Michael Bullington", - "githubUsername": "mbullington" - }, - { - "name": "Olivier Pascal", - "githubUsername": "pascaloliv" - }, - { - "name": "Marko Schilde", - "githubUsername": "mschilde" - } - ] -} diff --git a/types/mapbox-gl/v2/tsconfig.json b/types/mapbox-gl/v2/tsconfig.json deleted file mode 100644 index f69bcb46d0e49f..00000000000000 --- a/types/mapbox-gl/v2/tsconfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "compilerOptions": { - "module": "node16", - "lib": [ - "es6", - "dom" - ], - "strictNullChecks": true, - "noImplicitAny": true, - "noImplicitThis": true, - "strictFunctionTypes": true, - "types": [], - "noEmit": true, - "forceConsistentCasingInFileNames": true - }, - "files": [ - "index.d.ts", - "mapbox-gl-tests.ts" - ] -} diff --git a/types/mapbox__mapbox-gl-geocoder/index.d.ts b/types/mapbox__mapbox-gl-geocoder/index.d.ts index edb637386bb6ad..05f34b2f14f0df 100644 --- a/types/mapbox__mapbox-gl-geocoder/index.d.ts +++ b/types/mapbox__mapbox-gl-geocoder/index.d.ts @@ -53,7 +53,7 @@ declare namespace MapboxGeocoder { * or [`fitBounds`](https://docs.mapbox.com/mapbox-gl-js/api/#map#fitbounds) method providing control over the animation of the transition. * @default true */ - flyTo?: boolean | mapboxgl.FlyToOptions | mapboxgl.FitBoundsOptions | undefined; + flyTo?: boolean | mapboxgl.EasingOptions | undefined; /** * a geographical point given as an object with `latitude` and `longitude` properties, or the string 'ip' to use a user's IP address location. Search results closer to this point will be given higher priority. */ @@ -331,11 +331,11 @@ declare class MapboxGeocoder implements mapboxgl.IControl { * If an object, it will be passed as `options` to the map [`flyTo`](https://docs.mapbox.com/mapbox-gl-js/api/#map#flyto) or [`fitBounds`](https://docs.mapbox.com/mapbox-gl-js/api/#map#fitbounds) * method providing control over the animation of the transition. */ - setFlyTo(flyTo: boolean | mapboxgl.FlyToOptions | mapboxgl.FitBoundsOptions): this; + setFlyTo(flyTo: boolean | mapboxgl.EasingOptions): this; /** * Get the parameters used to fly to the selected response, if any */ - getFlyTo(): boolean | mapboxgl.FlyToOptions | mapboxgl.FitBoundsOptions; + getFlyTo(): boolean | mapboxgl.EasingOptions; /** * Get the value of the placeholder string */ diff --git a/types/mapbox__mapbox-gl-geocoder/package.json b/types/mapbox__mapbox-gl-geocoder/package.json index e1fc6325f4c0f9..6b4ec497bb720c 100644 --- a/types/mapbox__mapbox-gl-geocoder/package.json +++ b/types/mapbox__mapbox-gl-geocoder/package.json @@ -7,7 +7,7 @@ ], "dependencies": { "@types/geojson": "*", - "@types/mapbox-gl": "*" + "mapbox-gl": "^3.13.0" }, "devDependencies": { "@types/mapbox__mapbox-gl-geocoder": "workspace:." diff --git a/types/mapbox__mapbox-gl-traffic/package.json b/types/mapbox__mapbox-gl-traffic/package.json index 56dbbb5b8291a5..7a3f8015839a74 100644 --- a/types/mapbox__mapbox-gl-traffic/package.json +++ b/types/mapbox__mapbox-gl-traffic/package.json @@ -6,7 +6,7 @@ "https://github.com/mapbox/mapbox-gl-traffic" ], "dependencies": { - "@types/mapbox-gl": "*", + "@types/mapbox-gl": "<3.5", "@types/node": "*" }, "devDependencies": { diff --git a/types/mapbox__mapbox-sdk/index.d.ts b/types/mapbox__mapbox-sdk/index.d.ts index 24e6a4e59346d9..b11ee20a101c99 100644 --- a/types/mapbox__mapbox-sdk/index.d.ts +++ b/types/mapbox__mapbox-sdk/index.d.ts @@ -1351,7 +1351,6 @@ declare module "@mapbox/mapbox-sdk/services/isochrone" { // eslint-disable-next-line @definitelytyped/no-declare-current-package declare module "@mapbox/mapbox-sdk/services/geocoding" { - import { LngLatLike } from "mapbox-gl"; // eslint-disable-next-line @definitelytyped/no-self-import import { Coordinates, MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request"; // eslint-disable-next-line @definitelytyped/no-self-import @@ -1388,7 +1387,7 @@ declare module "@mapbox/mapbox-sdk/services/geocoding" { /** * A location. This will be a place name for forward geocoding or a coordinate pair (longitude, latitude) for reverse geocoding. */ - query: string | LngLatLike; + query: string; /** * Either mapbox.places for ephemeral geocoding, or mapbox.places-permanent for storing results and batch geocoding. */ @@ -1846,9 +1845,16 @@ declare module "@mapbox/mapbox-sdk/services/optimization" { // eslint-disable-next-line @definitelytyped/no-declare-current-package declare module "@mapbox/mapbox-sdk/services/static" { import * as GeoJSON from "geojson"; - import { AnyLayer, LngLatBoundsLike, LngLatLike } from "mapbox-gl"; + /** + * It is now the only remaining place that still requires `mapbox-gl`. + * + * Since the js source of `mapbox__mapbox-sdk` does not import codes from `mapbox-gl`, + * the `AnyLayer` usage can probably be made gone in further PR, so that `mapbox-gl` dependency + * is no longer needed in this type lib. + */ + import { LayerSpecification as AnyLayer } from "mapbox-gl"; // eslint-disable-next-line @definitelytyped/no-self-import - import { MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request"; + import { Coordinates, MapiRequest } from "@mapbox/mapbox-sdk/lib/classes/mapi-request"; // eslint-disable-next-line @definitelytyped/no-self-import import MapiClient, { SdkConfig } from "@mapbox/mapbox-sdk/lib/classes/mapi-client"; @@ -1872,7 +1878,7 @@ declare module "@mapbox/mapbox-sdk/services/static" { height: number; position: | { - coordinates: LngLatLike | "auto"; + coordinates: Coordinates; zoom: number; bearing?: number | undefined; pitch?: number | undefined; @@ -1895,7 +1901,7 @@ declare module "@mapbox/mapbox-sdk/services/static" { } interface CustomMarker { - coordinates: LngLatLike; + coordinates: Coordinates; url: string; } @@ -1904,7 +1910,7 @@ declare module "@mapbox/mapbox-sdk/services/static" { } interface SimpleMarker { - coordinates: [number, number]; + coordinates: Coordinates; label?: string | undefined; color?: string | undefined; size?: "large" | "small" | undefined; @@ -1918,7 +1924,7 @@ declare module "@mapbox/mapbox-sdk/services/static" { /** * An array of coordinates describing the path. */ - coordinates: LngLatBoundsLike[]; + coordinates: Coordinates[]; strokeWidth?: number | undefined; strokeColor?: string | undefined; /** diff --git a/types/mapbox__mapbox-sdk/package.json b/types/mapbox__mapbox-sdk/package.json index 0b151418e26696..688484637fcd29 100644 --- a/types/mapbox__mapbox-sdk/package.json +++ b/types/mapbox__mapbox-sdk/package.json @@ -7,8 +7,8 @@ ], "dependencies": { "@types/geojson": "*", - "@types/mapbox-gl": "*", - "@types/node": "*" + "@types/node": "*", + "mapbox-gl": "^3.5.0" }, "devDependencies": { "@types/mapbox__mapbox-sdk": "workspace:." diff --git a/types/mapboxgl-spiderifier/package.json b/types/mapboxgl-spiderifier/package.json index d10ee04a4235fa..02494e3115f7e4 100644 --- a/types/mapboxgl-spiderifier/package.json +++ b/types/mapboxgl-spiderifier/package.json @@ -6,7 +6,7 @@ "https://github.com/bewithjonam/mapboxgl-spiderifier" ], "dependencies": { - "@types/mapbox-gl": "*" + "@types/mapbox-gl": "<3.5" }, "devDependencies": { "@types/mapboxgl-spiderifier": "workspace:." diff --git a/types/react-map-gl/package.json b/types/react-map-gl/package.json index 3d71704d2968d7..3996cb714a2f71 100644 --- a/types/react-map-gl/package.json +++ b/types/react-map-gl/package.json @@ -7,7 +7,7 @@ ], "dependencies": { "@types/geojson": "*", - "@types/mapbox-gl": "*", + "@types/mapbox-gl": "<3.5", "@types/react": "*", "@types/viewport-mercator-project": "*" },