Skip to content

Commit

Permalink
Switch to OSM service
Browse files Browse the repository at this point in the history
Rename the plugin and replace proprietary Google Maps service with Open Street Map
  • Loading branch information
faf committed May 9, 2018
1 parent d6bdee1 commit c9a742f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 84 deletions.
51 changes: 12 additions & 39 deletions Plugin.php
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,37 +18,29 @@
*/

/**
* @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;
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;
}
Expand All @@ -67,14 +59,14 @@ public function run()
/**
* 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.
Expand Down Expand Up @@ -111,10 +103,7 @@ public function pageAddJsHandler(&$args)
{
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';
}
}
Expand All @@ -128,6 +117,7 @@ public function pageAddCssHandler(&$args)
{
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';
}
}
Expand All @@ -137,7 +127,7 @@ public function pageAddCssHandler(&$args)
*/
public static function getVersion()
{
return '1.1.0';
return '0.1.0';
}

/**
Expand All @@ -147,21 +137,4 @@ public static function getDependencies()
{
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';
}
}
26 changes: 6 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 3 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
4 changes: 2 additions & 2 deletions css/styles.css
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 6 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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;
}));
}
30 changes: 14 additions & 16 deletions js/plugin.js
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -16,7 +16,7 @@
* limitations under the License.
*/

(function (Mibew, $, google) {
(function (Mibew, $, L) {
/**
* Display popup with a map and a marker on it.
*
Expand All @@ -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();
}
});
}
Expand All @@ -64,7 +62,7 @@
if (ip) {
server.callFunctions(
[{
'function': 'googleMapsGetInfo',
'function': 'openStreetMapGetInfo',
'arguments': {
'agentId': agentId,
'ip': ip,
Expand Down Expand Up @@ -126,4 +124,4 @@
}
);

})(Mibew, jQuery, google);
})(Mibew, jQuery, L);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.1.0",
"version": "0.1.0",
"devDependencies": {
"bower": "~1.3.12",
"gulp": "~3.8.10",
Expand Down

0 comments on commit c9a742f

Please sign in to comment.