Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PHP library to easily get static image from OpenStreetMap (OSM) with markers, lines, circles and polygons.

License

NotificationsYou must be signed in to change notification settings

DantSu/php-osm-static-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PackagistLatest Stable VersionGitHub license

PHP OpenStreetMap Static API

PHP library to easily get static image from OpenStreetMap with markers, lines, circles and polygons.

This project uses theTile Server of the OpenStreetMap Foundation which runs entirely on donated resources, seeTile Usage Policy for more information.

✨ Supporting

⭐ Star this repository to support this project. You will contribute to increase the visibility of this library 🙂

Installation

Install this library easily with composer :

composer require dantsu/php-osm-static-api

How to use

Generate OpenStreetMap static image with markers and polygon :

use \DantSu\OpenStreetMapStaticAPI\OpenStreetMap;use \DantSu\OpenStreetMapStaticAPI\LatLng;use \DantSu\OpenStreetMapStaticAPI\Polygon;use \DantSu\OpenStreetMapStaticAPI\Markers;\header('Content-type: image/png');(newOpenStreetMap(newLatLng(44.351933,2.568113),17,600,400))    ->addMarkers(        (newMarkers(__DIR__ .'/resources/marker.png'))            ->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)            ->addMarker(newLatLng(44.351933,2.568113))            ->addMarker(newLatLng(44.351510,2.570020))            ->addMarker(newLatLng(44.351873,2.566250))    )    ->addDraw(        (newPolygon('FF0000',2,'FF0000DD'))            ->addPoint(newLatLng(44.351172,2.571092))            ->addPoint(newLatLng(44.352097,2.570045))            ->addPoint(newLatLng(44.352665,2.568107))            ->addPoint(newLatLng(44.352887,2.566503))            ->addPoint(newLatLng(44.352806,2.565972))            ->addPoint(newLatLng(44.351517,2.565672))    )    ->getImage()    ->displayPNG();

Exported OpenStreetMap image

Align and zoom the map to drawings and markers :

  • ->fitToDraws(int $padding = 0)
  • ->fitToMarkers(int $padding = 0)
  • ->fitToDrawsAndMarkers(int $padding = 0)
  • ->fitToPoints(LatLng[] $points, int $padding = 0)

$padding sets the amount of padding in the borders of the map that shouldn't be accounted for when setting the view to fit bounds. This can be positive or negative according to your needs.

use \DantSu\OpenStreetMapStaticAPI\OpenStreetMap;use \DantSu\OpenStreetMapStaticAPI\LatLng;use \DantSu\OpenStreetMapStaticAPI\Polygon;use \DantSu\OpenStreetMapStaticAPI\Markers;\header('Content-type: image/png');(newOpenStreetMap(newLatLng(0,0),0,600,400))    ->addMarkers(        (newMarkers(__DIR__ .'/resources/marker.png'))            ->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM)            ->addMarker(newLatLng(44.351933,2.568113))            ->addMarker(newLatLng(44.351510,2.570020))            ->addMarker(newLatLng(44.351873,2.566250))    )    ->addDraw(        (newPolygon('FF0000',2,'FF0000DD'))            ->addPoint(newLatLng(44.351172,2.571092))            ->addPoint(newLatLng(44.352097,2.570045))            ->addPoint(newLatLng(44.352665,2.568107))            ->addPoint(newLatLng(44.352887,2.566503))            ->addPoint(newLatLng(44.352806,2.565972))            ->addPoint(newLatLng(44.351517,2.565672))    )    ->fitToDraws(10)    ->getImage()    ->displayPNG();

Documentation

ClassDescription
CircleDantSu\OpenStreetMapStaticAPI\Circle draw circle on the map.
LatLngDantSu\OpenStreetMapStaticAPI\LatLng define latitude and longitude for map, lines, markers.
LineDantSu\OpenStreetMapStaticAPI\Line draw line on the map.
MapDataDantSu\OpenStreetMapStaticAPI\MapData convert latitude and longitude to image pixel position.
MarkersDantSu\OpenStreetMapStaticAPI\Markers display markers on the map.
OpenStreetMapDantSu\OpenStreetMapStaticAPI\OpenStreetMap is a PHP library created for easily get static image from OpenStreetMap with markers, lines, polygons and circles.
PolygonDantSu\OpenStreetMapStaticAPI\Polygon draw polygon on the map.
TileLayerDantSu\OpenStreetMapStaticAPI\TileLayer define tile server url and related configuration
XYDantSu\OpenStreetMapStaticAPI\XY define X and Y pixel position for map, lines, markers.

Contributing

Please fork this repository and contribute back using pull requests.

Any contributions, large or small, major features, bug fixes, are welcomed and appreciated but will be thoroughly reviewed.

About

PHP library to easily get static image from OpenStreetMap (OSM) with markers, lines, circles and polygons.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors5

Languages


[8]ページ先頭

©2009-2025 Movatter.jp