|
|
@ -40,18 +40,27 @@ export function createTooltip(target: L.Layer, |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
target.on('popupopen', () => { |
|
|
target.on('popupopen', () => { |
|
|
const actions = document.getElementsByClassName('tb-custom-action'); |
|
|
bindPopupActions(popup, settings, datasource); |
|
|
Array.from(actions).forEach( |
|
|
|
|
|
(element: HTMLElement) => { |
|
|
|
|
|
const actionName = element.getAttribute('data-action-name'); |
|
|
|
|
|
if (element && settings.tooltipAction[actionName]) { |
|
|
|
|
|
element.addEventListener('click', ($event) => settings.tooltipAction[actionName]($event, datasource)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
}); |
|
|
return popup; |
|
|
return popup; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function bindPopupActions(popup: L.Popup, settings: MarkerSettings | PolylineSettings | PolygonSettings, |
|
|
|
|
|
datasource: Datasource) { |
|
|
|
|
|
const actions = popup.getElement().getElementsByClassName('tb-custom-action'); |
|
|
|
|
|
Array.from(actions).forEach( |
|
|
|
|
|
(element: HTMLElement) => { |
|
|
|
|
|
const actionName = element.getAttribute('data-action-name'); |
|
|
|
|
|
if (element && settings.tooltipAction[actionName]) { |
|
|
|
|
|
element.onclick = ($event) => |
|
|
|
|
|
{ |
|
|
|
|
|
settings.tooltipAction[actionName]($event, datasource); |
|
|
|
|
|
return false; |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export function getRatio(firsMoment: number, secondMoment: number, intermediateMoment: number): number { |
|
|
export function getRatio(firsMoment: number, secondMoment: number, intermediateMoment: number): number { |
|
|
return (intermediateMoment - firsMoment) / (secondMoment - firsMoment); |
|
|
return (intermediateMoment - firsMoment) / (secondMoment - firsMoment); |
|
|
} |
|
|
} |
|
|
@ -133,7 +142,7 @@ const linkActionRegex = /<link-act name=['"]([^['"]*)['"]>([^<]*)<\/link-act>/g; |
|
|
const buttonActionRegex = /<button-act name=['"]([^['"]*)['"]>([^<]*)<\/button-act>/g; |
|
|
const buttonActionRegex = /<button-act name=['"]([^['"]*)['"]>([^<]*)<\/button-act>/g; |
|
|
|
|
|
|
|
|
function createLinkElement(actionName: string, actionText: string): string { |
|
|
function createLinkElement(actionName: string, actionText: string): string { |
|
|
return `<a href="#" class="tb-custom-action" data-action-name=${actionName}>${actionText}</a>`; |
|
|
return `<a href="javascript:void(0);" class="tb-custom-action" data-action-name=${actionName}>${actionText}</a>`; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function createButtonElement(actionName: string, actionText: string) { |
|
|
function createButtonElement(actionName: string, actionText: string) { |
|
|
|