-
Notifications
You must be signed in to change notification settings - Fork 1
/
OpenstreetmapEmbedder.class.php
71 lines (63 loc) · 2.47 KB
/
OpenstreetmapEmbedder.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* Copyright (c) 2012 Rasmus Fuhse <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
class OpenstreetmapEmbedder extends StudIPPlugin implements SystemPlugin {
public function __construct()
{
parent::__construct();
StudipFormat::addStudipMarkup("osmap", "\[osmap(.*?)\]", "\[\/osmap\]", "OpenstreetmapEmbedder::createMap");
PageLayout::addHeadElement('script', array('type' => "text/javascript", 'src' => $this->getPluginURL()."/assets/khtml_all.js"), '');
}
public static function createMap($markup, $matches, $adress)
{
$id = "map_".uniqid();
$params = explode(":", $matches[1]);
foreach ($params as $param) {
if ($param) {
if (is_numeric($param)) {
$width = floor($param);
}
}
}
$width > 0 || $width = 400;
$height = floor($width * 3 / 4);
list($latitude, $longitude, $zoom, $marker_text) = explode(";", $adress);
if ($marker_text) {
$marker = 'var marker = new khtml.maplib.overlay.Marker({
position: new khtml.maplib.LatLng('.(double) $latitude.','.(double) $longitude.'),
map: map'.
($marker_text ? ', title:"'.htmlReady($marker_text).'"' : "") .'
});
map.addOverlay(marker);';
}
$output = sprintf(
'<style>#%s > div:not(:first-child) {display: none;} </style>'.
'<div id="%s" style="width: %spx; height: %spx; border: 1px solid black;"></div>' .
'<script>
jQuery(function () {
map=new khtml.maplib.base.Map(document.getElementById("%s"));
map.centerAndZoom(new khtml.maplib.LatLng(%s,%s),%s);
var zoombar=new khtml.maplib.ui.Zoombar();
map.addOverlay(zoombar);
%s
});
</script>',
$id,
$id,
$width,
$height,
$id,
(double) $latitude,
(double) $longitude,
(int) $zoom,
$marker
);
return str_replace("\n", "", $output);
}
}