core icon indicating copy to clipboard operation
core copied to clipboard

[OpenLayers3] Cluster-example is not working in deployment mode

Open JoachimRohde opened this issue 10 years ago • 9 comments

I'm trying to use the cluster-example of the OpenLayers3 project (https://github.com/wicketstuff/core/blob/master/jdk-1.7-parent/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/ClusterPage.java). While in development mode everything works as expected but if I switch the RuntimeConfigurationType to Deployment I receive a JavaScript error when trying to zoom.

If I zoom with the scrollwheel of my mouse the map moves (but does not zoom).

Firebug is showing me this error:

TypeError: window.org_wicketstuff_openlayers3.vector642331791.getSource(...).source_ is undefined

I tracked this down to OpenLayersMap#renderClusterLoaderJs, line 385:

builder.append("  " + layer.getJsId() + ".getSource().source_.loader_(extent, resolution, projection);");

Due to the fact that in deployment mode the minified version of ol.js (the OpenLayer library) is delivered, the aforementioned line needs to be differently in deployment mode. And that's where I'm stucked since I have no clue how to find out how this line should look like when using the minified version. Any help here would be really appreciated (even hints how I could fix this myself).

Steps for reproduction:

  1. In https://github.com/wicketstuff/core/blob/master/jdk-1.7-parent/openlayers3-parent/openlayers3-examples/src/main/java/org/wicketstuff/openlayers3/examples/WicketApplication.java alter the line
return RuntimeConfigurationType.DEVELOPMENT;

to

return RuntimeConfigurationType.DEPLOYMENT;
  1. Run the cluster example.
  2. Try to zoom (no matter if via mousewheel or the buttons on the maps).

JoachimRohde avatar Feb 06 '15 11:02 JoachimRohde

@cmiles74 ping!

martin-g avatar Feb 06 '15 11:02 martin-g

I will take a look at this. I do have an application that's using these maps in deployment mode, but I'm not using the clustering. I will take a look at that over the weekend. Thank you!

cmiles74 avatar Feb 06 '15 13:02 cmiles74

Things have changed since I first hacked this cluster support into the library. The data seems to reliably load when the map is first drawn as well as after the map is zoomed. When the map pans, however, the new extent isn't passed to the cluster layer and then onto it's loader. For now, the hack that only works with the non-minified version of OpenLayers 3 is still required.

I posted to the OpenLayers 3 developer list in the hopes of getting some help or maybe tips toward a better solution. You can follow the thread here.

cmiles74 avatar Feb 09 '15 19:02 cmiles74

It doesn't look like there's a lot of activity in the OpenLayers projects around the cluster data loader. It's a neat example but I'm thinking maybe I should remove this one from the demo project until this issue is resolved. Let me know what you think.

cmiles74 avatar Mar 12 '15 14:03 cmiles74

Sorry for the late reply and thanks for taking a look into this.

As a workaround we currently always deliver the debug version of the JavaScript: new DefaultOpenLayersMap(...) {

@Override
public void renderHead(final IHeaderResponse response) {
    try {
        if (RuntimeConfigurationType.DEPLOYMENT.equals(getApplication().getConfigurationType())) {
            response.render(JavaScriptHeaderItem.forUrl(MyApplication.get().getServletContext().getContextPath() + "/js/ol.js"));
        } 
        response.render(OnDomReadyHeaderItem.forScript(this.renderJs()));
    } catch (Exception ex) {
        // if the back button is used, OpenLayers throws a NullPointerException
        // in this case, redirect to our page
        setResponsePage(MyPage.class);
        Logger.getLogger(MyPage.class.getName()).log(Level.FINE, "Error in renderHead: {0}", ex.getMessage());
    }
}

};

I would keep the example and update the documentation / example page regarding this, pointing out that the debug-version needs to be used and users should use it on their on risk. I'm happier with this workaround than writing this all on my own.

JoachimRohde avatar Apr 21 '15 20:04 JoachimRohde

I have added text to the clustering example that warns people about this issue. I also went ahead and tracked down the upstream issue in the OpenLayers project and have submitted a pull request that resolves the issue.

cmiles74 avatar Apr 23 '15 20:04 cmiles74

OpenLayers has merged in my fix for this issue and it will be in their next relase (v3.8.3). After they release, I'll update this module to use the new version, remove the kludgy fix and then remove the warning.

cmiles74 avatar Aug 28 '15 14:08 cmiles74

Thank you, Chris!

martin-g avatar Aug 29 '15 06:08 martin-g

Great, thanks.

JoachimRohde avatar Aug 30 '15 17:08 JoachimRohde