miclf/static-map
Composer 安装命令:
composer require miclf/static-map
包简介
README 文档
README
A PHP package for generating static maps from map tile servers. Think of it as taking a screenshot of specific locations on OpenStreetMap.
Requirements
This package uses the GD library. You probably already have it, since it’s almost always installed by default with PHP.
Installation
You can install the package via the Composer dependency manager:
composer require miclf/static-map
Usage
The most straightforward way to use the package is by providing coordinates (latitude and longitude) and the path where the generated map will be saved.
<?php use Miclf\StaticMap\StaticMap; // This generates a map centred on the Atomium, in Brussels. StaticMap::centeredOn(50.89492, 4.34152)->save('path/to/map.png');
You can also provide a specific zoom level to use:
// Specify the zoom level as a third argument to the constructor. StaticMap::centeredOn(50.89492, 4.34152, 10)->save('path/to/map.png'); // Alternatively, you can also specify a zoom level with a dedicated method. StaticMap::centeredOn(50.89492, 4.34152) ->withZoom(10) ->save('path/to/map.png');
Options
Several aspects of the generated maps can be customised.
Width and height of the image
// Generates a map with a width of 500px and a height of 250px. StaticMap::centeredOn(50.89492, 4.34152) ->withDimensions(500, 250) ->save('path/to/map.png');
Tile provider
By default, the maps are rendered using the ‘Terrain’ style from Stamen Design.
If, for example, you would like to use the tiles provided by GEO-6 for OpenStreepMap Belgium instead, use the withTileProvider() method to specify the URL template to use.
Please don’t forget to provide proper attribution to the tile provider and the OSM contributors when using the generated maps. StaticMap is not able to do that for you.
StaticMap::centeredOn(50.89492, 4.34152) ->withTileProvider('https://tile.openstreetmap.be/osmbe/{z}/{x}/{y}.png') ->save('path/to/map.png');
‘debug’ mode
Basically, StaticMap works by identifying which tiles are required for the map, depending on the coordinates and zoom level. It then downloads the tiles and groups them all in a single picture. Finally, it crops the image so that the map is centred on the specified latitude and longitude.
If you’re curious, you can enable a ‘debug’ mode to generate a map showing this process:
StaticMap::centeredOn(50.89492, 4.34152) ->debug() ->save('path/to/map.png');
This mode has no real purpose apart from this educational aspect.
License
License? Copyright? Putting copyright on code is like using pesticides in agriculture. Please don’t do that. That kills people.
This code belongs to the public domain. It belongs to everybody.
If you really want a license, then this project is licensed under the Creative Commons Zero license. Which means that it belongs to the public domain.
miclf/static-map 适用场景与选型建议
miclf/static-map 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 3, 最近一次更新时间为 2019 年 12 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 miclf/static-map 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 miclf/static-map 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: CC0-1.0
- 更新时间: 2019-12-14