Skip to content

Ol 5 migration snippets

LukasLohoff edited this page Sep 12, 2018 · 3 revisions

ol 5 migration snippets

This file contains some snippets for migrating code from ol v4 to v5 or react-geo v9 to v10.

Event Conditions

ol4:

import OlEventsCondition from 'ol/events/condition';

ol5:

import {
  pointerMove as pointerMoveCondition,
  click as ClickCondition
} from 'ol/events/condition';

Proj4

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);
}

OlProjection

ol4:

import OlProjection from 'ol/proj'

someFunc() {
  OlProjection.get(projection);
}

ol5:

import {
  get as OlGetProjection
} from 'ol/proj';


someFunc() {
  OlGetProjection(projection);
}

Renderer

ol4:

someFunc() {
  return olEvt.target.getRenderer().getType().toLowerCase() !== 'canvas';
}

ol5:

import OlCanvasMapRenderer from 'ol/renderer/canvas/Map';
someFunc() {
  return !(olEvt.target.getRenderer() instanceof OlCanvasMapRenderer);
}

Default Controls

ol4:

import OlControl from 'ol/control';
someFunc() {
  return OlControl.defaults;
}

ol5:

import {
  defaults as OlDefaultControls
} from 'ol/control';

someFunc() {
  return OlDefaultControls;
}

OlCoordinate

ol4:

import OlCoordinate from 'ol/coordinate';

someFunc() {
  return OlCoordinate.createStringXY(2);
}

ol5:

import {createStringXY} from 'ol/coordinate';

someFunc() {
  return createStringXY(2);
}

getAttributions()

ol4:

const layerSource = layer.getSource();

someFunc() {
  return layerSource.getAttributions()[0].getHTML();
}

ol5:

const layerSource = layer.getSource();

someFunc() {
  return layerSource.getAttributions()()[0];
}