Switch to OSM service

Rename the plugin and replace proprietary Google Maps service with Open Street Map
This commit is contained in:
Fedor A. Fetisov 2018-05-10 02:05:54 +03:00
parent d6bdee1536
commit c9a742ff83
7 changed files with 44 additions and 84 deletions

View File

@ -1,8 +1,8 @@
<?php
/*
* 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 <simushevds@gmail.com>.
* 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';
}
}

View File

@ -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 `<Mibew root>/plugins` folder.
4. Add plugins configs to "plugins" structure in "`<Mibew root>`/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 "`<Mibew Base URL>`/operator/plugin" page and enable the plugin.
4. Navigate to "`<Mibew Base URL>`/operator/plugin" page and enable the plugin.
## Plugin's configurations
The plugin can be configured with values in "`<Mibew root>`/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

View File

@ -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"
}
}

View File

@ -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 <simushevds@gmail.com>.
* 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.

View File

@ -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;
}));
}

View File

@ -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 <simushevds@gmail.com>.
* 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 © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 19, attribution: osmAttrib});
map.addLayer(osm);
L.marker([latitude, longitude]).addTo(map).bindPopup('<strong>' + city + ', ' + country + '</strong>').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);

View File

@ -1,5 +1,5 @@
{
"version": "1.1.0",
"version": "0.1.0",
"devDependencies": {
"bower": "~1.3.12",
"gulp": "~3.8.10",