-2

there is already a working script for OL 3.

https://next.plnkr.co/edit/DXnDfStbvbetOtdU

Is there anyone who can rewrite that in OL 5?

Please as in the example for OL 3 without Ajax, JQuery and NodeJS. Please include with: https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/css/ol.css https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.3.0/build/ol.js

3
  • The links provided were sufficient to demonstrate the problem. Substituting the latest ol js and css urls in the working script produces a run time error when referencing the deprecated ol.animation
    – Mike
    Dec 30, 2018 at 22:47
  • "deprecated". OK. I have seen in the console a problem with the ".ani" and have hide him. Than was a problem with "getTarget()" and i'm confused.
    – Suka
    Dec 31, 2018 at 10:35
  • It's better to use getTargetElement() as it always returns a div element, getTarget() can return a div id or element, but when as in the example the element is specified in the map constructor either method will work.
    – Mike
    Dec 31, 2018 at 10:55

1 Answer 1

2

Currently it won't work in OpenLayers 4 or 5 because the the way animations work has changed since OL3.

In ol-popup.js you would need to remove

this.ani = options.ani;
if (this.ani === undefined) {
    this.ani = ol.animation.pan;
}

and change

if (this.ani && this.ani_opts) {
    this.ani_opts.source = center;
    this.getMap().beforeRender(this.ani(this.ani_opts));
}
this.getMap().getView().setCenter(this.getMap().getCoordinateFromPixel(px));

return this.getMap().getView().getCenter();

to

center = this.getMap().getCoordinateFromPixel(px);
if (this.ani_opts) {
    this.ani_opts.center = center;
    this.getMap().getView().animate(this.ani_opts);
} else {
    this.getMap().getView().setCenter(center);
}

return center;
1
  • you are realy helpfull! I have a problem, you have a solution. I'm ignore the VOTEWAR! Many thanks @Mike!!!
    – Suka
    Dec 31, 2018 at 10:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.