Mapnik is the core of cartographic design and processing.
string
version
:
current version of mapnik
string
module_path
:
path to native mapnik binding
Object
supports
:
indicates which of the following are supported: grid, svg, cairo, cairo_pdf, cairo_svg, png, jpeg, tiff, webp, proj4, threadsafe
Object
versions
:
diagnostic object with versions of node, v8, boost, boost_number, mapnik, mapnik_number, mapnik_git_describe, cairo
var mapnik = require('node-mapnik');
.compositeOp
Image type constants representing color and grayscale encodings. Composite operation constants
Image type constants representing color and grayscale encodings. Composite operation constants
number
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
.imageScaling
Image scaling type constants representing color and grayscale encodings.
Image scaling type constants representing color and grayscale encodings.
.polygonFillType
Image scaling type constants representing color and grayscale encodings.
Image scaling type constants representing color and grayscale encodings.
string
or number
value
:
either an array of [r, g, b, a], a color keyword, or a CSS color in rgba() form.
number
green
:
number
blue
:
number
blue
:
boolean
premultiplied
:
TypeError
: if a rgb component is outside of the 0-255 range
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);
#get_premultiplied
Get whether this color is premultiplied
Get whether this color is premultiplied
boolean
:
premultiplied
#hex
Get this color represented as a hexademical string
Get this color represented as a hexademical string
string
:
hex representation
var c = new mapnik.Color('green');
c.hex();
// '#008000'
#set_premultiplied(premultiplied)
Set whether this color should be premultiplied
#toString
Get this color's representation as a string
Get this color's representation as a string
string
:
color as a string
var green = new mapnik.Color('green');
green.toString()
// 'rgb(0,128,0)'
A Datasource object. This is the connector from Mapnik to any kind of file, network, or database source of geographical data.
#describe
Describe the datasource's contents and type.
Describe the datasource's contents and type.
Object
:
description: an object with type, fields, encoding, geometry_type, and proj4 code
#extent
Get the Datasource's extent
Get the Datasource's extent
A single geographic feature, with geometry and properties. This is typically derived from data by a datasource, but can be manually created.
.fromJSON(geojson)
string
geojson
:
string
Create a feature from a GeoJSON representation.
#attributes
Get the feature's attributes as an object.
Get the feature's attributes as an object.
Object
:
attributes
#extent
Get the feature's extent
Get the feature's extent
#geometry
Get the feature's attributes as a Mapnik geometry.
Get the feature's attributes as a Mapnik geometry.
mapnik.Geometry
:
geometry
#toJSON
Generate and return a GeoJSON representation of this feature
Generate and return a GeoJSON representation of this feature
string
:
geojson Feature object in stringified GeoJSON
An iterator of mapnik.Feature
objects.
#next
Return the next Feature in this featureset if it exists, or null
if it
does not.
Return the next Feature in this featureset if it exists, or null
if it
does not.
mapnik.Feature
or
:
next feature
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.
#extent
Get the geometry's extent
Get the geometry's extent
#toJSON([options], callback)
Convert this geometry into a GeoJSON representation, asynchronously.
Convert this geometry into a GeoJSON representation, asynchronously.
[Object
]
options
(default {}
)
:
. The only supported object is transform
,
which should be a valid mapnik.ProjTransform
object.
Function
callback
:
called with (err, result)
#toJSONSync
Convert this geometry into a GeoJSON representation, synchronously.
#toWKB
Get the geometry's representation as Well-Known Binary
Get the geometry's representation as Well-Known Binary
string
:
wkb representation of this geometry
#toWKT
Get the geometry's representation as Well-Known Text
Get the geometry's representation as Well-Known Text
string
:
wkt representation of this geometry
Generator for UTFGrid representations of data.
number
width
:
number
height
:
[Object
]
options
(default {}
)
:
optional argument, which can have a 'key' property
string
key
#addField
Get all of this grid's fields
Get all of this grid's fields
#addField(field)
Add a field to this grid's output
Add a field to this grid's output
string
field
:
#encodeSync([options])
Get a constrained view of this field given x, y, width, height parameters.
#height
Get this grid's height
Get this grid's height
number
:
height
#view(x, y, width, height)
Get a constrained view of this field given x, y, width, height parameters.
Get a constrained view of this field given x, y, width, height parameters.
mapnik.Grid
:
a grid constrained to this new view
#width
Get this grid's width
Get this grid's width
number
:
width
number
width
:
number
height
:
Object
options
:
valid options are premultiplied
, painted
,
type
and initialize
.
TypeError
: if any argument is the wrong type, like if width or height is not numeric.
var im = new mapnik.Image(256, 256, {
premultiplied: true,
type: mapnik.imageType.gray8
});
.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!
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!
mapnik.Image
:
image object
.fromBytes(buffer, callback)
Create a new image from a buffer
Create a new image from a buffer
.fromSVG(filename, callback)
Create a new image from an SVG file
Create a new image from an SVG file
.fromSVGBytes(filename, callback)
Create a new image from an SVG file
Create a new image from an SVG file
#clear(callback)
Make this image transparent, removing all image data from it.
Make this image transparent, removing all image data from it.
Function
callback
:
#clearSync
Make this image transparent.
Make this image transparent.
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);
#compare(other, [options])
Compare two images visually. This is useful for algorithms and tests that confirm whether a certain image has changed significantly.
Compare two images visually. This is useful for algorithms and tests that confirm whether a certain image has changed significantly.
mapnik.Image
other
:
another image instance
[Object
]
options
(default {threshold:16,alpha:true}
)
:
number
:
quantified visual difference between these two images
#composite(other, callback)
Overlay this image with another image, creating a layered composite as a new image
Overlay this image with another image, creating a layered composite as a new image
mapnik.Image
other
:
Function
callback
:
#copy(type, [options], callback)
Copy this image data so that changes can be made to a clone of it.
Copy this image data so that changes can be made to a clone of it.
#copySync(type, [options])
Copy this image data so that changes can be made to a clone of it.
Copy this image data so that changes can be made to a clone of it.
mapnik.Image
:
copy
#demultiply(callback)
Demultiply the pixels in this image, asynchronously. The opposite of premultiplying
Demultiply the pixels in this image, asynchronously. The opposite of premultiplying
Function
callback
:
#demultiplySync
Demultiply the pixels in this image. The opposite of premultiplying
Demultiply the pixels in this image. The opposite of premultiplying
#encode([format], callback)
Encode this image into a buffer of encoded data
Encode this image into a buffer of encoded data
Buffer
:
encoded image data
var fs = require('fs');
myImage.encode('png', function(err, encoded) {
fs.writeFileSync('myimage.png', encoded);
});
#encodeSync([format])
Encode this image into a buffer of encoded data
#fill(color, callback)
Asynchronously fill this image with a given color.
Asynchronously fill this image with a given color.
mapnik.Color
or number
color
:
Function
callback
:
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);
});
#fillSync(color)
Fill this image with a given color
Fill this image with a given color
mapnik.Color
or number
color
:
#filter(filter, callback)
Asynchronously filter this image.
Asynchronously filter this image.
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);
});
#filterSync(filter)
Filter this image
Filter this image
string
filter
:
#getPixel(x, y, options)
number
x
:
position within image from top left
number
y
:
position within image from top left
Object
options
:
the only valid option is get_color
, which
should be a boolean
.
number
:
color
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);
#getType
Determine the image type
Determine the image type
number
:
Number of the image type
#height
Get this image's height
Get this image's height
number
:
height
#isSolidSync
Determine whether the image is solid - whether it has alpha values of greater than one.
Determine whether the image is solid - whether it has alpha values of greater than one.
boolean
:
whether the image is solid
var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);
assert.equal(view.isSolidSync(), true);
#premultiplied
Determine whether the given image is premultiplied.
Determine whether the given image is premultiplied.
boolean
:
premultiplied true if the image is premultiplied
#premultiply(callback)
Premultiply the pixels in this image, asynchronously
Premultiply the pixels in this image, asynchronously
Function
callback
:
#premultiplySync
Premultiply the pixels in this image
Premultiply the pixels in this image
#resize(width, height, [options], callback)
Create a copy this image that is resized
Create a copy this image that is resized
#resizeSync(width, height, [options])
Make a resized copy of an image
Make a resized copy of an image
mapnik.Image
:
copy
#save(filename, [format], callback)
Encode this image and save it to disk as a file.
Encode this image and save it to disk as a file.
#saveSync(filename, [format])
Encode this image and save it to disk as a file.
Encode this image and save it to disk as a file.
myImage.saveSync('foo.png');
#setPixel(x, y, numeric)
#view(x, y, width, height)
Get a constrained view of this image given x, y, width, height parameters.
Get a constrained view of this image given x, y, width, height parameters.
mapnik.Image
:
an image constrained to this new view
#width
Get this image's width
Get this image's width
number
:
width
This is usually not initialized directly: you'll use the mapnik.Image#view
method to instantiate an instance.
TypeError
: if any argument is missing or not numeric
var im = new mapnik.Image(256, 256);
var view = im.view(0, 0, 256, 256);
A map in mapnik is an object that combined data sources and styles in a way that lets you produce styled cartographic output.
var map = new mapnik.Map(25, 25, '+init=epsg:3857');
#add_layer(new)
Add a new layer to this map
Add a new layer to this map
mapnik.Layer
new
:
layer
#clear
Remove all layers and styles from this map
Remove all layers and styles from this map
#clone
Clone this map object, returning a value which can be changed without mutating the original
Clone this map object, returning a value which can be changed without mutating the original
mapnik.Map
:
clone
#font
Get all of the fonts currently registered as part of this map
Get all of the fonts currently registered as part of this map
#fontDirectory
Get the currently-registered font directory, if any
Get the currently-registered font directory, if any
string
or
:
fonts
#fontFiles
Get all of the fonts currently registered as part of this map, as a mapping from font to font file
Get all of the fonts currently registered as part of this map, as a mapping from font to font file
Object
:
fonts
#fromStringSync(stylesheet, [options], callback)
Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.
Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.
var fs = require('fs');
map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'), function(err, res) {
// details loaded
});
#fromStringSync(stylesheet, [options])
Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.
Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.
var fs = require('fs');
map.fromStringSync(fs.readFileSync('./style.xml', 'utf8'));
#get_layer(layer)
Get a layer out of this map, given a name or index
Get a layer out of this map, given a name or index
mapnik.Layer
:
the layer
Error
: if index is incorrect or layer is not found
#layers
Get all of the currently-added layers in this map
Get all of the currently-added layers in this map
#load(stylesheet, [options], callback)
Load styles, layers, and other information for this map from a Mapnik XML stylesheet.
Load styles, layers, and other information for this map from a Mapnik XML stylesheet.
#loadSync(stylesheet, [options])
Load styles, layers, and other information for this map from a Mapnik XML stylesheet.
Load styles, layers, and other information for this map from a Mapnik XML stylesheet.
map.loadSync('./style.xml');
#resize(width, height)
Give this map new dimensions
Give this map new dimensions
#scale
Get the map's scale factor. This is the ratio between pixels and geographical units like meters.
Get the map's scale factor. This is the ratio between pixels and geographical units like meters.
number
:
scale
#scaleDenominator
Get the map's scale denominator.
Get the map's scale denominator.
number
:
scale denominator
A geographical projection: this class makes it possible to translate between locations in different projections
string
projection
:
projection as a proj4 definition string
[Object
]
options
(default {lazy:false}
)
:
whether to lazily instantiate the data backing this projection.
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
var wgs84 = new mapnik.Projection('+init=epsg:4326');
#forward
Project from a position in WGS84 space to a position in this projection.
Project from a position in WGS84 space to a position in this projection.
#inverse
Unproject from a position in this projection to the same position in WGS84 space.
Unproject from a position in this projection to the same position in WGS84 space.
A generator for the Mapbox Vector Tile specification of compressed and simplified tiled vector data
var vtile = new mapnik.VectorTile(9,112,195);
#addData(raw, name)
Add raw data to this tile as a Buffer
Add raw data to this tile as a Buffer
#addGeoJSON(geojson, name)
Add features to this tile from a GeoJSON string
Add features to this tile from a GeoJSON string
#clear(callback)
Remove all data from this vector tile
Remove all data from this vector tile
Function
callback
:
#compositeSync
Composite an array of vector tiles into one vector tile
Composite an array of vector tiles into one vector tile
#empty(whether)
Return whether this vector tile is empty - whether it has no layers and no features
Return whether this vector tile is empty - whether it has no layers and no features
boolean
whether
:
the layer is empty
#getData(map, renderable, callback)
Render this vector tile to a surface, like a mapnik.Image
Render this vector tile to a surface, like a mapnik.Image
mapnik.Map
map
:
object
mapnik.Image
renderable
:
surface
Function
callback
:
#getDataSync
Get the data in this vector tile as a buffer
Get the data in this vector tile as a buffer
Buffer
:
raw data
#height(height)
Get the vector tile's height
Get the vector tile's height
number
height
:
#isSolid(callback)
Test whether this tile is solid - whether it has features
Test whether this tile is solid - whether it has features
Function
callback
:
#isSolidSync
Test whether this tile is solid - whether it has features
Test whether this tile is solid - whether it has features
boolean
:
whether the tile is solid
#names
Get the names of all of the layers in this vector tile
Get the names of all of the layers in this vector tile
#painted(painted)
Get whether the vector tile has been painted
Get whether the vector tile has been painted
boolean
painted
:
#query(longitude, latitude, [options], callback)
Query a vector tile by longitude and latitude
Query a vector tile by longitude and latitude
#reportGeometrySimplicity(callback)
Count the number of non OGC simple geometries
Count the number of non OGC simple geometries
Function
callback
:
#reportGeometrySimplicitySync
Count the number of geometries that are not OGC simple
Count the number of geometries that are not OGC simple
number
:
number of features that are not simple
#reportGeometryValidity(callback)
Count the number of non OGC valid geometries
Count the number of non OGC valid geometries
Function
callback
:
#reportGeometryValiditySync
Count the number of geometries that are not OGC valid
Count the number of geometries that are not OGC valid
number
:
number of features that are not valid
#setData(raw, name)
Replace the data in this vector tile with new raw data
Replace the data in this vector tile with new raw data
#toGeoJSON(callback)
Get a GeoJSON representation of this tile
#toGeoJSONSync
Get a GeoJSON representation of this tile
#toJSON
Get a JSON representation of this tile
Get a JSON representation of this tile
Object
:
json representation of this tile with name, extent, and version properties
#width(width)
Get the vector tile's width
Get the vector tile's width
number
width
:
Composite multiple images on top of each other, with strong control over how the images are combined, resampled, and blended.