From cec7d43591ce479629a23bd46a59355dcfe80e06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20S=CC=8Ckoda?= Date: Sun, 19 Aug 2012 19:52:35 +0200 Subject: [PATCH] MDL-34959 add Google Maps API V3 support --- admin/settings/location.php | 3 ++- iplookup/index.php | 16 ++++++++++++++-- iplookup/module.js | 18 ++++++++++++++++++ lang/en/admin.php | 2 ++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/admin/settings/location.php b/admin/settings/location.php index 3d3ccb83a6b..9f74d519bb0 100644 --- a/admin/settings/location.php +++ b/admin/settings/location.php @@ -14,7 +14,8 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page $temp->add(new admin_setting_heading('iplookup', new lang_string('iplookup', 'admin'), new lang_string('iplookupinfo', 'admin'))); $temp->add(new admin_setting_configfile('geoipfile', new lang_string('geoipfile', 'admin'), new lang_string('configgeoipfile', 'admin', $CFG->dataroot.'/geoip/'), $CFG->dataroot.'/geoip/GeoLiteCity.dat')); - $temp->add(new admin_setting_configtext('googlemapkey', new lang_string('googlemapkey', 'admin'), new lang_string('configgooglemapkey', 'admin', $CFG->wwwroot), '')); + $temp->add(new admin_setting_configtext('googlemapkey', new lang_string('googlemapkey', 'admin'), new lang_string('configgooglemapkey', 'admin', $CFG->wwwroot), '', PARAM_RAW, 60)); + $temp->add(new admin_setting_configtext('googlemapkey3', new lang_string('googlemapkey3', 'admin'), new lang_string('googlemapkey3_help', 'admin'), '', PARAM_RAW, 60)); $temp->add(new admin_setting_configtext('allcountrycodes', new lang_string('allcountrycodes', 'admin'), new lang_string('configallcountrycodes', 'admin'), '', '/^(?:\w+(?:,\w+)*)?$/')); diff --git a/iplookup/index.php b/iplookup/index.php index e876e8f2641..40ec4c5ce62 100644 --- a/iplookup/index.php +++ b/iplookup/index.php @@ -80,7 +80,7 @@ $PAGE->set_title(get_string('iplookup', 'admin').': '.$title); $PAGE->set_heading($title); echo $OUTPUT->header(); -if (empty($CFG->googlemapkey)) { +if (empty($CFG->googlemapkey) and empty($CFG->googlemapkey3)) { $imgwidth = 620; $imgheight = 310; $dotwidth = 18; @@ -95,11 +95,23 @@ if (empty($CFG->googlemapkey)) { echo ''; echo '
'.$info['note'].'
'; -} else { +} else if (empty($CFG->googlemapkey3)) { $PAGE->requires->js(new moodle_url("http://maps.google.com/maps?file=api&v=2&key=$CFG->googlemapkey")); $module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js'); $PAGE->requires->js_init_call('M.core_iplookup.init', array($info['latitude'], $info['longitude']), true, $module); + echo '
'; + echo '
'.$info['note'].'
'; + +} else { + if (strpos($CFG->wwwroot, 'https:') === 0) { + $PAGE->requires->js(new moodle_url('https://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false'))); + } else { + $PAGE->requires->js(new moodle_url('http://maps.googleapis.com/maps/api/js', array('key'=>$CFG->googlemapkey3, 'sensor'=>'false'))); + } + $module = array('name'=>'core_iplookup', 'fullpath'=>'/iplookup/module.js'); + $PAGE->requires->js_init_call('M.core_iplookup.init3', array($info['latitude'], $info['longitude'], $ip), true, $module); + echo '
'; echo '
'.$info['note'].'
'; } diff --git a/iplookup/module.js b/iplookup/module.js index dba71cc4158..004b7d24706 100644 --- a/iplookup/module.js +++ b/iplookup/module.js @@ -41,3 +41,21 @@ M.core_iplookup.init = function(Y, latitude, longitude) { }, document.body); } }; + +M.core_iplookup.init3 = function(Y, latitude, longitude, ip) { + var ipLatlng = new google.maps.LatLng(latitude, longitude); + + var mapOptions = { + center: ipLatlng, + zoom: 6, + mapTypeId: google.maps.MapTypeId.ROADMAP + }; + + var map = new google.maps.Map(document.getElementById("map"), mapOptions); + + var marker = new google.maps.Marker({ + position: ipLatlng, + map: map, + title: ip + }); +}; diff --git a/lang/en/admin.php b/lang/en/admin.php index a3af926eb78..75d531e1a58 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -547,6 +547,8 @@ $string['globalswarning'] = '

SECURITY WARNING!

To ope $string['groupenrolmentkeypolicy'] = 'Group enrolment key policy'; $string['groupenrolmentkeypolicy_desc'] = 'Turning this on will make Moodle check group enrolment keys against a valid password policy.'; $string['googlemapkey'] = 'Google Maps API V2 key'; +$string['googlemapkey3'] = 'Google Maps API V3 key'; +$string['googlemapkey3_help'] = 'You need to enter a special key to use Google Maps for IP address lookup visualization. You can obtain the key free of charge at https://developers.google.com/maps/documentation/javascript/tutorial#api_key'; $string['gotofirst'] = 'Go to first missing string'; $string['gradebook'] = 'Gradebook'; $string['gradebookroles'] = 'Graded roles'; -- 2.43.0