dantsu/php-osm-static-api
Composer 安装命令:
composer require dantsu/php-osm-static-api
包简介
PHP library to easily get static image from OpenStreetMap (OSM), add markers and draw lines.
README 文档
README
PHP OpenStreetMap Static API
PHP library to easily get static image from OpenStreetMap with markers, lines, circles and polygons.
This project uses the Tile Server of the OpenStreetMap Foundation which runs entirely on donated resources, see Tile 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'); (new OpenStreetMap(new LatLng(44.351933, 2.568113), 17, 600, 400)) ->addMarkers( (new Markers(__DIR__ . '/resources/marker.png')) ->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM) ->addMarker(new LatLng(44.351933, 2.568113)) ->addMarker(new LatLng(44.351510, 2.570020)) ->addMarker(new LatLng(44.351873, 2.566250)) ) ->addDraw( (new Polygon('FF0000', 2, 'FF0000DD')) ->addPoint(new LatLng(44.351172, 2.571092)) ->addPoint(new LatLng(44.352097, 2.570045)) ->addPoint(new LatLng(44.352665, 2.568107)) ->addPoint(new LatLng(44.352887, 2.566503)) ->addPoint(new LatLng(44.352806, 2.565972)) ->addPoint(new LatLng(44.351517, 2.565672)) ) ->getImage() ->displayPNG();
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'); (new OpenStreetMap(new LatLng(0, 0), 0, 600, 400)) ->addMarkers( (new Markers(__DIR__ . '/resources/marker.png')) ->setAnchor(Markers::ANCHOR_CENTER, Markers::ANCHOR_BOTTOM) ->addMarker(new LatLng(44.351933, 2.568113)) ->addMarker(new LatLng(44.351510, 2.570020)) ->addMarker(new LatLng(44.351873, 2.566250)) ) ->addDraw( (new Polygon('FF0000', 2, 'FF0000DD')) ->addPoint(new LatLng(44.351172, 2.571092)) ->addPoint(new LatLng(44.352097, 2.570045)) ->addPoint(new LatLng(44.352665, 2.568107)) ->addPoint(new LatLng(44.352887, 2.566503)) ->addPoint(new LatLng(44.352806, 2.565972)) ->addPoint(new LatLng(44.351517, 2.565672)) ) ->fitToDraws(10) ->getImage() ->displayPNG();
Documentation
| Class | Description |
|---|---|
| Circle | DantSu\OpenStreetMapStaticAPI\Circle draw circle on the map. |
| LatLng | DantSu\OpenStreetMapStaticAPI\LatLng define latitude and longitude for map, lines, markers. |
| Line | DantSu\OpenStreetMapStaticAPI\Line draw line on the map. |
| MapData | DantSu\OpenStreetMapStaticAPI\MapData convert latitude and longitude to image pixel position. |
| Markers | DantSu\OpenStreetMapStaticAPI\Markers display markers on the map. |
| OpenStreetMap | DantSu\OpenStreetMapStaticAPI\OpenStreetMap is a PHP library created for easily get static image from OpenStreetMap with markers, lines, polygons and circles. |
| Polygon | DantSu\OpenStreetMapStaticAPI\Polygon draw polygon on the map. |
| TileLayer | DantSu\OpenStreetMapStaticAPI\TileLayer define tile server url and related configuration |
| XY | DantSu\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.
dantsu/php-osm-static-api 适用场景与选型建议
dantsu/php-osm-static-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 162.38k 次下载、GitHub Stars 达 97, 最近一次更新时间为 2021 年 09 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「image」 「api」 「map」 「static」 「maps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dantsu/php-osm-static-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dantsu/php-osm-static-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dantsu/php-osm-static-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
A PSR-7 compatible library for making CRUD API endpoints
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Yii2 prettyPhoto image galary widget uses Lightbox view control jquery.prettyphoto.js
Alfabank REST API integration
统计信息
- 总下载量: 162.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 97
- 点击次数: 26
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-08
