Skip to content

Commit

Permalink
New version of OpenLayers (origo-map#1648)
Browse files Browse the repository at this point in the history
New version of OpenLayers and removed monkey patch in print component since OL now have native support for transform: scale
  • Loading branch information
jokd committed Jan 12, 2023
1 parent 9708b9d commit 42404fd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 65 deletions.
67 changes: 41 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"downloadjs": "^1.4.7",
"elm-pep": "^1.0.6",
"html2canvas": "^1.4.0",
"ol-mapbox-style": "8.2.1",
"ol-mapbox-style": "9.4.0",
"jspdf": "^2.5.0",
"ol": "^6.15.1",
"ol": "^7.2.2",
"pepjs": "^0.5.3",
"proj4": "^2.7.5"
},
Expand Down
37 changes: 0 additions & 37 deletions src/controls/print/print-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import TileImage from 'ol/source/TileImage';
import TileWMSSource from 'ol/source/TileWMS';
import TileGrid from 'ol/tilegrid/TileGrid';
import { Group } from 'ol/layer';
import PluggableMap from 'ol/PluggableMap';
import {
Button, Component, cuid, dom
} from '../../ui';
Expand All @@ -19,34 +18,6 @@ import { afterRender, beforeRender } from './download-callback';
import maputils from '../../maputils';
import PrintResize from './print-resize';
import { withLoading } from '../../loading';
/** Backup of original OL function */
const original = PluggableMap.prototype.getEventPixel;

/**
* Recalculates the event position to account for transform: scale in the container as OL does not do that.
* Used to monkey patch OL.
* @param {any} event
*/
const getEventPixelScale = function monkeyPatch(event) {
// This is internal in OL, nust allow
// eslint-disable-next-line no-underscore-dangle
const viewportPosition = this.viewport_.getBoundingClientRect();
let size = [viewportPosition.width, viewportPosition.height];
const view = this.getView();
if (view) {
// This is internal in OL, nust allow
// eslint-disable-next-line no-underscore-dangle
size = view.getViewportSize_();
}
const eventPosition = 'changedTouches' in event ? event.changedTouches[0] : event;

return [
((eventPosition.clientX - viewportPosition.left) * size[0])
/ viewportPosition.width,
((eventPosition.clientY - viewportPosition.top) * size[1])
/ viewportPosition.height
];
};

const PrintComponent = function PrintComponent(options = {}) {
const {
Expand Down Expand Up @@ -463,10 +434,6 @@ const PrintComponent = function PrintComponent(options = {}) {
printResize.resetLayers();
printResize.setResolution(150);
}
// Restore monkey patch
// WORKAROUND: Remove when OL supports transform: scale
// See https://github.com/openlayers/openlayers/issues/13283
PluggableMap.prototype.getEventPixel = original;
// Restore scales
if (!supressResolutionsRecalculation) {
const viewerResolutions = viewer.getResolutions();
Expand Down Expand Up @@ -553,10 +520,6 @@ const PrintComponent = function PrintComponent(options = {}) {
}));
},
async onRender() {
// Monkey patch OL
// WORKAROUND: Remove when OL supports transform: scale
// See https://github.com/openlayers/openlayers/issues/13283
PluggableMap.prototype.getEventPixel = getEventPixelScale;
printScale = 0;
today = new Date(Date.now());
viewerMapTarget = map.getTarget();
Expand Down

0 comments on commit 42404fd

Please sign in to comment.