-
Notifications
You must be signed in to change notification settings - Fork 58
Ol 5 migration snippets
LukasLohoff edited this page Sep 12, 2018
·
3 revisions
This file contains some snippets for migrating code from ol
v4 to v5 or react-geo
v9 to v10.
ol4:
import OlEventsCondition from 'ol/events/condition';
ol5:
import {
pointerMove as pointerMoveCondition,
click as ClickCondition
} from 'ol/events/condition';
ol4:
import proj4 from 'proj4';
import OlProj from 'ol/proj';
someFunc() {
OlProj.setProj4(proj4);
}
ol5:
import proj4 from 'proj4';
import {
register as registerProj4
} from 'ol/proj/proj4';
someFunc() {
registerProj4(proj4);
}
ol4:
import OlProjection from 'ol/proj'
someFunc() {
OlProjection.get(projection);
}
ol5:
import {
get as OlGetProjection
} from 'ol/proj';
someFunc() {
OlGetProjection(projection);
}
ol4:
someFunc() {
return olEvt.target.getRenderer().getType().toLowerCase() !== 'canvas';
}
ol5:
import OlCanvasMapRenderer from 'ol/renderer/canvas/Map';
someFunc() {
return !(olEvt.target.getRenderer() instanceof OlCanvasMapRenderer);
}
ol4:
import OlControl from 'ol/control';
someFunc() {
return OlControl.defaults;
}
ol5:
import {
defaults as OlDefaultControls
} from 'ol/control';
someFunc() {
return OlDefaultControls;
}
ol4:
import OlCoordinate from 'ol/coordinate';
someFunc() {
return OlCoordinate.createStringXY(2);
}
ol5:
import {createStringXY} from 'ol/coordinate';
someFunc() {
return createStringXY(2);
}
-
getAttributions()
now returns a function instead of an array (code here) -
getHTML()
is not working at the moment, see https://github.com/openlayers/openlayers/commit/1d5c7469747308b6b6c2b86c2d69a5b247fba76d
ol4:
const layerSource = layer.getSource();
someFunc() {
return layerSource.getAttributions()[0].getHTML();
}
ol5:
const layerSource = layer.getSource();
someFunc() {
return layerSource.getAttributions()()[0];
}