larswiegers/laravel-maps
Composer 安装命令:
composer require larswiegers/laravel-maps
包简介
A new way to handle maps in your laravel applications.
README 文档
README
This package allows you to easily use leaflet.js or google maps to create a map in your laravel project.
Installation
You can install the package via composer:
composer require larswiegers/laravel-maps
If you want to customize the map views more then you can publish the views:
php artisan vendor:publish --provider="Larswiegers\LaravelMaps\LaravelMapsServiceProvider"
Supported map types
| What | Basic map | Different map types | Centerpoint | Basic markers | Use bounds | Zoomlevel | Can use different tiles | Can be used multiple times on the same page |
|---|---|---|---|---|---|---|---|---|
| Leaflet | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ |
| Google maps | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ |
Tilehosts
Openstreetmap
Openstreetmap is a creative commence tile library created by volunteers. No configuration has to be set to use as it is the default tilehost for this library. More information can be found here: openstreetmap.org
Mapbox
Mapbox is a for profit company that also offers free keys.
Their map can be more accurate / precise.
To get your free key go to mapbox.com
Once logged in you can get your free key and use it by placing it in the env file like this MAPS_MAPBOX_ACCESS_TOKEN.
Attribution
Mapbox requires you to have attribution when you use their tilehost. More information on that here: https://docs.mapbox.com/help/getting-started/attribution/ We provide a default value if you use mapbox. But if you want to customize it you can pass in the te text via the attribution attribute. Like this:
<x-maps-leaflet
:attribution="Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>">
</x-maps-leaflet>
Usage
Leaflet
// Leaflet // A basic map is as easy as using the x blade component. <x-maps-leaflet></x-maps-leaflet> // Set the centerpoint of the map: <x-maps-leaflet :centerPoint="['lat' => 52.16, 'long' => 5]"></x-maps-leaflet> // Set a zoomlevel: <x-maps-leaflet :zoomLevel="6"></x-maps-leaflet> // Set markers on the map: <x-maps-leaflet :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091]]"></x-maps-leaflet>
Do note that if you want to use multiple maps on the same page that you need to specify an id per map.
Leaflet Version
By default we use the latest version of leaflet, but if you want to use a different version just pass it in via a parameter:
// Set leafletVersion to desired version: <x-maps-leaflet leafletVersion='1.9.4'></x-maps-leaflet>
Google Maps
// Google Maps // Set the centerpoint of the map: <x-maps-google :centerPoint="['lat' => 52.16, 'long' => 5]"></x-maps-google> // Set a zoomlevel: <x-maps-google :zoomLevel="6"></x-maps-google> // Set type of the map (roadmap, satellite, hybrid, terrain): <x-maps-google :mapType="'hybrid'"></x-maps-google> // Set markers on the map: <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091]]"></x-maps-google> // You can customize the title for each markers: <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'title' => 'Your Title']]"></x-maps-google> // You can add custom icons to markers: <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'icon' => 'path/to/icon.png']]"></x-maps-google> // You can add text labels next to markers (uses Advanced Markers): <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'label' => 'Store Location']]"></x-maps-google> // You can combine icons and labels: <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'icon' => 'store.png', 'label' => 'Main Store']]"></x-maps-google> // You can add info windows that appear when clicking markers: <x-maps-google :markers="[['lat' => 52.16444513293423, 'long' => 5.985622388024091, 'info' => 'This is our main office']]"></x-maps-google> // Automatically adjust the map's view during initialization to encompass all markers: <x-maps-google :markers="[ ['lat' => 46.056946, 'long' => 14.505752], ['lat' => 41.902782, 'long' => 12.496365] ]" :fitToBounds="true" ></x-maps-google> // Position the map's center at the geometric midpoint of all markers: <x-maps-google :markers="[ ['lat' => 46.056946, 'long' => 14.505752], ['lat' => 41.902782, 'long' => 12.496365] ]" :centerToBoundsCenter="true" :zoomLevel="7" ></x-maps-google>
Google maps api key
You can get an api key here:
Create an api key and enable the Maps Javascript API in the console aswell.
Place the api key in the env file like this
MAPS_GOOGLE_MAPS_ACCESS_TOKEN
Advanced Markers
This package now uses Google Maps' AdvancedMarkerElement (introduced in v3.56) instead of the deprecated google.maps.Marker class. Advanced Markers provide several improvements including:
- Better performance and rendering
- Support for custom HTML content including text labels next to markers
- Improved accessibility
- Future-proof implementation aligned with Google's latest recommendations
Read more about Advanced Markers: Google Maps Advanced Markers Documentation
Good to know
Double quotes need to be escaped, i.e. add a backslash followed by double quotes (/")
Usage in livewire
This library does not support livewire out of the box, but some users have found a workaround to work. Please see this issue for more information: #34
Feel free to PR a livewire component if you have the time.
Testing
To run the tests just use the following component:
composer test
Testing is done through rendering the blade components and making assertions on the html outputted. While this is great for initial testing it does lack some more certainty. In the future an browser test may be needed to further make sure that the code works as intended.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email larswiegers@live.nl instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
larswiegers/laravel-maps 适用场景与选型建议
larswiegers/laravel-maps 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138.37k 次下载、GitHub Stars 达 364, 最近一次更新时间为 2021 年 05 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「larswiegers」 「laravel-maps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 larswiegers/laravel-maps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 larswiegers/laravel-maps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 larswiegers/laravel-maps 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 138.37k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 365
- 点击次数: 26
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-26