Skip to content

PHP7 extension for geospatial rendering with Mapnik

Notifications You must be signed in to change notification settings

3XE/php7-mapnik

 
 

Repository files navigation

PHP7 Mapnik

Introduction

PHP7 Mapnik brings geospatial rendering to PHP via the powerful Mapnik XML API. It is ideal for building dynamic tile servers or livening up websites with custom static maps.

Build Status

Requirements

  • PHP 7.0.x
  • Mapnik 3.0.x

Installation

# git clone ... && cd php7-mapnik
phpize
./configure --with-mapnik
make test
echo "extension=`pwd`/modules/mapnik.so" | sudo tee -a /etc/php.ini

Usage

<?php

// Register datasource plugins
$pluginConfigOutput = [];
exec('mapnik-config --input-plugins', $pluginConfigOutput);
\Mapnik\DatasourceCache::registerDatasources($pluginConfigOutput[0]);

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

// Register fonts
$fontConfigOutput = [];
exec('mapnik-config --fonts', $fontConfigOutput);
$map->registerFonts($fontConfigOutput[0]);

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

// Situate the map within the viewport
$map->zoomAll();

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

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

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

Developer Notes

  • Do NOT compile Boost with C++11. On Mac at least, you'll have a bad time with missing symbols.

License

The MIT License (MIT)

Copyright © 2016 Garrett Johnson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

PHP7 extension for geospatial rendering with Mapnik

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 67.1%
  • PHP 17.4%
  • C 9.3%
  • M4 4.0%
  • HTML 2.0%
  • Shell 0.2%