From c9a742ff83903babd768073c483c7e85f99c4045 Mon Sep 17 00:00:00 2001 From: "Fedor A. Fetisov" Date: Thu, 10 May 2018 02:05:54 +0300 Subject: [PATCH] Switch to OSM service Rename the plugin and replace proprietary Google Maps service with Open Street Map --- Plugin.php | 51 ++++++++++++-------------------------------------- README.md | 26 ++++++------------------- bower.json | 5 +++-- css/styles.css | 4 ++-- gulpfile.js | 10 ++++++---- js/plugin.js | 30 ++++++++++++++--------------- package.json | 2 +- 7 files changed, 44 insertions(+), 84 deletions(-) diff --git a/Plugin.php b/Plugin.php index 566387b..55ff25b 100644 --- a/Plugin.php +++ b/Plugin.php @@ -1,8 +1,8 @@ . + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,10 @@ */ /** - * @file The main file of Mibew:GoogleMaps plugin. + * @file The main file of Mibew:OpenStreetMap plugin. */ -namespace Mibew\Mibew\Plugin\GoogleMaps; +namespace Mibew\Mibew\Plugin\OpenStreetMap; use Mibew\Asset\AssetManagerInterface; use Mibew\EventDispatcher\EventDispatcher; @@ -29,26 +29,18 @@ use Mibew\EventDispatcher\Events; use Mibew\Plugin\PluginManager; /** - * Provides an ability to view visitors at Google Maps. + * Provides an ability to view visitors on Open Street Map. */ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\PluginInterface { /** * Class constructor. * - * @param array $config List of the plugin config. The following options are - * supported: - * - 'api_key': string, Google Maps API key that should be used to render - * maps. + * @param array $config List of the plugin config. + * */ public function __construct($config) { - if (empty($config['api_key'])) { - trigger_error('Google API key cannot be empty', E_USER_WARNING); - - return; - } - parent::__construct($config); $this->initialized = true; } @@ -67,14 +59,14 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi /** * A handler for {@link \Mibew\EventDispatcher\Events::USERS_FUNCTION_CALL}. * - * Provides an ability to use "googleMapsGetInfo" function at the client + * Provides an ability to use "openStreetMapGetInfo" function at the client * side. * * @see \Mibew\EventDispatcher\Events::USERS_FUNCTION_CALL */ public function usersFunctionCallHandler(&$function) { - if ($function['function'] == 'googleMapsGetInfo') { + if ($function['function'] == 'openStreetMapGetInfo') { // An IP string can contain more than one IP address. For example it // can be something like this: "x.x.x.x (x.x.x.x)". We need to // use only first one. @@ -111,10 +103,7 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi { if ($args['request']->attributes->get('_route') == 'users') { $args['js'][] = $this->getFilesPath() . '/vendor/jquery-colorbox/jquery.colorbox-min.js'; - $args['js'][] = array( - 'content' => $this->getApiUrl(), - 'type' => AssetManagerInterface::ABSOLUTE_URL, - ); + $args['js'][] = $this->getFilesPath() . '/vendor/leaflet/dist/leaflet.js'; $args['js'][] = $this->getFilesPath() . '/js/plugin.js'; } } @@ -128,6 +117,7 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi { if ($args['request']->attributes->get('_route') == 'users') { $args['css'][] = $this->getFilesPath() . '/vendor/jquery-colorbox/example3/colorbox.css'; + $args['css'][] = $this->getFilesPath() . '/vendor/leaflet/dist/leaflet.css'; $args['css'][] = $this->getFilesPath() . '/css/styles.css'; } } @@ -137,7 +127,7 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi */ public static function getVersion() { - return '1.1.0'; + return '0.1.0'; } /** @@ -147,21 +137,4 @@ class Plugin extends \Mibew\Plugin\AbstractPlugin implements \Mibew\Plugin\Plugi { return array('Mibew:GeoIp' => '1.*'); } - - /** - * Builds URL for Google Maps API. - * - * @return string API URL - * @throws \RuntimeException if API key was not set correctly. - */ - protected function getApiUrl() - { - if (empty($this->config['api_key'])) { - throw new \RuntimeException('Google API key cannot be empty'); - } - - return '//maps.googleapis.com/maps/api/js?key=' - . $this->config['api_key'] - . '&sensor=false'; - } } diff --git a/README.md b/README.md index 92a832b..2e12edf 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,22 @@ -# Google Maps plugin +# Open Street Map plugin -It shows your clients' location at Google maps! +Based upon the code of [Mibew Google Maps plugin](https://github.com/Mibew/google-maps-plugin). +Displays a visitor's location using Open Street Map service. ## Installation -1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-google-maps) or build the plugin from sources. +1. Get the archive with the plugin sources. You can download it from the [official site](https://mibew.org/plugins#mibew-open-street-map) or build the plugin from sources. 2. Untar/unzip the plugin's archive. 3. Put files of the plugins to the `/plugins` folder. -4. Add plugins configs to "plugins" structure in "``/configs/config.yml". If the "plugins" stucture looks like `plugins: []` it will become: - ```yaml - plugins: - "Mibew:GoogleMaps": # Plugin's configurations are described below - api_key: "secret API key provided by Google" - ``` - -5. Navigate to "``/operator/plugin" page and enable the plugin. - +4. Navigate to "``/operator/plugin" page and enable the plugin. ## Plugin's configurations -The plugin can be configured with values in "``/configs/config.yml" file. - -### config.api_key - -Type: `String` - -Google Maps API key that will be used to render maps. You can learn how to get the key [here](https://developers.google.com/maps/documentation/javascript/tutorial#api_key). - +This plugin does not require any configuration. ## Build from sources diff --git a/bower.json b/bower.json index 014c623..d5167e5 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,8 @@ { - "name": "google-maps-plugin", + "name": "open-street-map-plugin", "private": true, "dependencies": { - "jquery-colorbox": "~1.5.14" + "jquery-colorbox": "~1.5.14", + "leaflet": "~1.3.1" } } diff --git a/css/styles.css b/css/styles.css index 3545080..ae85007 100644 --- a/css/styles.css +++ b/css/styles.css @@ -1,7 +1,7 @@ /* - * This file is a part of Mibew Google Maps Plugin. + * This file is a part of Mibew Open Street Map Plugin. * - * Copyright 2014 Dmitriy Simushev . + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/gulpfile.js b/gulpfile.js index 4cd93b0..093f04a 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,9 +23,9 @@ gulp.task('prepare-release', ['bower'], function() { return eventStream.merge( getSources() - .pipe(zip('google-maps-plugin-' + version + '.zip')), + .pipe(zip('open-street-map-plugin-' + version + '.zip')), getSources() - .pipe(tar('google-maps-plugin-' + version + '.tar')) + .pipe(tar('open-street-map-plugin-' + version + '.tar')) .pipe(gzip()) ) .pipe(chmod(0644)) @@ -51,11 +51,13 @@ var getSources = function() { 'css/*', 'vendor/jquery-colorbox/README.md', 'vendor/jquery-colorbox/jquery.colorbox-min.js', - 'vendor/jquery-colorbox/example3/**/*' + 'vendor/jquery-colorbox/example3/**/*', + 'vendor/leaflet/dist/leaflet.*', + 'vendor/leaflet/dist/images/*', ], {base: './'} ) .pipe(rename(function(path) { - path.dirname = 'Mibew/Mibew/Plugin/GoogleMaps/' + path.dirname; + path.dirname = 'Mibew/Mibew/Plugin/OpenStreetMap/' + path.dirname; })); } diff --git a/js/plugin.js b/js/plugin.js index e4019bd..e92c932 100644 --- a/js/plugin.js +++ b/js/plugin.js @@ -1,7 +1,7 @@ /*! - * This file is a part of Mibew Google Maps Plugin. + * This file is a part of Mibew Open Street Map Plugin. * - * Copyright 2014 Dmitriy Simushev . + * Copyright 2014-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ * limitations under the License. */ -(function (Mibew, $, google) { +(function (Mibew, $, L) { /** * Display popup with a map and a marker on it. * @@ -35,17 +35,15 @@ $.colorbox({ html: $canvas, onComplete: function() { - var position = new google.maps.LatLng(latitude, longitude), - map = new google.maps.Map($canvas.get(0), { - center: position, - zoom: (city ? 8 : 6), - mapTypeId: google.maps.MapTypeId.ROADMAP - }), - marker = new google.maps.Marker({ - map: map, - position: position, - title: city ? (city + ' (' + country + ')') : country - }); + var map = L.map('map-canvas', { + center: [latitude, longitude], + zoom: 9 + }); + var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; + var osmAttrib='Map data © OpenStreetMap contributors'; + var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 19, attribution: osmAttrib}); + map.addLayer(osm); + L.marker([latitude, longitude]).addTo(map).bindPopup('' + city + ', ' + country + '').openPopup(); } }); } @@ -64,7 +62,7 @@ if (ip) { server.callFunctions( [{ - 'function': 'googleMapsGetInfo', + 'function': 'openStreetMapGetInfo', 'arguments': { 'agentId': agentId, 'ip': ip, @@ -126,4 +124,4 @@ } ); -})(Mibew, jQuery, google); +})(Mibew, jQuery, L); diff --git a/package.json b/package.json index a662e84..da98e0b 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.1.0", + "version": "0.1.0", "devDependencies": { "bower": "~1.3.12", "gulp": "~3.8.10",