repo_name string | dataset string | owner string | lang string | func_name string | code string | docstring string | url string | sha string |
|---|---|---|---|---|---|---|---|---|
rill-flow | github_2023 | weibocom | typescript | VAxios.configAxios | configAxios(config: CreateAxiosOptions) {
if (!this.axiosInstance) {
return;
}
this.createAxios(config);
} | /**
* @description: Reconfigure axios
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L52-L57 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | VAxios.setHeader | setHeader(headers: any): void {
if (!this.axiosInstance) {
return;
}
Object.assign(this.axiosInstance.defaults.headers, headers);
} | /**
* @description: Set general header
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L62-L67 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | VAxios.setupInterceptors | private setupInterceptors() {
// const transform = this.getTransform();
const {
axiosInstance,
options: { transform },
} = this;
if (!transform) {
return;
}
const {
requestInterceptors,
requestInterceptorsCatch,
responseInterceptors,
responseInterceptors... | /**
* @description: Interceptor configuration 拦截器配置
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L72-L124 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | VAxios.uploadFile | uploadFile<T = any>(config: AxiosRequestConfig, params: UploadFileParams) {
const formData = new window.FormData();
const customFilename = params.name || 'file';
if (params.filename) {
formData.append(customFilename, params.file, params.filename);
} else {
formData.append(customFilename, pa... | /**
* @description: File Upload
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L129-L163 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | VAxios.supportFormData | supportFormData(config: AxiosRequestConfig) {
const headers = config.headers || this.options.headers;
const contentType = headers?.['Content-Type'] || headers?.['content-type'];
if (
contentType !== ContentTypeEnum.FORM_URLENCODED ||
!Reflect.has(config, 'data') ||
config.method?.toUpperC... | // support form-data | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/Axios.ts#L166-L182 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosCanceler.addPending | public addPending(config: AxiosRequestConfig): void {
this.removePending(config);
const url = getPendingUrl(config);
const controller = new AbortController();
config.signal = config.signal || controller.signal;
if (!pendingMap.has(url)) {
// 如果当前请求不在等待中,将其添加到等待中
pendingMap.set(url, contr... | /**
* 添加请求
* @param config 请求配置
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosCancel.ts#L15-L24 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosCanceler.removeAllPending | public removeAllPending(): void {
pendingMap.forEach((abortController) => {
if (abortController) {
abortController.abort();
}
});
this.reset();
} | /**
* 清除所有等待中的请求
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosCancel.ts#L29-L36 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosCanceler.removePending | public removePending(config: AxiosRequestConfig): void {
const url = getPendingUrl(config);
if (pendingMap.has(url)) {
// 如果当前请求在等待中,取消它并将其从等待中移除
const abortController = pendingMap.get(url);
if (abortController) {
abortController.abort(url);
}
pendingMap.delete(url);
}
... | /**
* 移除请求
* @param config 请求配置
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosCancel.ts#L42-L52 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosCanceler.reset | public reset(): void {
pendingMap.clear();
} | /**
* 重置
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosCancel.ts#L57-L59 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosRetry.retry | retry(axiosInstance: AxiosInstance, error: AxiosError) {
// @ts-ignore
const { config } = error.response;
const { waitTime, count } = config?.requestOptions?.retryRequest ?? {};
config.__retryCount = config.__retryCount || 0;
if (config.__retryCount >= count) {
return Promise.reject(error);
... | /**
* 重试
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosRetry.ts#L10-L22 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
rill-flow | github_2023 | weibocom | typescript | AxiosRetry.delay | private delay(waitTime: number) {
return new Promise((resolve) => setTimeout(resolve, waitTime));
} | /**
* 延迟
*/ | https://github.com/weibocom/rill-flow/blob/287042161999be39b1b92968f8fd60b3825b7fb1/rill-flow-ui/src/utils/http/axios/axiosRetry.ts#L27-L29 | 287042161999be39b1b92968f8fd60b3825b7fb1 |
zerostep | github_2023 | zerostep-ai | typescript | sendTaskStartMessage | const sendTaskStartMessage = async (page: Page, task: string, taskId: string, options?: StepOptions) => {
const snapshot = await playwright.getSnapshot(page)
const message: TaskStartZeroStepMessage = {
type: 'task-start',
packageVersion: meta.getVersion(),
taskId,
task,
snapshot,
options,
... | /**
* Sends a message over the websocket to begin an AI task.
*/ | https://github.com/zerostep-ai/zerostep/blob/7c813beafa09f46bdd8c98b826d2085c936443c9/packages/playwright/src/index.ts#L104-L116 | 7c813beafa09f46bdd8c98b826d2085c936443c9 |
zerostep | github_2023 | zerostep-ai | typescript | sendCommandResolveMessage | const sendCommandResolveMessage = async (index: number, taskId: string, result: any) => {
const message: CommandResponseZeroStepMessage = {
type: 'command-response',
packageVersion: meta.getVersion(),
taskId,
index,
result: result === undefined || result === null ? "null" : JSON.stringify(result),... | /**
* Sends a message over the websocket in response to an AI command completing.
*/ | https://github.com/zerostep-ai/zerostep/blob/7c813beafa09f46bdd8c98b826d2085c936443c9/packages/playwright/src/index.ts#L121-L131 | 7c813beafa09f46bdd8c98b826d2085c936443c9 |
zerostep | github_2023 | zerostep-ai | typescript | runCommandsToCompletion | const runCommandsToCompletion = async (page: Page, test: TestType<any, any>, taskId: string) => {
return new Promise<TaskCompleteZeroStepMessage>((resolve) => {
webSocket.addWebSocketMessageHandler(taskId, (data, removeListener) => {
// Only respond to messages corresponding to the task for which this
... | /**
* Listens for websocket commands, executes them, then responds in a promise that
* is resolved once we see the task-complete message.
*/ | https://github.com/zerostep-ai/zerostep/blob/7c813beafa09f46bdd8c98b826d2085c936443c9/packages/playwright/src/index.ts#L137-L171 | 7c813beafa09f46bdd8c98b826d2085c936443c9 |
zerostep | github_2023 | zerostep-ai | typescript | executeCommand | const executeCommand = async (page: Page, command: CommandRequestZeroStepMessage): Promise<any> => {
switch (command.name) {
// CDP
case 'getDOMSnapshot':
return await cdp.getDOMSnapshot(page)
case 'executeScript':
return await cdp.executeScript(page, command.arguments as { script: string, arg... | /**
* Executes a webdriver command passed over the websocket using CDP.
*/ | https://github.com/zerostep-ai/zerostep/blob/7c813beafa09f46bdd8c98b826d2085c936443c9/packages/playwright/src/index.ts#L176-L243 | 7c813beafa09f46bdd8c98b826d2085c936443c9 |
zerostep | github_2023 | zerostep-ai | typescript | runInParallel | const runInParallel: typeof ai = async (tasks, config, options) => {
if (!Array.isArray(tasks) || tasks.length === 0) {
Promise.reject('Empty task list, nothing to do')
}
const parallelism = options?.parallelism || 10
const failImmediately = options?.failImmediately || false
const tasksArray = tasks as s... | /**
* Runs the provided tasks in parallel by chunking them up according to the
* `parallelism` option and waiting for all chunks to complete.
*/ | https://github.com/zerostep-ai/zerostep/blob/7c813beafa09f46bdd8c98b826d2085c936443c9/packages/playwright/src/index.ts#L249-L278 | 7c813beafa09f46bdd8c98b826d2085c936443c9 |
ollama-logseq | github_2023 | omagdy7 | typescript | css | const css = (t, ...args) => String.raw(t, ...args); | // @ts-expect-error | https://github.com/omagdy7/ollama-logseq/blob/cfd6f171e716f3f0f5976e96272d084db8dd0dec/src/main.tsx#L13-L13 | cfd6f171e716f3f0f5976e96272d084db8dd0dec |
ollama-logseq | github_2023 | omagdy7 | typescript | getIndentLevel | function getIndentLevel(line: string): number {
const firstCharIndex = line.search(/\S/);
// no non-whitespace => treat as top-level
if (firstCharIndex < 0) {
return 0;
}
// e.g. baseIndent=2 → each 2 leading spaces => +1 nesting level
const baseIndent = 3;
return Math.... | // Helper: Determine indent-based nesting level. | https://github.com/omagdy7/ollama-logseq/blob/cfd6f171e716f3f0f5976e96272d084db8dd0dec/src/ollama.tsx#L351-L360 | cfd6f171e716f3f0f5976e96272d084db8dd0dec |
ArisuAutoSweeper | github_2023 | TheFunny | typescript | getAlasABSPath | const getAlasABSPath = (
files: string[] = ['**/config/deploy.yaml', '**/config/deploy.template.yaml'],
rootName: string | string[] = ['AzurLaneAutoScript', 'Alas', 'ArisuAutoSweeper'],
) => {
const path = require('path');
const sep = path.sep;
const fg = require('fast-glob');
let appAbsPath = process.cwd()... | /**
* Get the absolute path of the project root directory
* @param files
* @param rootName
*/ | https://github.com/TheFunny/ArisuAutoSweeper/blob/62c147fdab131583c259a5dcdec0b80e27aff299/webapp/packages/common/utils/getAlasABSPath.ts#L9-L70 | 62c147fdab131583c259a5dcdec0b80e27aff299 |
ArisuAutoSweeper | github_2023 | TheFunny | typescript | changeLocale | async function changeLocale(locale: LocaleType) {
const globalI18n = i18n.global;
const currentLocale = unref(globalI18n.locale);
if (currentLocale === locale) {
return locale;
}
const langModule = messages[locale];
if (!langModule) return;
globalI18n.setLocaleMessage(locale, langModu... | // Switching the language will change the locale of useI18n | https://github.com/TheFunny/ArisuAutoSweeper/blob/62c147fdab131583c259a5dcdec0b80e27aff299/webapp/packages/renderer/src/locales/useLocale.ts#L30-L43 | 62c147fdab131583c259a5dcdec0b80e27aff299 |
ArisuAutoSweeper | github_2023 | TheFunny | typescript | formatComponentName | function formatComponentName(vm: any) {
if (vm.$root === vm) {
return {
name: 'root',
path: 'root',
};
}
const options = vm.$options as any;
if (!options) {
return {
name: 'anonymous',
path: 'anonymous',
};
}
const name = options.name || options._componentTag;
retu... | /**
* get comp name
* @param vm
*/ | https://github.com/TheFunny/ArisuAutoSweeper/blob/62c147fdab131583c259a5dcdec0b80e27aff299/webapp/packages/renderer/src/logics/error-handle/index.ts#L16-L36 | 62c147fdab131583c259a5dcdec0b80e27aff299 |
ArisuAutoSweeper | github_2023 | TheFunny | typescript | processStackMsg | function processStackMsg(error: Error) {
if (!error.stack) {
return '';
}
let stack = error.stack
.replace(/\n/gi, '') // Remove line breaks to save the size of the transmitted content
.replace(/\bat\b/gi, '@') // At in chrome, @ in ff
.split('@') // Split information with @
.slice(0, 9) // Th... | /**
* Handling error stack information
* @param error
*/ | https://github.com/TheFunny/ArisuAutoSweeper/blob/62c147fdab131583c259a5dcdec0b80e27aff299/webapp/packages/renderer/src/logics/error-handle/index.ts#L72-L89 | 62c147fdab131583c259a5dcdec0b80e27aff299 |
aws-cdk-stack-builder-tool | github_2023 | aws-samples | typescript | TypeScriptGenerator.importName | importName(fqn: string) {
const importName = fqn
.replaceAll(".", "/")
.split("/")
.slice(0, -1)
.join("/")
.replaceAll("_", "-");
return importName;
} | // @aws-cdk_aws/batch-alpha | https://github.com/aws-samples/aws-cdk-stack-builder-tool/blob/fb243b1bd75f908bad10c7a1d2faed009510f7ed/src/react-app/src/targets/typescript/typescript-generator.ts#L677-L686 | fb243b1bd75f908bad10c7a1d2faed009510f7ed |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onAutofillButtonClick | const onAutofillButtonClick = ({ target }: Event): void => {
const dataset = (target as HTMLButtonElement).dataset
console.debug("onAutofillButtonClick", dataset)
;(loginForm.elements.namedItem("display_name_or_email") as HTMLInputElement).value = dataset.login
loginForm.querySelector("i... | // Autofill buttons are present in development environment | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_login.ts#L30-L37 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | roundPy2 | const roundPy2 = (value: number): number => (value + (value < 0 ? -0.5 : 0.5)) | 0 | // Encoded Polyline Algorithm Format | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_polyline.ts#L10-L10 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getObjectRequestUrl | const getObjectRequestUrl = (object: OSMObject): string => {
const type = object.type === "note" ? "notes" : object.type
// When requested for complex object, request for full version (incl. object's members)
// Ignore version specification as there is a very high chance it will be rendered incorrectly
... | /**
* Get object request URL
* @example
* getObjectRequestUrl({ type: "node", id: 123456 })
* // => "https://api.openstreetmap.org/api/0.6/node/123456"
*/ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_remote-edit.ts#L15-L29 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getBoundsFromCoords | const getBoundsFromCoords = ({ lon, lat, zoom }: LonLatZoom, paddingRatio = 0): Bounds => {
// Assume the map takes up the entire screen
const mapHeight = window.innerHeight
const mapWidth = window.innerWidth
const tileSize = 256
const tileCountHalfX = mapWidth / tileSize / 2
const tileCountHal... | /** Get bounds from coordinates and zoom level */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_remote-edit.ts#L32-L46 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | abortRequest | const abortRequest = (source: Element, newController: boolean): AbortController | null => {
const controller = abortControllers.get(source)
controller?.abort()
// When a new controller is requested, replace the old one and return it
if (newController) {
const controller = new AbortController()
... | /** Abort any pending request for the given source element, optionally returning a new AbortController */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_rich-text.ts#L6-L20 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onEditClick | const onEditClick = () => {
abortRequest(sourceTextArea, false)
for (const button of editButtons) button.disabled = true
for (const button of previewButtons) button.disabled = false
for (const button of helpButtons) button.disabled = false
sourceTextArea.classList.remove("d-non... | /** On edit button click, abort any requests and show the source textarea */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_rich-text.ts#L30-L41 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onPreviewClick | const onPreviewClick = () => {
const abortController = abortRequest(sourceTextArea, true)
for (const button of editButtons) button.disabled = false
for (const button of previewButtons) button.disabled = true
for (const button of helpButtons) button.disabled = false
sourceTextAr... | /** On preview button click, abort any requests and fetch the preview */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_rich-text.ts#L46-L78 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onHelpClick | const onHelpClick = () => {
abortRequest(sourceTextArea, false)
for (const button of editButtons) button.disabled = false
for (const button of previewButtons) button.disabled = false
for (const button of helpButtons) button.disabled = true
sourceTextArea.classList.add("d-none")... | /** On help button click, show the help content */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_rich-text.ts#L83-L94 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | handleElementFeedback | const handleElementFeedback = (
element: HTMLInputElement,
type: "success" | "info" | "error",
message: string,
): void => {
if (element.classList.contains("hidden-password-input")) {
const actualElement = form.querySelector(`input[type=password][data-name="${element.name... | /** Handle feedback for a specific element */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_standard-form.ts#L48-L104 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onInput | const onInput = () => {
if (!feedback) return
console.debug("Invalidating form feedback")
form.dispatchEvent(new CustomEvent("invalidate"))
} | // Remove feedback on change or submit | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_standard-form.ts#L86-L90 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | handleFormFeedback | const handleFormFeedback = (type: "success" | "info" | "error", message: string): void => {
let feedback = form.querySelector(".form-feedback")
let feedbackAlert: Alert | null = null
if (!feedback) {
feedback = document.createElement("div")
feedback.classList.add("form-f... | /** Handle feedback for the entire form */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_standard-form.ts#L107-L158 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onInvalidated | const onInvalidated = () => {
if (!feedback) return
console.debug("configureStandardForm", "handleFormFeedback", "onInvalidated")
feedbackAlert.dispose()
feedbackAlert = null
feedback.remove()
feedback = null
} | // Remove feedback on submit | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_standard-form.ts#L146-L153 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | loadSystemApp | const loadSystemApp = (clientId: string, successCallback: (token: string) => void): void => {
console.debug("loadSystemApp", clientId)
const accessToken = getSystemAppAccessToken(clientId)
if (!accessToken) {
createAccessToken(clientId, successCallback)
return
}
fetch("/api/0.6/use... | /** Load system app access token and call successCallback with it */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_system-app.ts#L5-L31 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | generatePathData | const generatePathData = (coords: [number, number][]): string => {
const ds = [`M${coords[0][0]},${coords[0][1]}`]
for (const pair of coords.slice(1)) ds.push(`L${pair[0]},${pair[1]}`)
return ds.join(" ")
} | /** Generate a path data string from coordinates in [x, y] pairs */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_trace-svg.ts#L54-L58 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapClick | const onMapClick = ({ latlng }: { latlng: L.LatLng }) => {
const precision = zoomPrecision(map.getZoom())
const lon = latlng.lng.toFixed(precision)
const lat = latlng.lat.toFixed(precision)
const latLng = L.latLng(Number(lat), Number(lon))
lonInput.value = lon
latInput.v... | /** On map click, update the coordinates and move the marker */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_user-settings-home.ts#L55-L67 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onGeolocationSuccess | const onGeolocationSuccess = (position: GeolocationPosition) => {
console.debug("onGeolocationSuccess", position)
const lon = position.coords.longitude
const lat = position.coords.latitude
const zoom = 17
const geolocationState: MapState = { lon, lat, zoom, la... | // If location was not provided, request navigator.geolocation | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_welcome.ts#L40-L52 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onGeolocationFailure | const onGeolocationFailure = () => {
console.debug("onGeolocationFailure")
startButton.removeEventListener("click", onStartButtonClick)
} | /** On geolocation failure, remove event listener */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/_welcome.ts#L55-L58 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getFixTheMapLink | const getFixTheMapLink = ({ lon, lat, zoom }: LonLatZoom): string => {
const zoomRounded = beautifyZoom(zoom)
const precision = zoomPrecision(zoom)
const lonFixed = lon.toFixed(precision)
const latFixed = lat.toFixed(precision)
// TODO: test from within iframe
return `${window.location.origin}/f... | /**
* Get the fix the map link
* @example
* getFixTheMapLink(5.123456, 6.123456, 17)
* // => "https://www.openstreetmap.org/fixthemap?lat=6.123456&lon=5.123456&zoom=17"
*/ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/embed.ts#L65-L72 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMoveEnd | const onMoveEnd = () => {
const center = map.getCenter()
const zoom = map.getZoom()
reportProblemLink.href = getFixTheMapLink({ lon: center.lng, lat: center.lat, zoom })
attributionControl.options.customAttribution = reportProblemLink.outerHTML
attributionControl._updateAttributions()
} | /** On move end, update the link with the current coordinates */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/embed.ts#L79-L85 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapClick | const onMapClick = ({ lngLat }: { lngLat: LngLat }) => {
console.debug("onMapClick", lngLat)
setMarker(lngLat)
setInput(lngLat)
} | /** On map click, update the coordinates and move the marker */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/diaries/_compose.ts#L60-L64 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onCoordinatesInputChange | const onCoordinatesInputChange = () => {
if (mapDiv.classList.contains("d-none")) return
if (lonInput.value && latInput.value) {
console.debug("onCoordinatesInputChange", lonInput.value, latInput.value)
const lon = Number.parseFloat(lonInput.value)
const lat = Number.... | /** On coordinates input change, update the marker position */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/diaries/_compose.ts#L67-L82 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onCloseButtonClick | const onCloseButtonClick = () => {
console.debug("configureActionSidebar", "onCloseButtonClick")
routerNavigateStrict("/")
} | /** On sidebar close button click, navigate to index */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_action-sidebar.ts#L31-L34 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | renderElements | const renderElements = (
elementsSection: HTMLElement,
elements: { [key: string]: PartialChangesetParams_Element[] },
): void => {
console.debug("renderElements")
const groupTemplate = elementsSection.querySelector("template.group")
const entryTemplate = elementsSection.querySelector("template.entr... | /** Render elements component */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_changeset.ts#L108-L129 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | renderElementType | const renderElementType = (
groupTemplate: HTMLTemplateElement,
entryTemplate: HTMLTemplateElement,
type: string,
elements: PartialChangesetParams_Element[],
): DocumentFragment => {
console.debug("renderElementType", type, elements)
const groupFragment = groupTemplate.content.cloneNode(true) a... | /** Render elements of a specific type */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_changeset.ts#L132-L277 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | setHover | const setHover = ({ id, firstFeatureId, numBounds }: GeoJsonProperties, hover: boolean): void => {
const result = idSidebarMap.get(id)
result.classList.toggle("hover", hover)
if (hover) {
// Scroll result into view
const sidebarRect = parentSidebar.getBoundingClientRect()... | /** Set the hover state of the changeset features */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_changesets-history.ts#L169-L182 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSidebarScroll | const onSidebarScroll = (): void => {
if (parentSidebar.offsetHeight + parentSidebar.scrollTop < parentSidebar.scrollHeight) return
console.debug("Sidebar scrolled to the bottom")
updateState()
} | /** On sidebar scroll bottom, load more changesets */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_changesets-history.ts#L213-L217 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateState | const updateState = (): void => {
// Request full world when initial loading for scope/user
const fetchBounds = fetchedBounds || (!loadScope && !loadDisplayName) ? map.getBounds() : null
const params: { [key: string]: string | undefined } = { scope: loadScope, display_name: loadDisplayName }
... | /** On map update, fetch the changesets in view and update the changesets layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_changesets-history.ts#L220-L298 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateUrl | const updateUrl = (dirtyIndices: number[]): void => {
const newLength = markers.length
if (newLength < positionsUrl.length) {
// Truncate positions
positionsUrl.length = newLength
}
for (const markerIndex of dirtyIndices) {
const lngLat = markers[marke... | // Encodes current marker positions into URL polyline parameter | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L108-L120 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateLines | const updateLines = (dirtyIndices: number[]): void => {
const newLength = Math.max(markers.length - 1, 0)
if (newLength < lines.length) {
// Truncate lines
lines.length = newLength
}
for (const markerIndex of dirtyIndices) {
const lineIndex = markerInd... | // Updates GeoJSON line features between consecutive markers | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L129-L165 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateLabels | const updateLabels = (dirtyIndices: number[]): void => {
const newLength = Math.max(markers.length - 1, 0)
if (newLength < labels.length) {
// Truncate labels
for (let i = newLength; i < labels.length; i++) labels[i].remove()
labels.length = newLength
}
... | // Updates distance labels and calculates total measurement | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L168-L220 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | update | const update = (dirtyIndices: number[]): void => {
updateUrl(dirtyIndices)
updateLines(dirtyIndices)
updateLabels(dirtyIndices)
clearBtn.classList.toggle("d-none", !markers.length)
} | // Schedule updates to all components after marker changes, dirtyIndices must be sorted | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L223-L229 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | removeMarker | const removeMarker = (index: number): void => {
console.debug("Remove distance marker", index)
// Pop tailing markers
const tail = markers.splice(index + 1)
{
// Remove indexed marker
const marker = markers[index]
marker.remove()
markers.le... | // Removes a marker and updates subsequent geometry | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L239-L263 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | insertMarker | const insertMarker = (index: number, lngLat: LngLatLike) => {
console.debug("Insert distance marker", index, lngLat)
// Pop tailing markers
const tail = markers.splice(index)
update([])
// Add new marker
createNewMarker({ lngLat, skipUpdates: true })
// Add mark... | // Inserts new marker at specified position and updates connections | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L266-L282 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | createNewMarker | const createNewMarker = ({ lngLat, skipUpdates }: { lngLat: LngLatLike; skipUpdates?: boolean }): void => {
// Avoid event handlers after the controller is unloaded
if (!hasMapLayer(map, layerId)) return
console.debug("Create distance marker", lngLat, skipUpdates)
const markerIndex = mar... | // Adds new endpoint marker and updates visualization | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L285-L300 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | startGhostMarkerDrag | const startGhostMarkerDrag = () => {
console.debug("materializeGhostMarker")
ghostMarker.removeClassName("d-none")
ghostMarker.addClassName("dragging")
// Add a real marker
insertMarker(ghostMarkerIndex, ghostMarker.getLngLat())
} | /** On ghost marker drag start, replace it with a real marker */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L362-L368 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onGhostMarkerClick | const onGhostMarkerClick = (e: MouseEvent) => {
e.stopPropagation()
console.debug("onGhostMarkerClick")
startGhostMarkerDrag()
ghostMarker.removeClassName("dragging")
ghostMarker.addClassName("d-none")
} | /** On ghost marker click, convert it into a real marker */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_distance.ts#L379-L385 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | renderElementsComponent | const renderElementsComponent = (
elementsSection: HTMLElement,
elements: PartialElementParams_Entry[],
isWay: boolean,
): void => {
console.debug("renderElementsComponent", elements.length)
const entryTemplate = elementsSection.querySelector("template.entry")
const titleElement = elementsSecti... | /** Render elements component */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_element.ts#L90-L253 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateState | const updateState = () => {
const precision = zoomPrecision(map.getZoom())
const bounds = customRegionCheckbox.checked ? locationFilter.getBounds() : map.getBounds()
const [[minLon, minLat], [maxLon, maxLat]] = bounds.adjustAntiMeridian().toArray()
minLonInput.value = minLon.toFixed(prec... | /** On map move end, update the inputs */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_export.ts#L46-L55 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateButtonState | const updateButtonState = () => {
const hasValue = commentInput.value.trim().length > 0
submitButton.disabled = !hasValue
} | /** On comment input, update the button state */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_new-note.ts#L38-L41 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onFormSuccess | const onFormSuccess = () => {
map.panBy([0, 0], { animate: false })
controller.unload()
controller.load({ id: params.id.toString() })
} | /** On success callback, reload the note and simulate map move (reload notes layer) */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_note.ts#L89-L93 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSubmitClick | const onSubmitClick = ({ target }: MouseEvent) => {
eventInput.value = (target as HTMLButtonElement).dataset.event
} | /** On submit click, set event type */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_note.ts#L99-L101 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onCommentInput | const onCommentInput = () => {
const hasValue = commentInput.value.trim().length > 0
if (hasValue) {
closeButton.classList.add("d-none")
commentCloseButton.classList.remove("d-none")
commentButton.disabled = ... | /** On comment input, update the button state */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_note.ts#L106-L117 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getURLQueryPosition | const getURLQueryPosition = (): LonLatZoom | null => {
const searchParams = qsParse(location.search.substring(1))
if (searchParams.lon && searchParams.lat) {
const lon = Number.parseFloat(searchParams.lon)
const lat = Number.parseFloat(searchParams.lat)
const zoom = M... | /** Get query position from URL */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_query-features.ts#L74-L88 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | configureResultActions | const configureResultActions = (container: HTMLElement): void => {
const queryList = container.querySelector("ul.search-list")
const resultActions = queryList.querySelectorAll("li.social-action")
const params = fromBinary(PartialQueryFeaturesParamsSchema, base64Decode(queryList.dataset.params))
... | /** Configure result actions to handle focus and clicks */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_query-features.ts#L91-L102 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSidebarLoading | const onSidebarLoading = (center: LngLat, zoom: number, abortSignal: AbortSignal): void => {
nearbyContainer.innerHTML = nearbyLoadingHtml
enclosingContainer.innerHTML = enclosingLoadingHtml
const radiusMeters = 10 * 1.5 ** (19 - zoom)
console.debug("Query features radius", radiusMeters... | /** On sidebar loading, display loading content and show map animation */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_query-features.ts#L105-L134 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSidebarNearbyLoaded | const onSidebarNearbyLoaded = (html: string): void => {
nearbyContainer.innerHTML = html
configureResultActions(nearbyContainer)
} | /** On sidebar loaded, display content */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_query-features.ts#L137-L140 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSidebarEnclosingLoaded | const onSidebarEnclosingLoaded = (html: string): void => {
enclosingContainer.innerHTML = html
configureResultActions(enclosingContainer)
} | /** On sidebar loaded, display content */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_query-features.ts#L143-L146 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | findRoute | const findRoute = (path: string): Route | undefined => routes.find((route) => route.match(path)) | /** Find the first route that matches a path */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_router.ts#L13-L13 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | removeTrailingSlash | const removeTrailingSlash = (str: string): string =>
str.endsWith("/") && str.length > 1 ? removeTrailingSlash(str.slice(0, -1)) : str | /**
* Remove trailing slash from a string
* @example
* removeTrailingSlash("/way/1234/")
* // => "/way/1234"
*/ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_router.ts#L21-L22 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onInterfaceMarkerDragStart | const onInterfaceMarkerDragStart = (event: DragEvent) => {
const target = event.target as HTMLImageElement
const direction = target.dataset.direction
console.debug("onInterfaceMarkerDragStart", direction)
const dt = event.dataTransfer
dt.effectAllowed = "move"
dt.setData... | /** On draggable marker drag start, set data and drag image */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L110-L125 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | setHover | const setHover = (id: number, hover: boolean): void => {
const result = stepsTableBody.children[id]
result.classList.toggle("hover", hover)
if (hover) {
// Scroll result into view
const sidebarRect = sidebar.getBoundingClientRect()
const resultRect = result.ge... | /** Set the hover state of the step features */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L163-L174 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapMarkerDragEnd | const onMapMarkerDragEnd = (lngLat: LngLat, isStart: boolean): void => {
console.debug("onMapMarkerDragEnd", lngLat, isStart)
const precision = zoomPrecision(map.getZoom())
const lon = lngLat.lng.toFixed(precision)
const lat = lngLat.lat.toFixed(precision)
const value = `${lat},... | /** On marker drag end, update the form's coordinates */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L177-L194 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapDragOver | const onMapDragOver = (event: DragEvent) => event.preventDefault() | /** On map drag over, prevent default behavior */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L197-L197 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapDrop | const onMapDrop = (event: DragEvent) => {
const dragData = event.dataTransfer.getData(dragDataType)
console.debug("onMapDrop", dragData)
let marker: Marker
if (dragData === "start") {
if (!startMarker) {
startMarker = markerFactory("green")
st... | /** On map marker drop, update the marker's coordinates */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L200-L224 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapZoomOrMoveEnd | const onMapZoomOrMoveEnd = () => {
const [[minLon, minLat], [maxLon, maxLat]] = map.getBounds().adjustAntiMeridian().toArray()
bboxInput.value = `${minLon},${minLat},${maxLon},${maxLat}`
} | /** On map update, update the form's bounding box */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L227-L230 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | submitFormIfFilled | const submitFormIfFilled = () => {
popup.remove()
if (startInput.value && endInput.value) form.requestSubmit()
} | /** Utility method to submit the form if filled with data */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L265-L268 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getInitialRoutingEngine | const getInitialRoutingEngine = (engine?: string): string | null => {
return engine ?? getLastRoutingEngine()
} | /** Get initial routing engine identifier */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_routing.ts#L509-L511 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onSearchAlertClick | const onSearchAlertClick = () => {
console.debug("Searching within new area")
controller.unload()
if (whereIsThisMode) {
const center = map.getCenter()
const zoom = map.getZoom()
const precision = zoomPrecision(zoom)
controller.load({
... | /** On search alert click, reload the search with the new area */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_search.ts#L106-L121 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onMapZoomOrMoveEnd | const onMapZoomOrMoveEnd = () => {
if (!initialBounds) {
initialBounds = map.getBounds()
console.debug("Search initial bounds set to", initialBounds)
return
}
if (!searchAlert.classList.contains("d-none")) return
const initialBoundsSize = getLngLatBo... | /** On map update, check if view was changed and show alert if so */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/index/_search.ts#L124-L143 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getPopupPosition | const getPopupPosition = (): { lon: string; lat: string; zoom: number } => {
const zoom = map.getZoom()
const precision = zoomPrecision(zoom)
const lngLat = popup.getLngLat()
return {
lon: lngLat.lng.toFixed(precision),
lat: lngLat.lat.toFixed(precision),
... | /**
* Get the simplified position of the popup
* @example
* getPopupPosition()
* // => { lon: "12.345678", lat: "23.456789", zoom: 17 }
*/ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_context-menu.ts#L44-L53 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | closePopup | const closePopup = () => {
dropdown.hide()
popup.remove()
} | /** On map interactions, close the popup */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_context-menu.ts#L56-L59 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onGeolocationFieldClick | const onGeolocationFieldClick = async ({ target }: Event) => {
closePopup()
try {
const value = (target as Element).textContent
await navigator.clipboard.writeText(value)
console.debug("Copied geolocation to clipboard", value)
} catch (err) {
conso... | /** On geolocation field click, copy the text content */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_context-menu.ts#L94-L103 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onFeatureClick | const onFeatureClick = (e: MapLayerMouseEvent): void => {
const props = e.features[0].properties
routerNavigateStrict(`/${props.type}/${props.id}`)
} | /** On feature click, navigate to the object page */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L79-L82 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | loadData | const loadData = (): void => {
console.debug("Loading", fetchedElements.length, "elements")
loadDataAlert.classList.add("d-none")
source.setData(renderObjects(fetchedElements, { renderAreas: false }))
} | /** Load map data into the data layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L111-L115 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | showDataAlert | const showDataAlert = (): void => {
console.debug("Requested too much data, showing alert")
if (!loadDataAlert.classList.contains("d-none")) return
showDataButton.addEventListener("click", onShowDataButtonClick, { once: true })
hideDataButton.addEventListener("click", onHideDataButtonCli... | /** Display data alert if not already shown */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L118-L124 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onShowDataButtonClick | const onShowDataButtonClick = () => {
if (loadDataOverride) return
console.debug("onShowDataButtonClick")
loadDataOverride = true
loadDataAlert.classList.add("d-none")
fetchedElements = []
fetchedBounds = null
updateLayer()
} | /** On show data click, mark override and load data */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L127-L135 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | onHideDataButtonClick | const onHideDataButtonClick = () => {
if (dataOverlayCheckbox.checked === false) return
console.debug("onHideDataButtonClick")
dataOverlayCheckbox.checked = false
dataOverlayCheckbox.dispatchEvent(new Event("change"))
loadDataAlert.classList.add("d-none")
} | /** On hide data click, uncheck the data layer checkbox */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L138-L144 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateLayer | const updateLayer = (): void => {
// Skip if the notes layer is not visible
if (!enabled) return
// Abort any pending request
abortController?.abort()
abortController = new AbortController()
const viewBounds = map.getBounds()
// Skip updates if the view is sati... | /** On map update, fetch the elements in view and update the data layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_data-layer.ts#L147-L218 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | getImageTrim | const getImageTrim = (
map: MaplibreMap,
width: number,
height: number,
mapBounds: LngLatBounds,
filterBounds: LngLatBounds,
): { top: number; left: number; bottom: number; right: number } => {
filterBounds = getLngLatBoundsIntersection(mapBounds, filterBounds)
if (filterBounds.isEmpty()) {
... | /** Calculate the offsets for trimming the exported image */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_export-image.ts#L145-L165 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | createMainMap | const createMainMap = (container: HTMLElement): MaplibreMap => {
console.debug("Initializing main map")
const map = new MaplibreMap({
container,
maxZoom: 19,
attributionControl: { compact: true, customAttribution: "" },
refreshExpiredTiles: false,
canvasContextAttributes:... | /** Get the main map instance */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_main-map.ts#L37-L96 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | configureMainMap | const configureMainMap = (container: HTMLElement): void => {
const map = createMainMap(container)
// Configure here instead of navbar to avoid global script dependency (navbar is global)
// Find home button is only available for the users with configured home location
const homePoint = config.userConfi... | /** Configure the main map and all its components */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_main-map.ts#L99-L134 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | setMapLayersCode | const setMapLayersCode = (map: MaplibreMap, layersCode?: string): void => {
console.debug("setMapLayersCode", layersCode)
const addLayerCodes: Set<LayerCode> = new Set()
let hasBaseLayer = false
for (const layerCode of (layersCode || "") as Iterable<LayerCode>) {
const layerId = resolveLayerCod... | /**
* Set the map layers from a layers code
* @example
* setMapLayersCode(map, "BT")
*/ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_map-utils.ts#L56-L95 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | convertBoundsToLonLatZoom | const convertBoundsToLonLatZoom = (map: MaplibreMap | null, bounds: Bounds): LonLatZoom => {
const [minLon, minLat, maxLon, maxLat] = bounds
const lon = (minLon + maxLon) / 2
const lat = (minLat + maxLat) / 2
if (map) {
const camera = map.cameraForBounds([minLon, minLat, maxLon, maxLat])
... | /** Convert bounds to a lon, lat, zoom object */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_map-utils.ts#L188-L217 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateState | const updateState = () => {
const zoom = map.getZoom()
if (zoom < newNoteMinZoom) {
if (!button.disabled) {
button.blur()
button.disabled = true
Tooltip.getInstance(button).setContent({
".tooltip-... | /** On map zoom, change button availability */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_new-note.ts#L46-L62 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateLayer | const updateLayer = (): void => {
// Skip if the notes layer is not visible
if (!enabled) return
// Abort any pending request
abortController?.abort()
abortController = new AbortController()
// Skip updates if the area is too big
const fetchBounds = map.getBound... | /** On map update, fetch the notes and update the notes layer */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_notes-layer.ts#L84-L128 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateState | const updateState = () => {
const zoom = map.getZoom()
if (zoom < queryFeaturesMinZoom) {
if (!button.disabled) {
if (button.classList.contains("active")) button.click()
button.blur()
button.disabled = true
... | /** On map zoom, change button availability */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_query-features.ts#L54-L71 | 42f2654614f20520271f46b3ddd389732dde6545 |
openstreetmap-ng | github_2023 | openstreetmap-ng | typescript | updateAvailableOverlays | const updateAvailableOverlays = () => {
// Skip updates if the sidebar is hidden
if (!button.classList.contains("active")) return
const currentViewAreaSize = getLngLatBoundsSize(map.getBounds())
for (const [layerId, areaMaxSize] of [
["notes", config.not... | /** On map zoom, update the available overlays */ | https://github.com/openstreetmap-ng/openstreetmap-ng/blob/42f2654614f20520271f46b3ddd389732dde6545/app/static/ts/leaflet/_sidebar-layers.ts#L118-L170 | 42f2654614f20520271f46b3ddd389732dde6545 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.