ol-ext icon indicating copy to clipboard operation
ol-ext copied to clipboard

Openlayers 7 compatibility

Open fracsi opened this issue 2 years ago • 23 comments

Current version seems to be incompatible with the new Openlayers 7.0.0.

Legend throws Class constructor BaseObject cannot be invoked without 'new' here: https://github.com/Viglino/ol-ext/blob/0cc449ad30a905207e5d9940c0c082f27261d5fb/src/legend/Legend.js#L39

fracsi avatar Aug 19 '22 07:08 fracsi

Whole ol-ext would require rewritting now, OpenLayers changed building options, dropping legacy syntax. Now in bundle there are real classes that are much more restrict. I was using just AnimatedCluster, so I just locally wrote something like:

export class AnimatedCluster7 extends ol_layer_Vector {
  constructor(options) {
    // constructor
  }
  // other methods, previously injected through prototype

It's not hard job, but require a lot of work.

Anyway, it would be nice to rewrite it slowly in TypeScript, now that OL has own types in it's package.

Razi91 avatar Aug 19 '22 08:08 Razi91

ol-ext has its own TypeScript def: https://github.com/Siedlerchr/types-ol-ext

Viglino avatar Aug 19 '22 14:08 Viglino

@Razi91 VSCode as an option to automatically convert to class syntax. That's what I use as a base for creating the external typedefs.

The error comes because transpiled classes to ES5 cannot extend native ES6 ones https://stackoverflow.com/a/51860850 I am unfortunately not that deep into the gulp stuff to know if we can use it without

Here is an example how it looks like: https://github.com/Siedlerchr/ol-ext/tree/typejsdoc

Siedlerchr avatar Aug 20 '22 12:08 Siedlerchr

The examples are now not working as the latest build and css are now at https://openlayers.org/en/latest/legacy/ol.css https://openlayers.org/en/latest/legacy/ol.js

That is not compatible with extending classes using ol_ext_inherits so the short term fix would be to change to https://openlayers.org/en/v6.15.1/css/ol.css https://openlayers.org/en/v6.15.1/build/ol.js

mike-000 avatar Aug 21 '22 21:08 mike-000

The problem is to ensure compatibility with the pure js lib (https://viglino.github.io/ol-ext/dist/ol-ext.js). But ES6 class syntax is now widely supported in all modern browsers and could be used indeed (ending explorer support as ol7 does) I'll try to integrate it progressively...

Viglino avatar Aug 22 '22 05:08 Viglino

I will update my fork asap, so you can use this PR then as a base.

Siedlerchr avatar Aug 22 '22 08:08 Siedlerchr

That is not compatible with extending classes using ol_ext_inherits so the short term fix would be to change to https://openlayers.org/en/v6.15.1/css/ol.css https://openlayers.org/en/v6.15.1/build/ol.js Examples are now working on v6.15.1 while updateing to ES6 classes

Viglino avatar Aug 22 '22 12:08 Viglino

@Razi91 VSCode as an option to automatically convert to class syntax. That's what I use as a base for creating the external typedefs.

I've just discovered this function 🤩 It's a kind of magic!

Viglino avatar Aug 22 '22 12:08 Viglino

@Siedlerchr tell me if you have something working. I'll may have some times to work on it tomorrow...

Viglino avatar Aug 23 '22 06:08 Viglino

I've started to move to ES6 classes. @Razi91 see https://viglino.github.io/ol-ext/examples/animation/map.animatedcluster.html @Siedlerchr I don't use your PR to add functionalities step by step (the whole bulk is to hard to debug), but your VS tip work like a charm... Tell me if you see something that can help to derive typescript defs.

Viglino avatar Aug 24 '22 14:08 Viglino

@Viglino I basically just used VS Code's magic function. Nothing else. I tested a couple of examples, and it seems to work. I just also checked with peer deps update to ol 7. For typedefs, the javadoc is enough if the types (e.g. number or the ol ones can be correctly inferred.

Siedlerchr avatar Aug 24 '22 15:08 Siedlerchr

Yes. Classes are needed. I solved problem with OL 7 and ol-ext using webpack and babel-loader: to force to transpile /node_modules/ol/* into JS without classes. As a workaround. It works.

image

So, plugin "@babel/plugin-transform-classes" converts classes into functions.. and legacy ol-ext continues working (until classes are created, I hope).

vitalus avatar Aug 25 '22 13:08 vitalus

@Viglino I recently tried to create an example in the types for the video recorder function and noticed that I already have problems with the GeoPortail Layer that cannot be cast to the BaseLayer class. Would be nice if you could take a look at that hierarchy while transforming this to the classes

Siedlerchr avatar Aug 29 '22 20:08 Siedlerchr

@Siedlerchr I'm slowly moving to class declaration (actually I'm in holidays). Geoportail Layer are now using class declaration...

Viglino avatar Sep 08 '22 07:09 Viglino

@Viglino Thanks for the continuous work. Enjoy your holidays :) Edit and thanks for the clarification of the class expression thing.

Siedlerchr avatar Sep 08 '22 07:09 Siedlerchr

I'm almost done upgrading to ES6 classes. All examples are using ol v.7 I still have to check some extra classes and lint... Try to publish a new version asap.

Viglino avatar Sep 10 '22 07:09 Viglino

@mike-000 I've noticed a bug on VectorLayer opacity. It seems it is applied twice. You can see it on: https://viglino.github.io/ol-ext/examples/layer/test.html The first time the opacity is set is right. But when you move the map the layer fade.

Viglino avatar Sep 10 '22 07:09 Viglino

I've published a new version 4.0.0 👉 4️⃣.0️⃣.0️⃣ https://www.npmjs.com/package/ol-ext Now compatible with ol v7 Tell me if you see bugs 🐞

Viglino avatar Sep 17 '22 10:09 Viglino

I will try to work on updated types.

Siedlerchr avatar Sep 17 '22 11:09 Siedlerchr

😃 Official release : https://twitter.com/jmviglino/status/1573291101791948800 image

Viglino avatar Sep 23 '22 13:09 Viglino

Oh need to make a new release for the types then

Siedlerchr avatar Sep 23 '22 13:09 Siedlerchr

Oh need to make a new release for the types then

no pressure...

Viglino avatar Sep 23 '22 15:09 Viglino

@Viglino Just released a new version 3.0.0 of the types package. Now compatible with ol-ext 4.01 and ol7

Siedlerchr avatar Sep 27 '22 18:09 Siedlerchr

Does ol-ext now have OL7 compatibility, ie should this issue remain open?

Would it be worth mentioning compatibility status in the README.md?

leegee avatar Apr 05 '23 09:04 leegee

ol-ext is compatible with ol7

Viglino avatar Apr 05 '23 11:04 Viglino

I think the minified build in #901 was not compatible but in the latest version that is also fixed?

Note that all the examples are still using OpenLayers 7.0.0 as the legacy path was not used after that, the latest released versions are now at

https://openlayers.org/en/latest/ol/dist/ol.js https://openlayers.org/en/latest/ol/ol.css

mike-000 avatar Apr 05 '23 11:04 mike-000