Home Reference Source Repository
public class | source

MapBuilder

Class for encapsulating a map building operation.

Example:

new MapBuilder()
  .specFile('examples/france.yaml')
  .onError((err) => {
    console.log(err);
  })
  .onSuccess((data) => {
    console.log("Success");
    do_something_with_svg_data(data);
  })
  .build_map();

Method Summary

Public Methods
public

Asynchronously build the map.

public

force(force: boolean): *

Specify whether to force a rebuild.

public

Print information from the shape file specified in the config.

public

onError(err_cb: function(err: string)): *

Specify an error callback for this MapBuilder.

public

onSuccess(ok_cb: function(data: string)): *

Specify a success callback for this MapBuilder.

public

spec(spec_obj: Object): *

Specify the configuration to use.

public

specFile(spec_file: string): *

Specify the configuration to use.

Public Methods

public build_map() source

Asynchronously build the map.

Requires onError and onSuccess specified to handle the results.

public force(force: boolean): * source

Specify whether to force a rebuild.

Normally maps are cached based on the specification, but if you update this module you may want to use this option to force the map to be re-created.

Params:

NameTypeAttributeDescription
force boolean

whether to force map re-creation.

Return:

*

public get_shape_info() source

Print information from the shape file specified in the config.

Requires onError and onSuccess specified to handle the results.

public onError(err_cb: function(err: string)): * source

Specify an error callback for this MapBuilder.

Params:

NameTypeAttributeDescription
err_cb function(err: string)

the error callback.

Return:

*

public onSuccess(ok_cb: function(data: string)): * source

Specify a success callback for this MapBuilder.

Params:

NameTypeAttributeDescription
ok_cb function(data: string)

the success callback, passed the generated SVG as a string.

Return:

*

public spec(spec_obj: Object): * source

Specify the configuration to use.

May be used in conjunction with specFile. They will be merged with the spec_obj taking precedence in case of clashes.

Params:

NameTypeAttributeDescription
spec_obj Object
  • nullable: false

object describing the configuration to use.

Return:

*

Example:

var spec_obj = {
  "parameters": {
    "projection": {
      "type": "mercator",
      "width": 960,
      "height": 1120,
      "scale": 1600,
      "center": [2, 50]
    }
  }
}
new MapBuilder()
  .spec(spec_obj)
  // (Register .onError and .onSuccess callbacks.)
  .build_map();

public specFile(spec_file: string): * source

Specify the configuration to use.

May be used in conjunction with spec. They will be merged with the spec_obj taking precedence in case of clashes.

Params:

NameTypeAttributeDescription
spec_file string

configuration file to use.

Return:

*