Browse Source

Merge 9c4b6fd4a3 into 2d784c83ae

pull/16898/merge
Maksym Tsymbarov 9 hours ago
committed by GitHub
parent
commit
8bfb6cca32
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/circles-data-layer.ts
  2. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/markers-data-layer.ts
  3. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/polygons-data-layer.ts
  4. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/polylines-data-layer.ts
  5. 2
      ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts
  6. 116
      ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet/leaflet-tb.ts
  7. 3
      ui-ngx/src/app/modules/home/components/widget/lib/maps/map.scss
  8. 6
      ui-ngx/src/typings/leaflet-extend-tb.d.ts

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/circles-data-layer.ts

@ -76,7 +76,7 @@ class TbCircleDataLayerItem extends TbLatestDataLayerItem<CirclesDataLayerSettin
}
protected bindLabel(content: L.Content): void {
this.circle.bindTooltip(content, { className: 'tb-circle-label', permanent: true, direction: 'center'})
this.circle.bindTooltip(L.TB.labelTooltip(content, { className: 'tb-circle-label', permanent: true, direction: 'center'}))
.openTooltip(this.circle.getLatLng());
}

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/markers-data-layer.ts

@ -515,7 +515,7 @@ class TbMarkerDataLayerItem extends TbLatestDataLayerItem<MarkersDataLayerSettin
}
protected bindLabel(content: L.Content): void {
this.marker.bindTooltip(content, { className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.labelOffset });
this.marker.bindTooltip(L.TB.labelTooltip(content, { className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.labelOffset }));
}
protected updateLabel(data: FormattedData<TbMapDatasource>, dsData: FormattedData<TbMapDatasource>[]) {

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/polygons-data-layer.ts

@ -81,7 +81,7 @@ class TbPolygonDataLayerItem extends TbLatestDataLayerItem<PolygonsDataLayerSett
}
protected bindLabel(content: L.Content): void {
this.polygonContainer.bindTooltip(content, {className: 'tb-polygon-label', permanent: true, direction: 'center'})
this.polygonContainer.bindTooltip(L.TB.labelTooltip(content, {className: 'tb-polygon-label', permanent: true, direction: 'center'}))
.openTooltip(this.polygonContainer.getBounds().getCenter());
}

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/polylines-data-layer.ts

@ -86,7 +86,7 @@ class TbPolylineDataLayerItem extends TbLatestDataLayerItem<PolylinesDataLayerSe
}
protected bindLabel(content: L.Content): void {
this.polylineContainer.bindTooltip(content, {className: 'tb-polyline-label', permanent: true, direction: 'center'})
this.polylineContainer.bindTooltip(L.TB.labelTooltip(content, {className: 'tb-polyline-label', permanent: true, direction: 'center'}))
.openTooltip(this.polylineContainer.getBounds().getCenter());
}

2
ui-ngx/src/app/modules/home/components/widget/lib/maps/data-layer/trips-data-layer.ts

@ -366,7 +366,7 @@ class TbTripDataItem extends TbDataLayerItem<TripsDataLayerSettings, TbTripsData
}
} else {
this.marker.unbindTooltip();
this.marker.bindTooltip(content, { className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.labelOffset });
this.marker.bindTooltip(L.TB.labelTooltip(content, { className: 'tb-marker-label', permanent: true, direction: 'top', offset: this.labelOffset }));
}
this.labelContent = content;
this.boundLabelOffset = this.labelOffset;

116
ui-ngx/src/app/modules/home/components/widget/lib/maps/leaflet/leaflet-tb.ts

@ -1012,6 +1012,120 @@ class PatternImage extends PatternElement<L.TB.PatternImageOptions> implements L
}
}
const tooltipProto = L.Tooltip.prototype as any;
class LabelTooltip extends L.Tooltip implements L.TB.LabelTooltip {
private labelSize: L.Point;
private labelDirection: string;
private fontsReadyPending: boolean;
private readonly onLabelLayoutChange = () => {
this.labelSize = null;
if (this._map) {
tooltipProto._updatePosition.call(this);
}
};
onAdd(map: L.Map): this {
this.labelSize = null;
this.labelDirection = null;
super.onAdd(map);
this.watchFonts();
return this;
}
_updateContent() {
tooltipProto._updateContent.call(this);
this.labelSize = null;
this.watchImages();
}
_animateZoom(e: L.ZoomAnimEvent) {
if (e.zoom === this._map.getZoom()) {
tooltipProto._animateZoom.call(this, e);
}
}
_setPosition(pos: L.Point) {
const container = this.getElement();
const size = this.getLabelSize(container);
const offset = L.point(this.options.offset as L.PointTuple);
const anchor: L.Point = tooltipProto._getAnchor.call(this);
let direction = this.options.direction;
let subX: number;
let subY: number;
if (direction === 'top') {
subX = size.x / 2;
subY = size.y;
} else if (direction === 'bottom') {
subX = size.x / 2;
subY = 0;
} else if (direction === 'center') {
subX = size.x / 2;
subY = size.y / 2;
} else if (direction === 'right') {
subX = 0;
subY = size.y / 2;
} else if (direction === 'left') {
subX = size.x;
subY = size.y / 2;
} else if (this._map.layerPointToContainerPoint(pos).x < this._map.latLngToContainerPoint(this._map.getCenter()).x) {
direction = 'right';
subX = 0;
subY = size.y / 2;
} else {
direction = 'left';
subX = size.x + (offset.x + anchor.x) * 2;
subY = size.y / 2;
}
pos = pos.subtract(L.point(subX, subY, true)).add(offset).add(anchor);
if (this.labelDirection !== direction) {
L.DomUtil.removeClass(container, 'leaflet-tooltip-right');
L.DomUtil.removeClass(container, 'leaflet-tooltip-left');
L.DomUtil.removeClass(container, 'leaflet-tooltip-top');
L.DomUtil.removeClass(container, 'leaflet-tooltip-bottom');
L.DomUtil.addClass(container, 'leaflet-tooltip-' + direction);
this.labelDirection = direction;
}
L.DomUtil.setPosition(container, pos);
}
private getLabelSize(container: HTMLElement): L.Point {
if (this.labelSize) {
return this.labelSize;
}
const size = L.point(container.offsetWidth, container.offsetHeight);
if (size.x > 0 && size.y > 0) {
this.labelSize = size;
}
return size;
}
private watchImages() {
this.getElement()?.querySelectorAll('img').forEach((img) => {
if (!img.complete) {
img.addEventListener('load', this.onLabelLayoutChange, {once: true});
img.addEventListener('error', this.onLabelLayoutChange, {once: true});
}
});
}
private watchFonts() {
const fonts = document.fonts;
if (fonts && fonts.status !== 'loaded' && !this.fontsReadyPending) {
this.fontsReadyPending = true;
fonts.ready.then(() => {
this.fontsReadyPending = false;
this.onLabelLayoutChange();
});
}
}
}
const labelTooltip = (content: L.Content, options?: L.TooltipOptions): L.TB.LabelTooltip => {
return new LabelTooltip(options).setContent(content);
}
const sidebar = (options: TB.SidebarControlOptions): L.TB.SidebarControl => {
return new SidebarControl(options);
}
@ -1478,6 +1592,8 @@ L.TB = L.TB || {
PatternRect,
PatternPath,
PatternImage,
LabelTooltip,
labelTooltip,
sidebar,
sidebarPane,
layers,

3
ui-ngx/src/app/modules/home/components/widget/lib/maps/map.scss

@ -208,6 +208,9 @@ div.tb-widget .tb-widget-content.tb-no-interaction {
}
}
}
.leaflet-map-pane.leaflet-zoom-anim .leaflet-tooltip-pane {
visibility: hidden;
}
.leaflet-map-pane:not(.leaflet-zoom-anim) {
.leaflet-marker-icon {
&.tb-hoverable:not(.tb-selected) {

6
ui-ngx/src/typings/leaflet-extend-tb.d.ts

@ -265,6 +265,12 @@ declare module 'leaflet' {
setStyle(style: PatternImageOptions): this;
}
class LabelTooltip extends Tooltip {
constructor(options?: TooltipOptions, source?: Layer);
}
function labelTooltip(content: Content, options?: TooltipOptions): LabelTooltip;
function sidebar(options: SidebarControlOptions): SidebarControl;
function sidebarPane<O extends SidebarPaneControlOptions>(options: O): SidebarPaneControl<O>;

Loading…
Cancel
Save