TDesjardins / gwt-ol

GWT wrapper for OpenLayers 3+ using JSInterop
Apache License 2.0
70 stars 33 forks source link

Compile fails if OpenLayers dependencies are injected by GWT #160

Closed mbrigl closed 4 years ago

mbrigl commented 4 years ago

The Measure interaction in package ol.gwt causes an exception. The Measure is defined as non native type, but extends Interaction that is a native type.

Uncaught TypeError: Cannot read property 'interaction' of undefined

TDesjardins commented 4 years ago

Hello @mbrigl ,

which version of gwt-ol and OpenLayers are you using? Yes, Measure is non native but extends native type Interaction. This is correct!

mbrigl commented 4 years ago

I'm using branch gwt/2.9. Due the Measure class I'm not able to run the application nor in compiled nor in development mode. If I remove the Measure class, all works correctly.

TDesjardins commented 4 years ago

I'm using branch gwt/2.9. Due the Measure class I'm not able to run the application nor in compiled nor in development mode. If I remove the Measure class, all works correctly.

And which OL version?

mbrigl commented 4 years ago

5.3.1

TDesjardins commented 4 years ago

When I use branch gwt/2.9 the measure example works fine with version OL 5.3.0 which is the latest official release of major version 5. Could you check this? There is a tag 5.3.1 but no releases in jsdelivr or rawgit. Is there a special reason for choosing an unoffical release? If not I would suggest you to use 5.3.0. By the way you can also use a release of gwt-ol which supports GWT 2.9. I will release this officially in the next days. Also a version with OL 6 support will be released soon.

mbrigl commented 4 years ago

Sorry, I wrote the wrong version number. I'm using 5.3.0 and I'm using the maven release. Nevertheless I found the problem but not the solution:

In your demo the OpenLayer js/css are included in the HTML page. In my example I'm injecting the js/css library from GWT self. Seems that is the problem:

public class OL3EntryPoint implements EntryPoint {

  private static final OpenLayer OPENLAYER = GWT.create(OpenLayer.class);

  @Override
  public void onModuleLoad() {
      ScriptInjector.fromString(MapEntryPoint.OPENLAYER.openlayer().getText()).inject();
  }

  public interface OpenLayer extends ClientBundle {

    @Source("ol-v5.3.0.js")
    TextResource openlayer();
  }
}
TDesjardins commented 4 years ago

In your demo the OpenLayer js/css are included in the HTML page. In my example I'm injecting the js/css library from GWT self.

The difference is the order of the scripts. In the demo the ol script is loaded before GWT script (HTML page). In your script the GWT script has to be loaded before ScriptInjector can add the ol script. Seems that GWT checks the non native types before entering the entry point. At the time the non native Measure class is checked, the inherited interaction class could not be resolved because the ol script isn't loaded yet.

But that's not a special problem of GWT 2.9 I think what the title of your issue implies. I suppose the behaviour is the same with GWT 2.8.

TDesjardins commented 4 years ago

@mbrigl Is this a problem for you to load the ol script in your HTML file? I will ask the GWT community if there is another solution for this issue. Actually you can reopen this issue because it isn't solved. Maybe renaming it would be useful.

mbrigl commented 4 years ago

It's not a serious problem. Injecting the dependencies by the gwt client makes it easier to avoid the usage of the wrong version of a library

TDesjardins commented 4 years ago

@mbrigl Before go further we have to clarify the facts. Actually I wanted you to rename the issue because it looks like this is a special problem of the GWT 2.9 version but it is also present when using 2.8 right? Now you speaking about a compile failure but the thing you described and the issue I reproduced is an runtime issue. Could you confirm that the failure doesn't appear when compiling?

mbrigl commented 4 years ago

@mbrigl Before go further we have to clarify the facts. Actually I wanted you to rename the issue because it looks like this is a special problem of the GWT 2.9 version but it is also present when using 2.8 right? Now you speaking about a compile failure but the thing you described and the issue I reproduced is an runtime issue. Could you confirm that the failure doesn't appear when compiling?

Yes it's a runtime problem, not a compile problem. I have this issue only with GWT 2.9, even if I never used the problematic class Measure. With GWT 2.8.2 and gwt-ol master branch I have not this problem, but it seems Measure will not be exposed to JavaScript (not in your demo application as well) You are free to rename the issue.

TDesjardins commented 4 years ago

After some investigations I can say that this is an issue of GWT not GWT-OL. As written in the linked issue you can solve this problem in test and production by using splitpoints, but SDM doesn't work then because it doesn't support code splitting. Otherwise you could simply load external scripts by referencing it in the HTML file like in the demo app.