add_layer(new)
Add a new layer to this map
Parameters
param | type = default | description |
---|---|---|
new | mapnik.Layer | layer |
clear
Remove all layers and styles from this map
clone
Clone this map object, returning a value which can be changed without mutating the original
Returns
mapnik.Map
:
clone
font
Get all of the fonts currently registered as part of this map
fontDirectory
Get the currently-registered font directory, if any
Returns
(
string
|
undefined
)
:
fonts
fontFiles
Get all of the fonts currently registered as part of this map, as a mapping from font to font file
Returns
Object
:
fonts
fromStringSync(stylesheet, [options], callback)
Load styles, layers, and other information for this map from a Mapnik XML stylesheet given as a string.
Parameters
Example
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.
Parameters
Example
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
Parameters
Returns
mapnik.Layer
:
the layer
Throws
- Error
:
if index is incorrect or layer is not found
layers
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.
Parameters
loadSync(stylesheet, [options])
Load styles, layers, and other information for this map from a Mapnik XML stylesheet.
Parameters
Example
map.loadSync('./style.xml');
resize(width, height)
Give this map new dimensions
Parameters
scale
Get the map's scale factor. This is the ratio between pixels and geographical units like meters.
Returns
number
:
scale
scaleDenominator
Get the map's scale denominator.
Returns
number
:
scale denominator
addData(raw, name)
Add raw data to this tile as a Buffer
Parameters
addGeoJSON(geojson, name)
Add features to this tile from a GeoJSON string
Parameters
clear(callback)
Remove all data from this vector tile
Parameters
param | type = default | description |
---|---|---|
callback | Function |
compositeSync
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
Parameters
param | type = default | description |
---|---|---|
whether | boolean | the layer is empty |
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 |
getDataSync
Get the data in this vector tile as a buffer
Returns
Buffer
:
raw data
height(height)
Get the vector tile's height
Parameters
param | type = default | description |
---|---|---|
height | number |
isSolid(callback)
Test whether this tile is solid - whether it has features
Parameters
param | type = default | description |
---|---|---|
callback | Function |
isSolidSync
Test whether this tile is solid - whether it has features
Returns
boolean
:
whether the tile is solid
names
Get the names of all of the layers in this vector tile
painted(painted)
Get whether the vector tile has been painted
Parameters
param | type = default | description |
---|---|---|
painted | boolean |
query(longitude, latitude, [options], callback)
Query a vector tile by longitude and latitude
Parameters
reportGeometrySimplicity(callback)
Count the number of non OGC simple geometries
Parameters
param | type = default | description |
---|---|---|
callback | Function |
reportGeometrySimplicitySync
Count the number of geometries that are not OGC simple
Returns
number
:
number of features that are not simple
reportGeometryValidity(callback)
Count the number of non OGC valid geometries
Parameters
param | type = default | description |
---|---|---|
callback | Function |
reportGeometryValiditySync
Count the number of geometries that are not OGC valid
Returns
number
:
number of features that are not valid
setData(raw, name)
Replace the data in this vector tile with new raw data
Parameters
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.
toGeoJSONSync
Get a GeoJSON representation of this tile
Returns
string
:
stringified GeoJSON of all the features in this tile.
toJSON
Get a JSON representation of this tile
Returns
Object
:
json representation of this tile with name, extent, and version properties
width(width)
Get the vector tile's width
Parameters
param | type = default | description |
---|---|---|
width | number |
addField(field)
Add a field to this grid's output
Parameters
param | type = default | description |
---|---|---|
field | string |
addField
Get all of this grid's fields
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.
height
Get this grid's height
Returns
number
:
height
view(x, y, width, height)
Get a constrained view of this field given x, y, width, height parameters.
Parameters
Returns
mapnik.Grid
:
a grid constrained to this new view
width
Get this grid's width
Returns
number
:
width
attributes
Get the feature's attributes as an object.
Returns
Object
:
attributes
extent
Get the feature's extent
geometry
Get the feature's attributes as a Mapnik geometry.
Returns
mapnik.Geometry
:
geometry
id
Returns
number
:
id the feature's internal id
toJSON
Generate and return a GeoJSON representation of this feature
Returns
string
:
geojson Feature object in stringified GeoJSON
fromJSON(geojson)
Parameters
param | type = default | description |
---|---|---|
geojson | string | string Create a feature from a GeoJSON representation. |
clear(callback)
Make this image transparent, removing all image data from it.
Parameters
param | type = default | description |
---|---|---|
callback | Function |
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);
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
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 |
copy(type, [options], callback)
Copy this image data so that changes can be made to a clone of it.
Parameters
copySync(type, [options])
Copy this image data so that changes can be made to a clone of it.
Parameters
Returns
mapnik.Image
:
copy
data
Return a copy of the pixel data in this image as a buffer
demultiply(callback)
Demultiply the pixels in this image, asynchronously. The opposite of premultiplying
Parameters
param | type = default | description |
---|---|---|
callback | Function |
demultiplySync
Demultiply the pixels in this image. The opposite of premultiplying
encode([format], callback)
Encode this image into a buffer of encoded data
Parameters
Returns
Buffer
:
encoded image data
Example
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
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'));
fill(color, callback)
Asynchronously fill this image with a given color.
Parameters
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);
});
fillSync(color)
Fill this image with a given color
Parameters
param | type = default | description |
---|---|---|
color | ( mapnik.Color | number ) |
filter(filter, callback)
Asynchronously filter this image.
Parameters
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);
});
filterSync(filter)
Filter this image
Parameters
param | type = default | description |
---|---|---|
filter | string |
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 |
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);
getType
Determine the image type
Returns
number
:
Number of the image type
height
Get this image's height
Returns
number
:
height
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);
premultiplied
Determine whether the given image is premultiplied.
Returns
boolean
:
premultiplied true if the image is premultiplied
premultiply(callback)
Premultiply the pixels in this image, asynchronously
Parameters
param | type = default | description |
---|---|---|
callback | Function |
premultiplySync
Premultiply the pixels in this image
resize(width, height, [options], callback)
Create a copy this image that is resized
Parameters
resizeSync(width, height, [options])
Make a resized copy of an image
Parameters
Returns
mapnik.Image
:
copy
save(filename, [format], callback)
Encode this image and save it to disk as a file.
Parameters
saveSync(filename, [format])
Encode this image and save it to disk as a file.
Parameters
Example
myImage.saveSync('foo.png');
setPixel(x, y, numeric)
Parameters
view(x, y, width, height)
Get a constrained view of this image given x, y, width, height parameters.
Parameters
Returns
mapnik.Image
:
an image constrained to this new view
width
Get this image's width
Returns
number
:
width
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
Returns
mapnik.Image
:
image object
fromBytes(buffer, callback)
Create a new image from a buffer
Parameters
fromSVG(filename, callback)
Create a new image from an SVG file
Parameters
fromSVGBytes(filename, callback)
Create a new image from an SVG file
Parameters
describe
Describe the datasource's contents and type.
Returns
Object
:
description: an object with type, fields, encoding, geometry_type, and proj4 code
extent
Get the Datasource's extent
extent
Get the geometry's extent
toJSON([options], callback)
Convert this geometry into a GeoJSON representation, asynchronously.
Parameters
toJSONSync
Convert this geometry into a GeoJSON representation, synchronously.
Returns
string
:
GeoJSON, string-encoded representation of this geometry.
toWKB
Get the geometry's representation as Well-Known Binary
Returns
string
:
wkb representation of this geometry
toWKT
Get the geometry's representation as Well-Known Text
Returns
string
:
wkt representation of this geometry
type
Get the geometry type
Returns
string
:
type of geometry.
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);
inverse
Unproject from a position in this projection to the same position in WGS84 space.
get_premultiplied
Get whether this color is premultiplied
Returns
boolean
:
premultiplied
hex
Get this color represented as a hexademical string
Returns
string
:
hex representation
Example
var c = new mapnik.Color('green');
c.hex();
// '#008000'
set_premultiplied(premultiplied)
Set whether this color should be premultiplied
Parameters
param | type = default | description |
---|---|---|
premultiplied | boolean |
Throws
- TypeError
:
given a non-boolean argument
Example
var c = new mapnik.Color('green');
c.set_premultiplied(true);
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)'
next
Return the next Feature in this featureset if it exists, or null
if it
does not.
Returns
(
mapnik.Feature
|
null
)
:
next feature
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
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
imageScaling
Image scaling type constants representing color and grayscale encodings.
Properties
.polygonFillType
polygonFillType
Image scaling type constants representing color and grayscale encodings.
Properties
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, |
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);
});
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);
mapnik.Datasource
A Datasource object. This is the connector from Mapnik to any kind of file, network, or database source of geographical data.
mapnik.Feature
A single geographic feature, with geometry and properties. This is typically derived from data by a datasource, but can be manually created.
mapnik.Featureset
An iterator of mapnik.Feature objects.
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.
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 |
mapnik.Image(width, height, options)
Parameters
param | type = default | description |
---|---|---|
width | number | |
height | number | |
options | Object | valid options are |
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
});
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
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);
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
Example
var map = new mapnik.Map(25, 25, '+init=epsg:3857');
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');
mapnik.VectorTile(z, x, y)
A generator for the Mapbox Vector Tile specification of compressed and simplified tiled vector data
Parameters
Example
var vtile = new mapnik.VectorTile(9,112,195);