Skip to content

Commit 7faabbd

Browse files
committed
Use app variables instead of latlng conversion.
Signed-off-by: Gökay Şatır <[email protected]> Change-Id: Id232cee5fe59c198dec8f0b5223ce84ede915216
1 parent 84d2770 commit 7faabbd

File tree

2 files changed

+5
-49
lines changed

2 files changed

+5
-49
lines changed

browser/src/control/Ruler.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ L.Control.Ruler = L.Control.extend({
205205
// update show ruler state on rulerChange event
206206
this.options.showruler = this._map.uiManager.getBooleanDocTypePref('ShowRuler', true);
207207
if(this.options.showruler) {
208-
// in case of disabled ruler at docload calculation of offset can be ignored
208+
// in case of disabled ruler at docload calculation of offset can be ignored
209209
// but after enabling the ruler we need to set the offset.
210210
this._fixOffset();
211211
}
@@ -418,28 +418,7 @@ L.Control.Ruler = L.Control.extend({
418418
if (!this._map.options.docBounds || !this.options.showruler)
419419
return;
420420

421-
var scale = this._map.getZoomScale(this._map.getZoom(), 10);
422-
var mapPane = this._map._mapPane;
423-
var topLeft = this._map.latLngToLayerPoint(this._map.options.docBounds.getNorthWest());
424-
var firstTileXTranslate = topLeft.x;
425-
426-
var tileContainer = mapPane.getElementsByClassName('leaflet-tile-container');
427-
for (var i = 0; i < tileContainer.length; ++i) {
428-
if (parseInt(tileContainer[i].style.zIndex) === this._map.getMaxZoom()) {
429-
tileContainer = tileContainer[i];
430-
break;
431-
}
432-
}
433-
var tileContainerXTranslate = 0;
434-
if (tileContainer.style !== undefined)
435-
tileContainerXTranslate = parseInt(tileContainer.style.transform.match(/\(([-0-9]*)/)[1]);
436-
437-
var mapPaneXTranslateMatch = mapPane.style.transform.match(/\(([-0-9]*)/);
438-
var mapPaneXTranslate = 0;
439-
if (mapPaneXTranslateMatch !== null && mapPaneXTranslateMatch[1] !== undefined)
440-
mapPaneXTranslate = parseInt(mapPaneXTranslateMatch[1]);
441-
442-
var rulerOffset = mapPaneXTranslate + firstTileXTranslate + tileContainerXTranslate + (this.options.tileMargin * scale);
421+
const rulerOffset = -app.file.viewedRectangle.cX1 + (this.options.tileMargin * app.getScale());
443422

444423
this._rFace.style.marginInlineStart = rulerOffset + 'px';
445424

browser/src/control/VRuler.ts

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -425,28 +425,6 @@ class VRuler {
425425
// in case of disabled ruler at docload or event like 'moveend' calculation of offset can be ignored
426426
if (!this._map.options.docBounds || !this.options.showruler) return;
427427

428-
const scale: number = this._map.getZoomScale(this._map.getZoom(), 10);
429-
const mapPane = this._map._mapPane;
430-
const topLeft = this._map.latLngToLayerPoint(
431-
this._map.options.docBounds.getNorthWest(),
432-
);
433-
const firstTileXTranslate = topLeft.y;
434-
435-
let mapPaneYTranslate: number = 0;
436-
437-
// Extract the transform property directly from the mapPane style
438-
const transformValue = mapPane.style.transform;
439-
440-
// Check if the transformValue exists and contains 'translate3d'
441-
if (transformValue && transformValue.startsWith('translate3d')) {
442-
// Split the transformValue string by commas and get the Y value
443-
const transformArray = transformValue.split(',');
444-
if (transformArray.length >= 2) {
445-
// The Y value is the second item in the 'translate3d' format
446-
mapPaneYTranslate = parseFloat(transformArray[1].trim());
447-
}
448-
}
449-
450428
// we need to also consider if there is more then 1 page then pageoffset is crucial to consider
451429
// i have calculated current page using pageoffset and pageWidth coming from CORE
452430
// based on that calculate the page offset
@@ -462,10 +440,9 @@ class VRuler {
462440
(this._map._docLayer._docPixelSize.y / this._map._docLayer._pages);
463441

464442
const rulerOffset: number =
465-
mapPaneYTranslate +
466-
firstTileXTranslate +
467-
pageoffset +
468-
this.options.tileMargin * scale;
443+
-app.file.viewedRectangle.cY1 +
444+
this.options.tileMargin * app.getScale() +
445+
pageoffset;
469446

470447
this._rFace.style.marginInlineStart = rulerOffset + 'px';
471448

0 commit comments

Comments
 (0)