forked from vfremaux/moodle-block_dashboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgooglemap.php
216 lines (206 loc) · 7.28 KB
/
googlemap.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle 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 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* GoogleMap iframe wrapper
*
* @package block_dashboard
* @category blocks
* @author Valery Fremaux ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @version Moodle 1.9
*/
require('../../config.php');
$courseid = required_param('id', PARAM_INT);
// Security.
if ($courseid != SITEID) {
if (!$course = $DB->get_record('course', array('id' => "$courseid"))) {
print_error('invalidcourseid');
}
require_login($course);
}
$options = stripslashes(urldecode(required_param('options', PARAM_TEXT)));
$lat = optional_param('lat', 0, PARAM_TEXT);
$lng = optional_param('lng', 0, PARAM_TEXT);
$mapid = 'map_'.required_param('mapid', PARAM_TEXT);
$markers = optional_param('markers', PARAM_TEXT); // Array of markers
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var latlng = new google.maps.LatLng(<?php echo $lat ?>, <?php echo $lng ?>);
var myOptions = <?php echo $options ?>;
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
map.setOptions({styles: administrative});
for (i = 0; i < mks ; i++){
marker[i].setMap(map);
}
}
<?php
$markerimages = glob ($CFG->dataroot.'/'.$course->id.'/blockdata/dashboard/all/mk_*.png');
$hasshadow = array();
if (!empty($markerimages)) {
foreach ($markerimages as $im) {
$imname = basename($im, '.png');
$shadowimname = str_replace('mk_', 'sh_', $imname);
$classname = str_replace('mk_', '', $imname);
$sizeinfo = getimagesize($im);
$imfullpath = $CFG->wwwroot."/file.php/{$course->id}/blockdata/dashboard/all/{$imname}.png";
echo "var image{$classname} = new google.maps.MarkerImage(\"$imfullpath\", new google.maps.Size({$sizeinfo[0]}, {$sizeinfo[1]}), new google.maps.Point(0, 0),new google.maps.Point(10, {$sizeinfo[1]}));\n";
$shadowimagepath = $CFG->dataroot."/{$course->id}/blockdata/dashboard/all/{$shadowimname}.png";
if (file_exists($shadowimagepath)) {
$sizeinfo = getimagesize($shadowimagepath);
// Todo reform to new pluginfile.php file wrapper
$shadowfullpath = $CFG->wwwroot."/file.php/{$course->id}/blockdata/dashboard/all/{$shadowimname}.png";
echo "var shadow{$classname} = new google.maps.MarkerImage(\"$shadowfullpath\", new google.maps.Size({$sizeinfo[0]}, {$sizeinfo[1]}), new google.maps.Point(0, 0),new google.maps.Point(10, {$sizeinfo[1]}));\n";
$hasshadow[$classname] = true;
} else {
$hasshadow[$classname] = false;
}
}
}
?>
/*
var imagecertif = new google.maps.MarkerImage("pix/of1.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var shadowcertif = new google.maps.MarkerImage("pix/of1_sh.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var imagefc = new google.maps.MarkerImage("pix/of2.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var shadowfc = new google.maps.MarkerImage("pix/of2_sh.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var imagecertiffoad = new google.maps.MarkerImage("pix/of1_foad.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var shadowcertiffoad = new google.maps.MarkerImage("pix/of1_foad_sh.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var imagefcfoad = new google.maps.MarkerImage("pix/of2_foad.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var shadowfcfoad = new google.maps.MarkerImage("pix/of2_foad_sh.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(10, 39));
var imagehq = new google.maps.MarkerImage("pix/hq.png", new google.maps.Size(13, 27), new google.maps.Point(0, 0),new google.maps.Point(5, 27));
var shadowhq = new google.maps.MarkerImage("pix/hq_sh.png", new google.maps.Size(40, 39), new google.maps.Point(0, 0),new google.maps.Point(5, 27));
*/
var latlngmarks = new Array();
var marker = new Array();
var mks = 0;
<?php
if (!empty($markers)) {
foreach ($markers as $amarker) {
$amarkerobj = json_decode(stripslashes(urldecode($amarker)));
?>
// 48.020587,0.151405
latlngmarks[mks] = new google.maps.LatLng(<?php echo $amarkerobj->lat ?>, <?php echo $amarkerobj->lng ?>);
marker[mks] = new google.maps.Marker({
position: latlngmarks[mks],
title:"<?php echo $amarkerobj->title ?>",
<?php
if (!empty($amarkerobj->markerclass)) {
if (@$hasshadow[$amarkerobj->markerclass]) {
?>
shadow:shadow<?php echo $amarkerobj->markerclass ?>,
<?php
}
?>
icon:image<?php echo $amarkerobj->markerclass ?>
<?php
}
?>
});
mks++;
<?php
}
}
?>
var administrative = [
{
featureType: "all",
stylers: [
{ saturation: -40 }
]
},
{
featureType: "administrative",
stylers: [
{ hue: "#1300FF" },
{ saturation: 80 }
]
},
{
featureType: "road.highway",
stylers: [
{ gamma: "4.0" }
]
},
{
featureType: "road.local",
stylers: [
{ visibility: "off" }
]
},
{
featureType: "road.arterial",
stylers: [
{ gamma: "5.0" }
]
},
{
featureType: "poi",
stylers: [
{ visibility: "off" }
]
},
{
featureType: "transit",
stylers: [
{ visibility: "off" }
]
},
{
featureType: "landscape.natural",
stylers: [
{ visibility: "off" }
]
},
{
featureType: "landscape.man_made",
stylers: [
{ hue: "#FF4000" },
{ saturation: 80 }
]
},
{
featureType: "administrative.country",
stylers: [
{ hue: "#1300FF" },
{ saturation: 80 }
]
},
{
featureType: "administrative.province",
stylers: [
{ hue: "#00B9FF" },
{ saturation: 70 }
]
}
];
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>