Node Mapnik

add_layer clear clone font fontDirectory fontFiles fromStringSync fromStringSync get_layer layers load loadSync resize scale scaleDenominator addData addGeoJSON clear compositeSync empty getData getDataSync height isSolid isSolidSync names painted query reportGeometrySimplicity reportGeometrySimplicitySync reportGeometryValidity reportGeometryValiditySync setData toGeoJSON toGeoJSONSync toJSON width addField addField encodeSync height view width attributes extent geometry id toJSON fromJSON clear clearSync compare composite copy copySync data demultiply demultiplySync encode encodeSync fill fillSync filter filterSync getPixel getType height isSolidSync premultiplied premultiply premultiplySync resize resizeSync save saveSync setPixel view width fromBufferSync fromBytes fromSVG fromSVGBytes describe extent extent toJSON toJSONSync toWKB toWKT type forward inverse get_premultiplied hex set_premultiplied toString next mapnik .compositeOp .imageScaling .imageType .polygonFillType mapnik.blend mapnik.Color mapnik.Datasource mapnik.Feature mapnik.Featureset mapnik.Geometry mapnik.Grid mapnik.Image mapnik.ImageView mapnik.Map mapnik.Projection mapnik.VectorTile
/src/mapnik_map.cpp

add_layer(new)

Add a new layer to this map

Parameters

param type = default description
new mapnik.Layer

layer

/src/mapnik_map.cpp

clear

Remove all layers and styles from this map

/src/mapnik_map.cpp

clone

Clone this map object, returning a value which can be changed without mutating the original

Returns

mapnik.Map :

clone

/src/mapnik_map.cpp

font

Get all of the fonts currently registered as part of this map

/src/mapnik_map.cpp

fontDirectory

Get the currently-registered font directory, if any

Returns

( string | undefined ) :

fonts

/src/mapnik_map.cpp

fontFiles

Get all of the fonts currently registered as part of this map, as a mapping from font to font file

Returns

Object :

fonts

/src/mapnik_map.cpp

fromStringSync(stylesheet, [options], callback)

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

Parameters

param type = default description
stylesheet string

contents

options Object = ({})
callback Function

Example

var fs = require('fs');
map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'), function(err, res) {
  // details loaded
});
/src/mapnik_map.cpp

fromStringSync(stylesheet, [options])

Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.

Parameters

param type = default description
stylesheet string

contents

options Object = ({})

Example

var fs = require('fs');
map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'));
/src/mapnik_map.cpp

get_layer(layer)

Get a layer out of this map, given a name or index

Parameters

param type = default description
layer ( string | number )

name or index

Returns

mapnik.Layer :

the layer

Throws

  • Error :

    if index is incorrect or layer is not found

/src/mapnik_map.cpp

layers

Get all of the currently-added layers in this map

/src/mapnik_map.cpp

load(stylesheet, [options], callback)

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

Parameters

param type = default description
stylesheet string

path

options Object = ({})
callback Function
/src/mapnik_map.cpp

loadSync(stylesheet, [options])

Load styles, layers, and other information for this map from a Mapnik XML stylesheet.

Parameters

param type = default description
stylesheet string

path

options Object = ({})

Example

map.loadSync('./style.xml');
/src/mapnik_map.cpp

resize(width, height)

Give this map new dimensions

Parameters

param type = default description
width number
height number
/src/mapnik_map.cpp

scale

Get the map's scale factor. This is the ratio between pixels and geographical units like meters.

Returns

number :

scale

/src/mapnik_map.cpp

scaleDenominator

Get the map's scale denominator.

Returns

number :

scale denominator

/src/mapnik_vector_tile.cpp

addData(raw, name)

Add raw data to this tile as a Buffer

Parameters

param type = default description
raw Buffer

data

name string

of the layer to be added

/src/mapnik_vector_tile.cpp

addGeoJSON(geojson, name)

Add features to this tile from a GeoJSON string

Parameters

param type = default description
geojson string

as a string

name string

of the layer to be added

/src/mapnik_vector_tile.cpp

clear(callback)

Remove all data from this vector tile

Parameters

param type = default description
callback Function
/src/mapnik_vector_tile.cpp

compositeSync

Composite an array of vector tiles into one vector tile

/src/mapnik_vector_tile.cpp

empty(whether)

Return whether this vector tile is empty - whether it has no layers and no features

Parameters

param type = default description
whether boolean

the layer is empty

/src/mapnik_vector_tile.cpp

getData(map, renderable, callback)

Render this vector tile to a surface, like a mapnik.Image

Parameters

param type = default description
map mapnik.Map

object

renderable mapnik.Image

surface

callback Function
/src/mapnik_vector_tile.cpp

getDataSync

Get the data in this vector tile as a buffer

Returns

Buffer :

raw data

/src/mapnik_vector_tile.cpp

height(height)

Get the vector tile's height

Parameters

param type = default description
height number
/src/mapnik_vector_tile.cpp

isSolid(callback)

Test whether this tile is solid - whether it has features

Parameters

param type = default description
callback Function
/src/mapnik_vector_tile.cpp

isSolidSync

Test whether this tile is solid - whether it has features

Returns

boolean :

whether the tile is solid

/src/mapnik_vector_tile.cpp

names

Get the names of all of the layers in this vector tile

/src/mapnik_vector_tile.cpp

painted(painted)

Get whether the vector tile has been painted

Parameters

param type = default description
painted boolean
/src/mapnik_vector_tile.cpp

query(longitude, latitude, [options], callback)

Query a vector tile by longitude and latitude

Parameters

param type = default description
longitude number
latitude number
options Object = ({tolerance:0})

tolerance: allow results that are not exactly on this longitude, latitude position.

callback Function
/src/mapnik_vector_tile.cpp

reportGeometrySimplicity(callback)

Count the number of non OGC simple geometries

Parameters

param type = default description
callback Function
/src/mapnik_vector_tile.cpp

reportGeometrySimplicitySync

Count the number of geometries that are not OGC simple

Returns

number :

number of features that are not simple

/src/mapnik_vector_tile.cpp

reportGeometryValidity(callback)

Count the number of non OGC valid geometries

Parameters

param type = default description
callback Function
/src/mapnik_vector_tile.cpp

reportGeometryValiditySync

Count the number of geometries that are not OGC valid

Returns

number :

number of features that are not valid

/src/mapnik_vector_tile.cpp

setData(raw, name)

Replace the data in this vector tile with new raw data

Parameters

param type = default description
raw Buffer

data

name string

of the layer to be added

/src/mapnik_vector_tile.cpp

toGeoJSON(callback)

Get a GeoJSON representation of this tile

Parameters

param type = default description
callback Function

Returns

string :

stringified GeoJSON of all the features in this tile.

/src/mapnik_vector_tile.cpp

toGeoJSONSync

Get a GeoJSON representation of this tile

Returns

string :

stringified GeoJSON of all the features in this tile.

/src/mapnik_vector_tile.cpp

toJSON

Get a JSON representation of this tile

Returns

Object :

json representation of this tile with name, extent, and version properties

/src/mapnik_vector_tile.cpp

width(width)

Get the vector tile's width

Parameters

param type = default description
width number
/src/mapnik_grid.cpp

addField(field)

Add a field to this grid's output

Parameters

param type = default description
field string
/src/mapnik_grid.cpp

addField

Get all of this grid's fields

/src/mapnik_grid.cpp

encodeSync([options])

Get a constrained view of this field given x, y, width, height parameters.

Parameters

param type = default description
options Object = ({resolution:4,features:false})

Returns

Object :

an encoded field with grid, keys, and data members.

/src/mapnik_grid.cpp

height

Get this grid's height

Returns

number :

height

/src/mapnik_grid.cpp

view(x, y, width, height)

Get a constrained view of this field given x, y, width, height parameters.

Parameters

param type = default description
x number
y number
width number
height number

Returns

mapnik.Grid :

a grid constrained to this new view

/src/mapnik_grid.cpp

width

Get this grid's width

Returns

number :

width

/src/mapnik_feature.cpp

attributes

Get the feature's attributes as an object.

Returns

Object :

attributes

/src/mapnik_feature.cpp

extent

Get the feature's extent

/src/mapnik_feature.cpp

geometry

Get the feature's attributes as a Mapnik geometry.

Returns

mapnik.Geometry :

geometry

/src/mapnik_feature.cpp

id

Returns

number :

id the feature's internal id

/src/mapnik_feature.cpp

toJSON

Generate and return a GeoJSON representation of this feature

Returns

string :

geojson Feature object in stringified GeoJSON

/src/mapnik_feature.cpp

fromJSON(geojson)

Parameters

param type = default description
geojson string

string

Create a feature from a GeoJSON representation.

/src/mapnik_image.cpp

clear(callback)

Make this image transparent, removing all image data from it.

Parameters

param type = default description
callback Function
/src/mapnik_image.cpp

clearSync

Make this image transparent.

Example

var im = new mapnik.Image(5,5);
im.fillSync(1);
assert.equal(im.getPixel(0, 0), 1);
im.clearSync();
assert.equal(im.getPixel(0, 0), 0);
/src/mapnik_image.cpp

compare(other, [options])

Compare two images visually. This is useful for algorithms and tests that confirm whether a certain image has changed significantly.

Parameters

param type = default description
other mapnik.Image

another image instance

options Object = ({threshold:16,alpha:true})

Returns

number :

quantified visual difference between these two images

/src/mapnik_image.cpp

composite(other, callback)

Overlay this image with another image, creating a layered composite as a new image

Parameters

param type = default description
other mapnik.Image
callback Function
/src/mapnik_image.cpp

copy(type, [options], callback)

Copy this image data so that changes can be made to a clone of it.

Parameters

param type = default description
type number
options Object = ({})
callback Function
/src/mapnik_image.cpp

copySync(type, [options])

Copy this image data so that changes can be made to a clone of it.

Parameters

param type = default description
type number
options Object = ({})

Returns

mapnik.Image :

copy

/src/mapnik_image.cpp

data

Return a copy of the pixel data in this image as a buffer

/src/mapnik_image.cpp

demultiply(callback)

Demultiply the pixels in this image, asynchronously. The opposite of premultiplying

Parameters

param type = default description
callback Function
/src/mapnik_image.cpp

demultiplySync

Demultiply the pixels in this image. The opposite of premultiplying

/src/mapnik_image.cpp

encode([format], callback)

Encode this image into a buffer of encoded data

Parameters

param type = default description
format string = (png)

image format

callback Function

Returns

Buffer :

encoded image data

Example

var fs = require('fs');
myImage.encode('png', function(err, encoded) {
  fs.writeFileSync('myimage.png', encoded);
});
/src/mapnik_image.cpp

encodeSync([format])

Encode this image into a buffer of encoded data

Parameters

param type = default description
format string = (png)

image format

Returns

Buffer :

encoded image data

Example

var fs = require('fs');
fs.writeFileSync('myimage.png', myImage.encodeSync('png'));
/src/mapnik_image.cpp

fill(color, callback)

Asynchronously fill this image with a given color.

Parameters

param type = default description
color ( mapnik.Color | number )
callback Function

Example

var im = new mapnik.Image(5, 5);
im.fill(1, function(err, im_res) {
  if (err) throw err;
  assert.equal(im_res.getPixel(0, 0), 1);
});
/src/mapnik_image.cpp

fillSync(color)

Fill this image with a given color

Parameters

param type = default description
color ( mapnik.Color | number )
/src/mapnik_image.cpp

filter(filter, callback)

Asynchronously filter this image.

Parameters

param type = default description
filter string
callback Function

Example

var im = new mapnik.Image(5, 5);
im.filter("blur", function(err, im_res) {
  if (err) throw err;
  assert.equal(im_res.getPixel(0, 0), 1);
});
/src/mapnik_image.cpp

filterSync(filter)

Filter this image

Parameters

param type = default description
filter string
/src/mapnik_image.cpp

getPixel(x, y, options)

Parameters

param type = default description
x number

position within image from top left

y number

position within image from top left

options Object

the only valid option is get_color, which should be a boolean.

Returns

number :

color

Example

var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);
var pixel = view.getPixel(0, 0, {get_color:true});
assert.equal(pixel.r, 0);
assert.equal(pixel.g, 0);
assert.equal(pixel.b, 0);
assert.equal(pixel.a, 0);
/src/mapnik_image.cpp

getType

Determine the image type

Returns

number :

Number of the image type

/src/mapnik_image.cpp

height

Get this image's height

Returns

number :

height

/src/mapnik_image.cpp

isSolidSync

Determine whether the image is solid - whether it has alpha values of greater than one.

Returns

boolean :

whether the image is solid

Example

var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);
assert.equal(view.isSolidSync(), true);
/src/mapnik_image.cpp

premultiplied

Determine whether the given image is premultiplied.

Returns

boolean :

premultiplied true if the image is premultiplied

/src/mapnik_image.cpp

premultiply(callback)

Premultiply the pixels in this image, asynchronously

Parameters

param type = default description
callback Function
/src/mapnik_image.cpp

premultiplySync

Premultiply the pixels in this image

/src/mapnik_image.cpp

resize(width, height, [options], callback)

Create a copy this image that is resized

Parameters

param type = default description
width number
height number
options Object = ({})
callback Function
/src/mapnik_image.cpp

resizeSync(width, height, [options])

Make a resized copy of an image

Parameters

param type = default description
width number
height number
options Object = ({})

Returns

mapnik.Image :

copy

/src/mapnik_image.cpp

save(filename, [format], callback)

Encode this image and save it to disk as a file.

Parameters

param type = default description
filename string
format string = (png)
callback Function
/src/mapnik_image.cpp

saveSync(filename, [format])

Encode this image and save it to disk as a file.

Parameters

param type = default description
filename string
format string = (png)

Example

myImage.saveSync('foo.png');
/src/mapnik_image.cpp

setPixel(x, y, numeric)

Parameters

param type = default description
x number

position within image from top left

y number

position within image from top left

numeric ( Object | number )

or object representation of a color

/src/mapnik_image.cpp

view(x, y, width, height)

Get a constrained view of this image given x, y, width, height parameters.

Parameters

param type = default description
x number
y number
width number
height number

Returns

mapnik.Image :

an image constrained to this new view

/src/mapnik_image.cpp

width

Get this image's width

Returns

number :

width

/src/mapnik_image.cpp

fromBufferSync(width, height, buffer)

Create an image of the existing buffer. BUFFER MUST LIVE AS LONG AS THE IMAGE. It is recommended that you do not use this method! Be warned!

Parameters

param type = default description
width number
height number
buffer Buffer

Returns

mapnik.Image :

image object

/src/mapnik_image.cpp

fromBytes(buffer, callback)

Create a new image from a buffer

Parameters

param type = default description
buffer Buffer
callback Function
/src/mapnik_image.cpp

fromSVG(filename, callback)

Create a new image from an SVG file

Parameters

param type = default description
filename String
callback Function
/src/mapnik_image.cpp

fromSVGBytes(filename, callback)

Create a new image from an SVG file

Parameters

param type = default description
filename String
callback Function
/src/mapnik_datasource.cpp

describe

Describe the datasource's contents and type.

Returns

Object :

description: an object with type, fields, encoding, geometry_type, and proj4 code

/src/mapnik_datasource.cpp

extent

Get the Datasource's extent

/src/mapnik_geometry.cpp

extent

Get the geometry's extent

/src/mapnik_geometry.cpp

toJSON([options], callback)

Convert this geometry into a GeoJSON representation, asynchronously.

Parameters

param type = default description
options Object = ({})

. The only supported object is transform, which should be a valid mapnik.ProjTransform object.

callback Function

called with (err, result)

/src/mapnik_geometry.cpp

toJSONSync

Convert this geometry into a GeoJSON representation, synchronously.

Returns

string :

GeoJSON, string-encoded representation of this geometry.

/src/mapnik_geometry.cpp

toWKB

Get the geometry's representation as Well-Known Binary

Returns

string :

wkb representation of this geometry

/src/mapnik_geometry.cpp

toWKT

Get the geometry's representation as Well-Known Text

Returns

string :

wkt representation of this geometry

/src/mapnik_geometry.cpp

type

Get the geometry type

Returns

string :

type of geometry.

/src/mapnik_projection.cpp

forward

Project from a position in WGS84 space to a position in this projection.

Example

var merc = new mapnik.Projection('+init=epsg:3857');
var long_lat_coords = [-122.33517, 47.63752];
var projected = merc.forward(long_lat_coords);
/src/mapnik_projection.cpp

inverse

Unproject from a position in this projection to the same position in WGS84 space.

/src/mapnik_color.cpp

get_premultiplied

Get whether this color is premultiplied

Returns

boolean :

premultiplied

/src/mapnik_color.cpp

hex

Get this color represented as a hexademical string

Returns

string :

hex representation

Example

var c = new mapnik.Color('green');
c.hex();
// '#008000'
/src/mapnik_color.cpp

set_premultiplied(premultiplied)

Set whether this color should be premultiplied

Parameters

param type = default description
premultiplied boolean

Throws

Example

var c = new mapnik.Color('green');
c.set_premultiplied(true);
/src/mapnik_color.cpp

toString

Get this color's representation as a string

Returns

string :

color as a string

Example

var green = new mapnik.Color('green');
green.toString()
// 'rgb(0,128,0)'
/src/mapnik_featureset.cpp

next

Return the next Feature in this featureset if it exists, or null if it does not.

Returns

( mapnik.Feature | null ) :

next feature

/src/node_mapnik.cpp

mapnik

Mapnik is the core of cartographic design and processing.

Properties

prop type = default description
version string

current version of mapnik

module_path string

path to native mapnik binding

supports Object

indicates which of the following are supported: grid, svg, cairo, cairo_pdf, cairo_svg, png, jpeg, tiff, webp, proj4, threadsafe

versions Object

diagnostic object with versions of node, v8, boost, boost_number, mapnik, mapnik_number, mapnik_git_describe, cairo

Example

var mapnik = require('node-mapnik');

Static members

.compositeOp
/src/node_mapnik.cpp

compositeOp

Image type constants representing color and grayscale encodings. Composite operation constants

Properties

prop type = default description
clear number
src number
dst number
src_over number
dst_over number
src_in number
dst_in number
src_out number
dst_out number
src_atop number
dst_atop number
xor number
plus number
minus number
multiply number
screen number
overlay number
darken number
lighten number
color_dodge number
color_burn number
hard_light number
soft_light number
difference number
exclusion number
contrast number
invert number
invert-rgb number
grain_merge number
grain_extract number
hue number
saturation number
color number
linear_dodge number
linear_burn number
divide number
.imageScaling
/src/node_mapnik.cpp

imageScaling

Image scaling type constants representing color and grayscale encodings.

Properties

prop type = default description
near number
bilinear number
bicubic number
spline16 number
spline36 number
hanning number
hamming number
hermite number
kaiser number
quadric number
catrom number
gaussian number
bessel number
mitchell number
sinc number
lanczos number
blackman number
.imageType
/src/node_mapnik.cpp

imageType

Image type constants representing color and grayscale encodings.

Properties

prop type = default description
rgba8 number
gray8 number
gray8s number
gray16 number
gray16s number
gray32 number
gray32s number
gray32f number
gray64 number
gray64s number
gray64f number
.polygonFillType
/src/node_mapnik.cpp

polygonFillType

Image scaling type constants representing color and grayscale encodings.

Properties

prop type = default description
evenOdd number
nonZero number
positive number
negative number
/src/blend.cpp

mapnik.blend(options, callback)

Composite multiple images on top of each other, with strong control over how the images are combined, resampled, and blended.

Parameters

param type = default description
options Object

can include width, height, compression, reencode, palette, mode can be either hextree or octree, quality. JPEG & WebP quality quality ranges from 0-100, PNG quality from 2-256. Compression varies by platform - it references the internal zlib compression algorithm.

callback Function

called with (err, res), where a successful result is a processed image as a Buffer

Example

mapnik.blend([
 fs.readFileSync('foo.png'),
 fs.readFileSync('bar.png'),
], function(err, result) {
 if (err) throw err;
 fs.writeFileSync('result.png', result);
});
/src/mapnik_color.cpp

mapnik.Color(value, green, blue, blue, premultiplied)

Parameters

param type = default description
value ( string | number )

either an array of [r, g, b, a], a color keyword, or a CSS color in rgba() form.

green number
blue number
blue number
premultiplied boolean

Throws

  • TypeError :

    if a rgb component is outside of the 0-255 range

Example

var c = new mapnik.Color('green');
var c = new mapnik.Color(0, 128, 0, 255);
// premultiplied
var c = new mapnik.Color(0, 128, 0, 255, true);
/src/mapnik_datasource.cpp

mapnik.Datasource

A Datasource object. This is the connector from Mapnik to any kind of file, network, or database source of geographical data.

/src/mapnik_feature.cpp

mapnik.Feature

A single geographic feature, with geometry and properties. This is typically derived from data by a datasource, but can be manually created.

/src/mapnik_featureset.cpp

mapnik.Featureset

An iterator of mapnik.Feature objects.

/src/mapnik_geometry.cpp

mapnik.Geometry

Geometry: a representation of geographical features in terms of shape alone. This class provides many useful functions for conversion to and from formats.

You'll never create a mapnik.Geometry instance manually: it is always part of a mapnik.Feature instance, which is often a part of a mapnik.Featureset instance.

/src/mapnik_grid.cpp

mapnik.Grid(width, height, [options])

Generator for UTFGrid representations of data.

Parameters

param type = default description
width number
height number
options Object = ({})

optional argument, which can have a 'key' property

Properties

prop type = default description
key string
/src/mapnik_image.cpp

mapnik.Image(width, height, options)

Parameters

param type = default description
width number
height number
options Object

valid options are premultiplied, painted, type and initialize.

Throws

  • TypeError :

    if any argument is the wrong type, like if width or height is not numeric.

Example

var im = new mapnik.Image(256, 256, {
  premultiplied: true,
  type: mapnik.imageType.gray8
});
/src/mapnik_image_view.cpp

mapnik.ImageView(left, top, width, height)

This is usually not initialized directly: you'll use the mapnik.Image#view method to instantiate an instance.

Parameters

param type = default description
left number
top number
width number
height number

Throws

  • TypeError :

    if any argument is missing or not numeric

Example

var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);
/src/mapnik_map.cpp

mapnik.Map(width, width, projection)

A map in mapnik is an object that combined data sources and styles in a way that lets you produce styled cartographic output.

Parameters

param type = default description
width number
width number
projection string

as a proj4 code

Example

var map = new mapnik.Map(25, 25, '+init=epsg:3857');
/src/mapnik_projection.cpp

mapnik.Projection(projection, [options])

A geographical projection: this class makes it possible to translate between locations in different projections

Parameters

param type = default description
projection string

projection as a proj4 definition string

options Object = ({lazy:false})

whether to lazily instantiate the data backing this projection.

Throws

  • TypeError :

    if the projection string or options argument is the wrong type

  • Error :

    the projection could not be initialized - it was not found in proj4's tables or the string was malformed

Example

var wgs84 = new mapnik.Projection('+init=epsg:4326');
/src/mapnik_vector_tile.cpp

mapnik.VectorTile(z, x, y)

A generator for the Mapbox Vector Tile specification of compressed and simplified tiled vector data

Parameters

param type = default description
z number
x number
y number

Example

var vtile = new mapnik.VectorTile(9,112,195);