staticmaplite/web/staticmap.php

102 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* staticMapLite 0.3.1
*
* Copyright 2009 Gerhard Koch
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @author Gerhard Koch <gerhard.koch AT ymail.com>
*
* USAGE:
*
* staticmap.php?center=40.714728,-73.998672&zoom=14&size=512x512&maptype=mapnik&markers=40.702147,-74.015794,blues|40.711614,-74.012318,greeng|40.718217,-73.998284,redc
*
*/
2017-05-26 11:17:40 +00:00
require_once '../vendor/autoload.php';
2017-09-29 14:20:00 +00:00
use StaticMapLite\Element\Marker\ExtraMarker;
2017-06-08 18:09:43 +00:00
use StaticMapLite\Element\Polyline\Polyline;
2017-05-26 14:06:21 +00:00
use StaticMapLite\Printer;
2017-05-26 14:06:21 +00:00
$printer = new Printer();
2017-05-26 14:16:40 +00:00
list($centerLatitude, $centerLongitude) = explode(',', $_GET['center']);
list($width, $height) = explode('x', $_GET['size']);
$printer
->setCenter($centerLatitude, $centerLongitude)
->setZoom($_GET['zoom'])
->setSize($width, $height)
->setMapType($_GET['maptype'])
;
2017-05-26 15:04:30 +00:00
$markers = $_GET['markers'];
if ($markers) {
$markerList = explode('|', $markers);
2017-06-08 18:09:43 +00:00
foreach ($markerList as $markerData) {
2017-09-30 20:33:23 +00:00
list($markerLatitude, $markerLongitude, $markerShape, $markerColor, $markerIcon) = explode(',', $markerData);
2017-05-26 15:04:30 +00:00
2017-09-30 20:33:23 +00:00
$marker = new ExtraMarker(getMarkerShape($markerShape), getMarkerColor($markerColor), $markerLatitude, $markerLongitude);
2017-05-26 15:11:00 +00:00
$printer->addMarker($marker);
2017-05-26 15:04:30 +00:00
}
}
2017-06-08 18:09:43 +00:00
$polylines = $_GET['polylines'];
if ($polylines) {
$polylineList = explode('|', $polylines);
foreach ($polylineList as $polylineData) {
list($polyline64String, $colorRed, $colorGreen, $colorBlue) = explode(',', $polylineData);
$polylineString = base64_decode($polyline64String);
$polyline = new Polyline($polylineString, $colorRed, $colorGreen, $colorBlue);
$printer->addPolyline($polyline);
}
}
2017-05-26 14:06:21 +00:00
print $printer->showMap();
2017-09-30 20:33:23 +00:00
function getMarkerShape(string $markerShape): int
{
$shapes = ['circle', 'square', 'star', 'penta'];
$key = array_search($markerShape, $shapes);
if (false === $key) {
die('This shape is not available');
}
return $key;
}
function getMarkerColor(string $markerColor): int
{
$colors = ['red', 'orangedark', 'orange', 'yellow', 'bluedark', 'blue', 'cyan', 'purple', 'violet', 'pink', 'greendark', 'green', 'greenlight', 'black', 'white'];
$key = array_search($markerColor, $colors);
if (false === $key) {
die('This color is not available');
}
return $key;
}