Home Reference Source Repository
import {ParameterSync} from 'leaflet-coverage/'
public class | source

ParameterSync

Expression Extends:

class ParameterSync extends EventMixin(L.Class)

Synchronizes visualization options of multiple renderer layers with matching Parameter and exposes a combined view of those options in form of a virtual layer object.

A common use case for this is to have equal palettes and only a single legend for multiple layers describing the same parameter.

Synchronizing visualization options means synchronizing certain common properties of the layer instances. For example, the palette extents of two layers can be synchronized by merging the extents of both. The logic for doing that has to be specified in terms of binary functions supplied in the constructor.

By default, a simple algorithm determines if two Parameter objects are equivalent by checking whether things like observedPropery have the same ID, units are the same, etc. This default algorithm can be replaced with a custom one. Such a custom algorithm could relate different vocabularies with each other or perform other checks.

Example:

let paramSync = new C.ParameterSync({
  syncProperties: {
    palette: (p1, p2) => p1,
    paletteExtent: (e1, e2) => e1 && e2 ? [Math.min(e1[0], e2[0]), Math.max(e1[1], e2[1])] : null
  }
}).on('parameterAdd', e => {
  // The virtual sync layer proxies the synced palette, paletteExtent, and parameter.
  // The sync layer will fire a 'remove' event once all real layers for that parameter were removed.
  let layer = e.syncLayer
  if (layer.palette) {
    C.legend(layer, {
      position: 'bottomright'
    }).addTo(map)
  }
})
let layer = C.layerFactory()(cov).on('add', e => {
  // Only add the layer to the ParameterSync instance once it has initialized.
  // We can use the 'add' event for that.
  paramSync.addLayer(e.target)
})

Constructor Summary

Public Constructor
public

constructor(options: Object)

Member Summary

Public Members
public

Method Summary

Public Methods
public

addLayer(layer: ILayer)

Adds a layer that will be synchronized.

public

pause()

Pause synchronization.

public

resume(sync: bool)

Resumes synchronization.

Public Constructors

public constructor(options: Object) source

Params:

NameTypeAttributeDescription
options Object
options.syncProperties Object

An object that defines which properties shall be synchronized and how. Each key is a property name where the value is a binary function that merges the values of two such properties.

options.match Function
  • optional

Custom function that checks if two Parameter objects shall be equivalent. The default function is simple and checks for identity of several properties.

Public Members

public paused: boolean source

Public Methods

public addLayer(layer: ILayer) source

Adds a layer that will be synchronized.

Synchronization stops automatically when the layer fires a 'remove' event.

Params:

NameTypeAttributeDescription
layer ILayer

The layer to synchronize.

public pause() source

Pause synchronization. This is useful when a property of many layers has to be set manually (like paletteExtent = 'fov') and the synchronization shall happen afterwards (see resume()).

public resume(sync: bool) source

Resumes synchronization.

Params:

NameTypeAttributeDescription
sync bool
  • optional

If true, then all layers will be synchronized immediately.