tombatossals / angular-openlayers-directive

AngularJS directive to embed an interact with maps managed by the OpenLayers library
http://tombatossals.github.io/angular-openlayers-directive/
MIT License
282 stars 184 forks source link

Providing arbitrary options for sources #230

Open aubm opened 8 years ago

aubm commented 8 years ago

Hello, I noticed that although the olHelpers provides a simple interface for building sources with the createSource function, the list of parameters we can provide is limited to those supported by the function.

For now if I need to provide some parameters to OpenLayers which are not supported by the directive, I can create a PR and that's fine as it does not happen too often. But I wonder if we could find a way to provide arbitrary options for sources.

Maybe a specific "raw" case could do the trick by providing a object like :

{
    type: 'raw',
    source: new ol.source.XYZ(...)
}

What do you think ?

juristr commented 8 years ago

Sure, can you elaborate bit more on this?

davinkevin commented 8 years ago

+1

The goal is to use every parameters defined by OL3 without restriction. If we choose to use this type, we know we are at the bleeding edge of the directive :

This kind of code could be in the switch/case which define the oSource in the olHelper : https://github.com/davinkevin/angular-openlayers-directive/commit/ecc46804f601849ea074e0f456eabca257144cc0

Do you think there is other side effect by doing that ?

juristr commented 8 years ago

Interesting.

Do you think there is other side effect by doing that ?

No, not really. It's an edge case where the developer might want to go native with ol3 constructs, which I think is fine. In the general case you could still benefit from the simpler object configuration syntax the directive currently offers.

Could you submit a PR for that?

davinkevin commented 8 years ago

After investigation, it seems ol object are too complexe for the $scope.$watch function. When angular try to do a comparison between two OpenLayer Source object, the browser reach it's maximum call stack size (from here : https://github.com/tombatossals/angular-openlayers-directive/blob/master/src/directives/layer.js#L61 )

So, as an alternative, and only for native type of OpenLayer (ImageWMS, TileWMS, WMTS, OSM, BingMaps, MapQuest, TileJSON, TileVector, TileTMS, TileImage, KML, XYZ), we should find a way to let the developper give angular-openlayer-directive the parameter of the constructor.

For example :

if (source.rawParameters) {
  return new ol.layer.[source.type](source.rawParameters);
}

switch(source.type):
case ...
...

If you have a better idea, I'll be glad to hear it :smile: