Download the PHP package prinsfrank/php-geo-svg without Composer
On this page you can find all versions of the php package prinsfrank/php-geo-svg. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package php-geo-svg
PHP Geo SVG
Generate and display maps without external services or compromising on privacy.
Why this package?
When searching for high quality SVG's for my blog, I ran into the issue that all SVG's where either too low quality, heavily polluted with unnecessary elements by the tool they were generated with, or in the wrong projection. This package provides the flexibility to generate maps manually or from geojson files, which are more readily available.
Features
- Supports creation of SVGs from GeoJSON (directly from file, as a JSON string or from an array) and manual GeometryCollection.
- Output the svg directly to your user on request or output to a file.
- Render an entire world map or only part of it by using a bounding box.
- Easy support for projections. Currently supported: EquiRectangular, Mercator, Miller and several Equal area projections (Lambert, Behrmann, Smyth, Trystan, Hobo-Dyer, Gall-Peters, Balthasart and Tobler's world in a square) Please open a PR to add any extra ones.
- When you create or edit a GeometryCollection, a Fluent Interface is provided to allow for method chaining.
Showcase |
---|
Countries - Equirectangular projection |
Netherlands - Mercator projection |
Table of Contents
- Why this package?
- Features
- Table of Contents
- Setup
- The basics; creating an SVG
- From a GeoJSON file
- From a GeoJSON string
- From a GeoJSON array
- From building your own GeometryCollection
- Different globe-to-plane transformations; Projections
- Displaying only parts of the world; Using bounding boxes
Setup
Make sure you are running PHP 8.0 or higher to use this package
To start right away, run the following command in your composer project;
Or for development only;
The basics; creating an SVG
Let's say we want to create the following simple continent map:
There are multiple ways we can go about creating this map in svg using this package;
From a GeoJSON file
To create an SVG from a GeoJson file, create a new 'GeometryCollection' by calling the 'createFromGeoJSONFilePath' method on the 'GeometryCollectionFactory' as follows;
Show code
With variables: Fluent:From a GeoJSON string
To create an SVG from a GeoJson string, create a new 'GeometryCollection' by calling the 'createFromGeoJsonString' method on the 'GeometryCollectionFactory' as follows;
Show code
With variables: Fluent:From a GeoJSON array
To create an SVG from a GeoJson array, create a new 'GeometryCollection' by calling the 'createFromGeoJSONArray' method on the 'GeometryCollectionFactory' as follows;
Show code
With variables: Fluent:From building your own GeometryCollection
To build an SVG manually from a GeometryCollection, create the object and add any geometry you want:
Show code
With variables: Fluent:Different globe-to-plane transformations; Projections
If you prefer a different projection other than the default EquiRectangular, you can! Currently, the following projections are supported, but please feel free to add any and open a PR;
- Equirectangular
- Mercator
- Miller
To specify the projection you want to use, you can do so either using the constructor;
Or using the 'setProjection' method;
Displaying only parts of the world; Using bounding boxes
If you want to use a bounding box, you have to know both the most southWestern and northEastern coordinates you want to show, and create 'BoundingBoxPositions' for both of them. Pass those along to a bounding box object and you have yourself a bounding box;
To actually use it, either pass the bounding box in the constructor after the projection;
Or set the bounding box using the 'setBoundingBox' method;