Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Others;
defined('_JEXEC') or die;
use TechFry\Library\View\Sky\Bootstrap;
use TechFry\Library\TResource;
use TechFry\Library\View\Html\TfHtml;
class Map extends Bootstrap
{
// Open Street Map and Leaflet JS - Latitude, Longitude, Marker Text
public function display()
{
// data - latitude, longitude (either as CSV or Array)
// config - height, zoom
if (empty($this->data))
{
return;
}
if (\is_string($this->data))
{
$arr = str_getcsv($this->data);
$map['latitude'] = $arr[0];
$map['longitude'] = $arr[1];
}
else
{
$map = $this->data;
}
$height = $this->config['height'] ?? '300';
$zoom = $this->config['zoom'] ?? '13';
$output = '<div id="map" style="height:' . $height . 'px"></div>';
$script = 'var map = L.map(\'map\').setView([' . $map['latitude'] . ', ' . $map['longitude'] . '], ' . $zoom . ');';
$script .= 'L.tileLayer(\'https://tile.openstreetmap.org/{z}/{x}/{y}.png\', {
maxZoom: 19,
attribution: \'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>\'
}).addTo(map);';
$script .= 'var marker = L.marker([' . $map['latitude'] . ', ' . $map['longitude'] . ']).addTo(map);';
$output .= TfHtml::get_js($script);
$r = new TResource();
// Add CSS
$css_url = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';
$r->add_resource('style', 'leaflet.css', $css_url);
// Add javaScript
$js_url = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
$r->add_resource('script', 'leaflet.js', $js_url);
return $output;
}
// Depriciated
public static function get_output($item, $config = array())
{
// item - latitude, longitude (either as CSV or Array)
// config - height, zoom
if (empty($item))
{
return;
}
if (\is_string($item))
{
$arr = str_getcsv($item);
$map['latitude'] = $arr[0];
$map['longitude'] = $arr[1];
}
else
{
$map = $item;
}
$output = '<div id="map" style="height:' . $config['height'] . 'px"></div>';
$script = 'var map = L.map(\'map\').setView([' . $map['latitude'] . ', ' . $map['longitude'] . '], ' . $config['zoom'] . ');';
$script .= 'L.tileLayer(\'https://tile.openstreetmap.org/{z}/{x}/{y}.png\', {
maxZoom: 19,
attribution: \'© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>\'
}).addTo(map);';
$script .= 'var marker = L.marker([' . $map['latitude'] . ', ' . $map['longitude'] . ']).addTo(map);';
$output .= TfHtml::get_js($script);
$r = new TResource();
// Add CSS
$css_url = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.css';
$r->add_resource('style', 'leaflet.css', $css_url);
// Add javaScript
$js_url = 'https://unpkg.com/leaflet@1.9.4/dist/leaflet.js';
$r->add_resource('script', 'leaflet.js', $js_url);
return $output;
}
}