How to use the mapnik.register_fonts function in mapnik

To help you get started, we’ve selected a few mapnik examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mapbox / mapbox-tile-copy / index.js View on Github external
var tl_file = require('tilelive-file');
var path = require('path');

// Note: tilelive-vector is needed for `tm2z` protocol (https://github.com/mapbox/tilelive-vector/issues/124)
Vector.registerProtocols(tilelive);
MBTiles.registerProtocols(tilelive);
Omnivore.registerProtocols(tilelive);
TileJSON.registerProtocols(tilelive);
Mapbox.registerProtocols(tilelive);
S3.registerProtocols(tilelive);
tl_file.registerProtocols(tilelive);

var mapnik = require('mapnik');
mapnik.Logger.setSeverity(mapnik.Logger.NONE);

mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-default-fonts')), { recurse: true });
mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-pro-fonts')), { recurse: true });
if (process.env.MapboxTileCopyFonts)
  mapnik.register_fonts(process.env.MapboxTileCopyFonts, { recurse: true });

module.exports = function(filepath, dsturi, options, callback) {

  if (s3urls.valid(dsturi)) {
    // Make sure the s3url is of type s3://bucket/key
    var query = url.parse(dsturi).query;
    dsturi = s3urls.convert(dsturi, 's3');
    if (query) dsturi += '?' + query;

    if (dsturi.indexOf('{z}') == -1 ||
        dsturi.indexOf('{x}') == -1 ||
        dsturi.indexOf('{y}') == -1) return callback(new Error('Destination URL does not include a {z}/{x}/{y} template.'));
github mapbox / mapbox-tile-copy / index.js View on Github external
// Note: tilelive-vector is needed for `tm2z` protocol (https://github.com/mapbox/tilelive-vector/issues/124)
Vector.registerProtocols(tilelive);
MBTiles.registerProtocols(tilelive);
Omnivore.registerProtocols(tilelive);
TileJSON.registerProtocols(tilelive);
Mapbox.registerProtocols(tilelive);
S3.registerProtocols(tilelive);
tl_file.registerProtocols(tilelive);

var mapnik = require('mapnik');
mapnik.Logger.setSeverity(mapnik.Logger.NONE);

mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-default-fonts')), { recurse: true });
mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-pro-fonts')), { recurse: true });
if (process.env.MapboxTileCopyFonts)
  mapnik.register_fonts(process.env.MapboxTileCopyFonts, { recurse: true });

module.exports = function(filepath, dsturi, options, callback) {

  if (s3urls.valid(dsturi)) {
    // Make sure the s3url is of type s3://bucket/key
    var query = url.parse(dsturi).query;
    dsturi = s3urls.convert(dsturi, 's3');
    if (query) dsturi += '?' + query;

    if (dsturi.indexOf('{z}') == -1 ||
        dsturi.indexOf('{x}') == -1 ||
        dsturi.indexOf('{y}') == -1) return callback(new Error('Destination URL does not include a {z}/{x}/{y} template.'));

  } else if (dsturi.indexOf('file://') == -1) {
    return callback(new Error('Invalid output protocol: ' + dsturi));
  }
github mapbox / mapbox-studio-classic / lib / tm.js View on Github external
tm.config = function(opts, callback) {
    if (!opts) return tm._config;

    tm._config = _(opts).defaults(tm._config);
    // @TODO create other paths (cache, etc.)
    try {
        mkdirp.sync(path.dirname(tm.config().db));
        mkdirp.sync(tm.config().tmp);
        mkdirp.sync(tm.config().cache);
    } catch(err) { throw err; }

    // Register default fonts.
    mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-pro-fonts')), { recurse: true });
    mapnik.register_fonts(path.dirname(require.resolve('mapbox-studio-default-fonts')), { recurse: true });

    // Register default plugins. Used for font rendering.
    mapnik.register_default_input_plugins();

    // Set up logging with rotation after 10e6 bytes.
    applog(tm.config().log, 10e6, function(err) {
        if (err && callback) return callback(err);
        if (err) throw err;
        // Compact db.
        tm.dbcompact(tm.config().db, function(err, db) {
            if (err && callback) return callback(err);
            if (err) throw err;
            tm.dbmigrate(db);
            tm.db = db;
            if (callback) return callback();
        });
github mapbox / mapbox-studio-default-fonts / bin / generate-font-families.js View on Github external
const mapnik = require('mapnik');
const path = require('path');
const fs = require('fs');

mapnik.register_fonts('./', { recurse: true });
// Keywords are ordered by "display priority" -- e.g. fonts
// containing earlier words should be favored for being a preview
// of the family as a whole.
const keywords = [
    'medium',
    'normal',
    'regular',
    'book',
    'roman',
    'semibold',
    'semibolditalic',
    'demi',
    'bold',
    'bolditalic',
    'caption',
    'cn',
github mapbox / tilelive / tilelive.js View on Github external
require.paths.unshift(__dirname + '/modules',
        __dirname + '/lib/node', __dirname);

var mapnik = require('mapnik');

mapnik.register_datasources('/usr/local/lib/mapnik2/input');
mapnik.register_fonts('/usr/local/lib/mapnik2/fonts/');

var settings = require('./settings');

/**
 * Wireframe of TileLive.js
 */
require('bootstrap.js')();
require('tilehandler.js');
require('inspect.js');

var app = require('server');
app.listen(app.set('settings')('port'));
console.log('TileLive server started on port %s', app.address().port);