Skip to content

Manage TileGrids in LayerFactory instead of MapComponent #309

@chrismayer

Description

@chrismayer

Currently the TileGrids, which are defined in the app-conf.json are managed withing the MapComponent: the OL TileGrids are instanciated in the created hook of the MapComponent (see here) and are stored in the tileGrids member variable. This works quite well in case you have only static map layers defined in the app-conf.json.

In case you want to create dynamic layers with a custom TileGrid by the LayerFactory this won't work. The TileGrid instance is set within the createLayers function of the MapComponent and not by the LayerFactory. Therefore a layer created in the app code with the LayerFactory is not aware of the TileGrid. In a project / app we used the following overwrite, which works quite well (here for Tile WMS):

// ==========================
// Overwrite LayerFactory with custom changes not (yet) in Wegue master
// ==========================
LayerFactory.tileGrids = {};
LayerFactory.createTileWmsLayer = (lConf) => {
  // apply additional HTTP params
  const params = { 'LAYERS': lConf.layers };
  ObjectUtil.mergeDeep(params, lConf.params);

  // manage TileGrid instances from app config
  const tileGridDefs = Vue.prototype.$appConfig.tileGridDefs || {};
  // Optional TileGrid definitions by name, for ref in Layers
  Object.keys(tileGridDefs).map(name => {
    LayerFactory.tileGrids[name] = new TileGrid(tileGridDefs[name]);
  });
  const tileGrid = lConf.tileGridRef ? LayerFactory.tileGrids[lConf.tileGridRef] : undefined;

  const layer = new TileLayer({
    ...LayerFactory.getCommonLayerOptions(lConf),
    // ...this.getCommonLayerOptions(lConf),
    source: new TileWmsSource({
      url: lConf.url,
      params: params,
      serverType: lConf.serverType,
      tileGrid: tileGrid,
      projection: lConf.projection,
      crossOrigin: lConf.crossOrigin,
      hoverable: lConf.hoverable,
      hoverAttribute: lConf.hoverAttribute,
      hoverOverlay: lConf.hoverOverlay
    })
  });

  return layer;
};
// ==========================
// END Overwrite LayerFactory  
// ==========================

Should I come up with a PR for that or are there any objections for this approach?

/cc @fschmenger @JakobMiksch @justb4 (and anybody else welcome of course)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions