Generate static map url for maptiler.com

Overview

PHP static maps url generator

The package is used for static maps (images) URL generate.

For now, it works only with maptiler.com. I welcome your commits to add new providers (such as Openstreet maps, Mapbox, Google.Maps, Yandex.Maps, Bing.Maps, 2GIS, and others)

Quickstart

Add package to your project via Composer: composer require surzhikov/static-map-url-generator

Centered map example:

<?php
use \Surzhikov\StaticMapUrlGenerator\Map;

$map = Map::provider('maptiler')
  ->apiKey('XXXXXXXXXXXXXXXXXXXX') // Your MapTiler token
  ->width(250) // Width of resulted image
  ->height(210) // Height of resulted image
  ->retina(true) // For retina screen devices
  ->mapStyle('basic-v2') // Map style 
  ->centered(32.413403, 34.765209, 12) // Center map on Lng/Lat, zoom
  ->url(); // Get URL for static map
Will return:
https://api.maptiler.com/maps/basic-v2/static/32.413403,34.765209,12/[email protected]?key=[TOKEN_IS_HIDDEN]&attribution=1

Bounded map example

<?php
use \Surzhikov\StaticMapUrlGenerator\Map;

$map = Map::provider('maptiler')
  ->apiKey('XXXXXXXXXXXXXXXXXXXX') // Your MapTiler token
  ->width(250) // Width of resulted image
  ->height(210) // Height of resulted image
  ->retina(true) // For retina screen devices
  ->mapStyle('streets-v2') // Map style 
  ->bounds(11, 51, 14, 54) // Bounds: minLng, minLat, maxLng, maxLat
  ->url(); // Get URL for static map
Will return:
https://api.maptiler.com/maps/streets-v2/static/11,51,14,54/[email protected]?key=[TOKEN_IS_HIDDEN]&attribution=1

Auto-fit map with polylines / markers example

<?php
use \Surzhikov\StaticMapUrlGenerator\Map;
$polygon1 = [[-59.83703613, -3.23649764], [-59.81506347, -3.10212100], [-59.83154296, -3.05001113], [-59.89746093, -2.99789874], [-59.94689941, -2.95675562], [-59.90020751, -2.86349227], [-59.86450195, -2.78942477], [-59.95239257, -2.75376097], [-60.00457763, -2.87446482], [-59.99633789, -2.82508749], [-60.02105712, -2.70986560], [-60.08148193, -2.71260911], [-60.08148193, -2.84703323], [-60.08697509, -2.91286794], [-60.40008544, -2.97047016], [-60.55938720, -3.14600100], [-60.55664062, -3.39279086], [-60.29571533, -3.77655930], [-59.96063232, -3.44488305], [-59.83703613, -3.23649764]];

$polygon2 = [[-60.72418212, -2.44920493], [-60.66375732, -2.27906185], [-60.63629150, -2.11713280], [-60.77087402, -2.00459579], [-60.93292236, -2.00734069], [-61.06201171, -2.08694073], [-61.06201171, -2.37785715], [-60.79559326, -2.57817004], [-60.72418212, -2.44920493]];

$poligon1StrokeColor = 'rgba(0,0,255,0.5)'; // Color can be set as rgba()
$poligon2StrokeColor = urlencode('#00ff00'); // Or as urlencoded #hex
$poligon1FillColor = 'rgba(0,0,255,0.2)'; 
$poligon2FillColor = 'rgba(0,255,0,0.5)'; 

$map = Map::provider('maptiler')
  ->apiKey('XXXXXXXXXXXXXXXXXXXX') // Your MapTiler token
  ->width(500) // Width of resulted image
  ->height(350) // Height of resulted image
  ->retina(false) // For retina screen devices
  ->mapStyle('streets-v2') // Map style 
  ->autoFit() // Set map position to auto-fit
  ->addPolyline($polygon1, 2, $poligon1StrokeColor, $poligon1FillColor, true)
  ->addPolyline($polygon2, 2, $poligon2StrokeColor, $poligon2FillColor, true)
  ->addMarker([-60.70495605, -2.8003989], 'red')
  ->url(); // Get URL for static map
Will return:
https://api.maptiler.com/maps/streets-v2/static/auto/500x350.png?key=[TOKEN_IS_HIDDEN]&path=stroke:rgba(0,0,255,0.5)|width:2|fill:rgba(0,0,255,0.2)|enc:bcwRn|elJ{fYkhCudI~eBudI~zKc`G~sH}eQybH}mMe~E{}EhdPjqVdeIqsHor@coUnyCbPrxJbgY?nzKja@~fJ|c|@`ha@rb^leo@ePp}iAw}q@_x_Aim`Akug@mcW&path=stroke:%2300ff00|width:2|fill:rgba(0,255,0,0.5)|enc:nj}MbesqJkf`@sxJas^ujDi~TbhYbPxs^npNxeXfyw@?|bf@c`s@aeXi}L&markers=-60.70495605,-2.8003989,red&attribution=1

Marker params

addMarker($point, $color, $anchor, $icon, $scale);
  • point – Point for marker [lng, lat].
  • color – Color of polyline stroke. Example: 'rgba(0,0,255,0.2)' or urlencode('#EF00FF')
  • anchor – Marker anchor (top, left, bottom, right, center, topleft, bottomleft, topright, bottomright), default - bottom
  • icon – URL to a remote image (URL-encoded)
  • scale – the scale of the image

Polyline params

addPolyline($points, $strokeWidth, $strokeColor, $fillColor, $asEnc);
  • points – array of points, like [[lng, lat], [lng, lat], [lng, lat], [lng, lat]].
  • strokeWidth – width of polyline stroke.
  • strokeColor – color of polyline stroke. Example: 'rgba(0,0,255,0.2)' or urlencode('#EF00FF')
  • fillColor - color of polyline fill.
  • asEnc – ture/false – use Google Polyline encoding format (default: true).
You might also like...
Magento 2 module which can find potential url related problems in your catalog data
Magento 2 module which can find potential url related problems in your catalog data

Url data integrity checker module for Magento 2 Purpose The purpose of this module is to give store owners of a Magento 2 shop insight into what url-r

A Magento 2 module that allows for creating discrete PDP (Product Detail Pages) page layouts for customers landing on the site from a PPC (Pay Per Click) link/ad by allowing routing to the same pages using a `/ppc/` prefix in the URL path.
A Magento 2 module that allows for creating discrete PDP (Product Detail Pages) page layouts for customers landing on the site from a PPC (Pay Per Click) link/ad by allowing routing to the same pages using a `/ppc/` prefix in the URL path.

A Magento 2 module that allows for creating discrete PDP (Product Detail Pages) page layouts for customers landing on the site from a PPC (Pay Per Click) link/ad by allowing routing to the same pages using a `/ppc/` prefix in the URL path.

UrlFactory help you to manage URL.

UrlFactory UrlFactory is a PHP package for working with URLs. Its offer you to best developer experience to manage and manipulate URLs. UrlFactory off

⚡️ A WordPress plugin to quickly send a 404 for missing static files

Static 404 A WordPress plugin to quickly send a 404 for missing static files. Quickly output a 404 for static files that aren't found, rather than loa

Static Web App to train Filipinos in using MS Word with the use of Filipino language
Static Web App to train Filipinos in using MS Word with the use of Filipino language

MS Word Filipino Isang static web application na layuning magturo ng paggamit ng MS Word sa wikang Filipino. Ito ay isang proyekto na bahagi ng panana

Docker image that provides static analysis tools for PHP

Static Analysis Tools for PHP Docker image providing static analysis tools for PHP. The list of available tools and the installer are actually managed

A Magento 1.x module which facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN, Varnish, etc using best practices outlined within the HTML5 boilerplate community.

Magento Cachebuster Cachebuster is a Magento module which facilitates automatic purging of static assets from HTTP caches such as browser cache, CDN,

Beautiful and understandable static analysis tool for PHP
Beautiful and understandable static analysis tool for PHP

PhpMetrics PhpMetrics provides metrics about PHP project and classes, with beautiful and readable HTML report. Documentation | Twitter | Contributing

The SensioLabs DeprecationDetector runs a static code analysis against your project's source code to find usages of deprecated methods, classes and interfaces

SensioLabs DeprecationDetector CAUTION: This package is abandoned and will no longer receive any updates. The SensioLabs DeprecationDetector runs a st

Releases(v1.0.2)
Owner
Andrey Surzhikov
Contact: https://t.me/surzhikov
Andrey Surzhikov
Shortener URL is simple web application to short your URL

Shortener URL is simple web application to short your URL. It will generate unique key, with the unique key it will redirect to the original URL.

Abid Ra 1 Jan 22, 2022
Maps Railroad Online Savegames to a SVG map

RailroadOnlineMapper @ian76g#6577 Environments DEV - https://zwackelmann.online/ QA - https://ohnezahn.online/ PROD - https://minizwerg.online/ Gettin

Sebastian Köhler 5 Jan 3, 2023
PHP library that helps to map any input into a strongly-typed value object structure.

Valinor • PHP object mapper with strong type support Valinor is a PHP library that helps to map any input into a strongly-typed value object structure

Team CuyZ 873 Jan 7, 2023
A plugin to test Server->getPlayerExact() vs Map performance

PeformanceTests A plugin to test Server->getPlayerExact() vs Map<username, Player> performance Timings with Server->getPlayerExact() https://timings.p

KingOfTurkey38 1 Feb 25, 2022
Google map with autocomplete

Nova Google Map With Autocomplete Field Package This field allows you to work with Google Places API to autocomplete and Google Map on user input and

TrinityRank DevTeam 2 Jul 29, 2022
590+ usernames in this dictionary! A list of reserved usernames to prevent url collision with resource paths.

590+ usernames in this dictionary! A list of reserved usernames to prevent url collision with resource paths. This repository hosts the list in multiple formats like JSON, CSV, SQL and plain text. You can use its just download its by wget.

ShouldBee 546 Dec 22, 2022
Unicode-url-for-Textpattern - Plugin for using unicode urls instead of transliterations to ASCII characters

Unicode-url-for-Textpattern Summary textpattern plugin wcz_utf8_url – uses UTF-8 permlinks instead of transliterated ones for SEO Features automatical

Andrij 4 Dec 16, 2017
Magento 2 Module Experius Page Not Found 404. This module saves all 404 url to a database table

Magento 2 Module Experius Page Not Found 404 This module saves all 404 urls to a database table. Adds an admin grid with 404s It includes a count so y

Experius 28 Dec 9, 2022
Magento 2 extension. Solution for set Url of Category without Parent path.

Magento 2 extension. Solution for set Url of Category without Parent path.

Alex S 1 Jul 28, 2022
Url's amigables en PHP

Phurl - Url's amigables en PHP Motor de url's amigables minimalista y sencillo de usar, crea tus vistas en Html plano. No es compatible con variables

Devfy 2 Apr 28, 2022