Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use app variables instead of latlng conversion. #10904

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions browser/src/control/Ruler.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ L.Control.Ruler = L.Control.extend({
// update show ruler state on rulerChange event
this.options.showruler = this._map.uiManager.getBooleanDocTypePref('ShowRuler', true);
if(this.options.showruler) {
// in case of disabled ruler at docload calculation of offset can be ignored
// in case of disabled ruler at docload calculation of offset can be ignored
// but after enabling the ruler we need to set the offset.
this._fixOffset();
}
Expand Down Expand Up @@ -418,28 +418,7 @@ L.Control.Ruler = L.Control.extend({
if (!this._map.options.docBounds || !this.options.showruler)
return;

var scale = this._map.getZoomScale(this._map.getZoom(), 10);
var mapPane = this._map._mapPane;
var topLeft = this._map.latLngToLayerPoint(this._map.options.docBounds.getNorthWest());
var firstTileXTranslate = topLeft.x;

var tileContainer = mapPane.getElementsByClassName('leaflet-tile-container');
for (var i = 0; i < tileContainer.length; ++i) {
if (parseInt(tileContainer[i].style.zIndex) === this._map.getMaxZoom()) {
tileContainer = tileContainer[i];
break;
}
}
var tileContainerXTranslate = 0;
if (tileContainer.style !== undefined)
tileContainerXTranslate = parseInt(tileContainer.style.transform.match(/\(([-0-9]*)/)[1]);

var mapPaneXTranslateMatch = mapPane.style.transform.match(/\(([-0-9]*)/);
var mapPaneXTranslate = 0;
if (mapPaneXTranslateMatch !== null && mapPaneXTranslateMatch[1] !== undefined)
mapPaneXTranslate = parseInt(mapPaneXTranslateMatch[1]);

var rulerOffset = mapPaneXTranslate + firstTileXTranslate + tileContainerXTranslate + (this.options.tileMargin * scale);
const rulerOffset = -app.file.viewedRectangle.cX1 + (this.options.tileMargin * app.getScale());

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

Expand Down
29 changes: 3 additions & 26 deletions browser/src/control/VRuler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,28 +425,6 @@ class VRuler {
// in case of disabled ruler at docload or event like 'moveend' calculation of offset can be ignored
if (!this._map.options.docBounds || !this.options.showruler) return;

const scale: number = this._map.getZoomScale(this._map.getZoom(), 10);
const mapPane = this._map._mapPane;
const topLeft = this._map.latLngToLayerPoint(
this._map.options.docBounds.getNorthWest(),
);
const firstTileXTranslate = topLeft.y;

let mapPaneYTranslate: number = 0;

// Extract the transform property directly from the mapPane style
const transformValue = mapPane.style.transform;

// Check if the transformValue exists and contains 'translate3d'
if (transformValue && transformValue.startsWith('translate3d')) {
// Split the transformValue string by commas and get the Y value
const transformArray = transformValue.split(',');
if (transformArray.length >= 2) {
// The Y value is the second item in the 'translate3d' format
mapPaneYTranslate = parseFloat(transformArray[1].trim());
}
}

// we need to also consider if there is more then 1 page then pageoffset is crucial to consider
// i have calculated current page using pageoffset and pageWidth coming from CORE
// based on that calculate the page offset
Expand All @@ -462,10 +440,9 @@ class VRuler {
(this._map._docLayer._docPixelSize.y / this._map._docLayer._pages);

const rulerOffset: number =
mapPaneYTranslate +
firstTileXTranslate +
pageoffset +
this.options.tileMargin * scale;
-app.file.viewedRectangle.cY1 +
this.options.tileMargin * app.getScale() +
pageoffset;

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

Expand Down
Loading