Skip to content

GitiFarazPishro/php7-mapnik

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP7 Mapnik

PHP7 Mapnik

Introduction

This project is an extension for PHP 7 that enables geospatial rendering with Mapnik. Create tile generation scripts, dynamic tile services, or static maps with Mapnik XML and PHP.

Build Status

Requirements

  • PHP >= 7.0
    • php7.0-gd
    • php7.0-dev
    • Available through sudo apt-get install php-dev php-gd on Ubuntu 16.04 Xenial
  • Mapnik 3.0.x
    • mapnik-config
    • Available through sudo apt-get install libmapnik-dev on Ubuntu 16.04 Xenial

Installation

git clone https://github.com/garrettrayj/php7-mapnik.git && cd php7-mapnik
phpize
./configure --with-mapnik
make test
make install
echo "extension=mapnik.so" > /etc/php.d/mapnik.ini

Note: Your PHP configuration directory may be different depending on OS and PHP settings.

Tile Server Example

Run the example...

./example/run.sh

...then visit http://localhost:8000/

Usage

<?php

// Register datasource plugins
// Use `mapnik-config --input-plugins` to get input plugin directory
\Mapnik\DatasourceCache::registerDatasources('/usr/local/lib/mapnik/input');

// Create map
$map = new \Mapnik\Map(640, 480);

// Register fonts
// Use `mapnik-config --fonts` to get Mapnik fonts directory
$map->registerFonts('/usr/local/lib/mapnik/fonts');

// Load Mapnik XML
$map->loadXmlFile('my_awesome_map.xml', false, $basePath);

// Situate map content within canvas
$map->zoomAll();

// Create image
$image = new \Mapnik\Image(640, 480);

// Render
$renderer = new \Mapnik\AggRenderer($map, $image);
$renderer->apply();

// Save PNG image file
$image->saveToFile('my_awesome_map.png');

See the API Documentation for a complete list of available objects and methods.

About

PHP extension for geospatial rendering with Mapnik

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 56.3%
  • PHP 36.9%
  • C 3.2%
  • M4 2.3%
  • HTML 1.2%
  • Shell 0.1%