Class: Class

Class

This library uses ES2015 class system.
Class is the root class of class hierachy.
It provides utility methods to make it easier to manage configration options, merge mixins and add init hooks.

(abstract) new Class(options) [source]

Create an object, set options if given and call all the init hooks.
Options is where the object manages its configuration. Options passed to the object will be merged with parent's instead of overriding it.
var defaultOptions = {
    'foo' : 'bar'
};
class Foo extends maptalks.Class {
    constructor(id, options) {
        super(options);
        this.setId(id);
    }

    setId(id) {
        this.id = id;
    }

    whenCreated() {
        // .....
    }
}

Foo.mergeOptions(defaultOptions);

Foo.addInitHook('whenCreated');
Parameter Type Description
options Object options to set

Static Methods

  • (static) addInitHook(fn, …args) [source]

  • Add an init hook, which will be called when the object is initiated.
    It is useful in plugin developing to do things when creating objects without changing class's constructor.
    Parameter Type Description
    fn String | function a hook function or name of the hook function
    args repeatable Array.<Any> arguments for the init hook function

  • (static) include(…sources) [source]

  • Mixin the specified objects into the class as prototype properties or methods.
    Parameter Type Description
    sources repeatable Object objects to mixin

  • (static) mergeOptions(options) [source]

  • Mixin options with the class's default options.
    Parameter Type Description
    options Object options to merge.

    Methods

  • callInitHooks() [source]

  • Visit and call all the init hooks defined on Class and its parents.
    Returns:
    Class: this
  • setOptions(options) [source]

  • Merges options with the default options of the object.
    Parameter Type Description
    options Object options to set
    Returns:
    Class: this
  • config(conf) [source]

  • 1. Return object's options if no parameter is provided.
    2. update an option and enable/disable the handler if a handler with the same name existed.
    // Get marker's options;
    var options = marker.config();
    // Set map's option "draggable" to false and disable map's draggable handler.
    map.config('draggable', false);
    // You can update more than one options like this:
    map.config({
        'scrollWheelZoom' : false,
        'doubleClickZoom' : false
    });
    Parameter Type Description
    conf Object config to update
    Returns:
    Class: this
  • onConfig() [source]

  • Default callback when config is called