定制 burnthebook/craft3-osmaps 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

burnthebook/craft3-osmaps

Composer 安装命令:

composer require burnthebook/craft3-osmaps

包简介

Allows you to display Ordnance Survey maps on your Craft CMS website.

README 文档

README

Allows you to display Ordnance Survey maps on your Craft CMS website.

Requirements

This plugin requires PHP 7.4 - 8.2 and supports Craft CMS 3.x, 4.x and 5.x.

OS Maps Craft 3 Craft 4 Craft 5
1.x
2.x
3.x

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

    cd /path/to/project
    
  2. Then tell Composer to load the plugin:

    composer require burnthebook/craft3-osmaps
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for OS Maps.

Configuration

  1. Add your OS Maps API Key on the plugin's settings page in the Control Panel.

  2. Set a Max Zoom Level value. This is usually 10 if you are not allowed to display the OS MasterMap Topography Layer.

Using OS Maps

Add the following to your twig template and modify where necessary.

{% do view.registerAssetBundle("Burnthebook\\OSMaps\\assetbundles\\OSMaps\\OSMapsAsset") %}

{% set tileUrl = craft.osMaps.getApiUrl() %}
{% set maxZoomLevel = craft.osMaps.getMaxZoomLevel() %}
{% set zoomLevel = 10 %}
{% set lat = 52.921309 %}
{% set long = -1.475118 %}

<div id="map" style="height: 500px; width: 500px;"></div>

{% js %}
    var map = createOSMap('map', '{{ tileUrl }}', { maxZoom: {{ maxZoomLevel }} });
    var latlng = [{{ lat }}, {{ long }}];
   
    map.setView(latlng, {{ zoomLevel }});
    L.marker(latlng).addTo(map);
{% endjs %}

See the Leaflet Documentation for reference on using the L JavaScript object.

Note that the createOSMap() function returns a Leaflet Map object.

Advanced usage

The getApiUrl() method accepts an object with options.

See the OS Maps Documentation for more details.

The default options we define are:

{% set tileUrl = craft.osMaps.getApiUrl({
    'service': 'WMTS',
    'request': 'GetTile',
    'version': '1.0.0',
    'layer': 'Road 27700',
    'style': 'true',
    'format': 'image/png',
    'tileMatrixSet': 'EPSG:27700',
    'tileMatrix': 'EPSG:27700:{z}',
    'tileRow': '{y}',
    'tileCol': '{x}'
}) %}

If you are using Google Maps in the Control Panel (e.g. Maps plugin), you will want to convert the Google Maps zoom level to an OS Maps zoom level:

{% set zoomLevel = craft.osMaps.convertGMapsZoomLevel(entry.map.zoom) %}

The JavaScript function createOSMap() accepts the following parameters:

  • id : ID of the Map's HTML element
  • tileUrl : URL to fetch tiles from
  • tileLayerOptions : Options for the Leaflet TileLayer object. See the Leaflet documentation for more details.
  • mapOptions : Options for the Leaflet Map object. See the Leaflet documentation for more details.
  • crs : An optional CRS object. See the Leaflet and/or Proj4leaflet documentations for instructions on creating a CRS object. It's fairly complicated. We provide a default CRS object for EPSG:27700

The function returns a standard Leaflet Map object. Do with it as you wish.

The Leaflet library (L object in JS) is also globally exposed should you wish to use it e.g. for adding markers or manipulating the map.

A note on performance

We are proxying all tile requests via the plugin (Craft) in order to keep the OS API key hidden from the public. This isn't the best approach from a performance perspective, however it is required by OS.

To illustrate this:

Map (front-end) <--> OS Maps Plugin (Craft) <--> OS Maps API

When users interact with a map (zooming/panning) this will trigger lots of requests to your server - one request for each tile to be more precise! If you have lots of users and lots of maps on your site, this could become a problem!

A possible solution would be to place your website over a CDN e.g. CloudFlare and enable full-page caching on all requests to /actions/os-maps/api/*, where /actions/ is your actionTrigger config setting (actions by default).

Just note that you'd have to clear the CDN cache when/if OS update any tiles.

Useful resources

Brought to you by Burnthebook

burnthebook/craft3-osmaps 适用场景与选型建议

burnthebook/craft3-osmaps 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 1.15k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「cms」 「Craft」 「craftcms」 「craft-plugin」 「os maps」 「ordnance survey」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 burnthebook/craft3-osmaps 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 burnthebook/craft3-osmaps 我们能提供哪些服务?
定制开发 / 二次开发

基于 burnthebook/craft3-osmaps 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.15k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: CSS

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-21