Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish as npm package and update to support newer OpenLayers version #2

Open
whakey opened this issue Nov 4, 2021 · 1 comment
Open

Comments

@whakey
Copy link

whakey commented Nov 4, 2021

Please provide us with the following information:

This issue is for a: (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Currently the code is not published as a npm package and taking it into use is unnecessarily difficult.
It also targets OpenLayers v4.6.5, which is quite old compared to the newest release v6.9.0.

@ChrisHSandN
Copy link

To add to this, since Openlayers 5, the library is now ES module based and there is no longer the global window.ol object which this plugin relies on so it is effectively unusable now.

For others looking for a solution, below is my webpack config workaround using imports-loader and exports-loader to shim the package. It's pretty horrible but it works.

package.json

"devDependencies": {
  "imports-loader": "^3.1.1",
  "exports-loader": "^3.1.0"
},
"dependencies": {
  "azure-maps-openlayers": "https://github.com/Azure-Samples/azure-maps-openlayers.git"
},

webpack.config.js

module: {
  rules: [
    {
      test: require.resolve("azure-maps-openlayers/dist/azure-maps-openlayers"),
      use: {
        loader: "exports-loader",
        options: {
          exports: "default _window",
        },
      },
    },
    {
      test: require.resolve("azure-maps-openlayers/dist/azure-maps-openlayers"),
      use: {
        loader: "imports-loader",
        options: {
          imports: [
            {
              syntax: "named",
              moduleName: "ol/source",
              name: "XYZ",
              alias: "OlSourceXYZ",
            },
            {
              syntax: "named",
              moduleName: "ol/tilegrid/TileGrid",
              name: "default",
              alias: "OlTileGridTileGrid",
            }
          ],
          additionalCode: 'var _window = window;var ol={source:{XYZ:OlSourceXYZ},tilegrid:{TileGrid:OlTileGridTileGrid}};',
          wrapper: 'window',
        },
      },
    },
  ]
},

Usage

import {default as AzureMapsOpenlayers} from 'azure-maps-openlayers/dist/azure-maps-openlayers';

new AzureMapsOpenlayers.ol.source.AzureMaps({
  ...
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants