jenkins-bot has submitted this change and it was merged.
Change subject: add google map service
......................................................................
add google map service
Change-Id: Ie661162f4e6cb82d283ead5bee1214310b70332b
---
M MultiMaps.body.php
M MultiMaps.php
M Settings.php
A services/Google/Google.php
A services/Google/ext.google.js
5 files changed, 286 insertions(+), 6 deletions(-)
Approvals:
Pastakhov: Verified; Looks good to me, approved
jenkins-bot: Verified
diff --git a/MultiMaps.body.php b/MultiMaps.body.php
index 8e7a304..2ac2fe5 100644
--- a/MultiMaps.body.php
+++ b/MultiMaps.body.php
@@ -20,10 +20,15 @@
$params = func_get_args();
array_shift( $params );
- $service = MultiMapsServices::getServiceInstance(
- 'showmap',
- isset($params['service']) ? $params['service']
: null
- );
+ $nameService = null;
+ $matches = array();
+ foreach ($params as $value) {
+ if( preg_match('/^\s*service\s*=(.+)$/si', $value,
&$matches) ) {
+ $nameService = strtolower($matches[1]);
+ break;
+ }
+ }
+ $service = MultiMapsServices::getServiceInstance( 'showmap',
$nameService );
if( !($service instanceof \MultiMaps\BaseService) ) {
if( is_string($service) ) {
diff --git a/MultiMaps.php b/MultiMaps.php
index 5344802..082724f 100644
--- a/MultiMaps.php
+++ b/MultiMaps.php
@@ -81,6 +81,15 @@
'group' => 'ext.MultiMaps',
);
+// Google service
+$wgAutoloadClasses["MultiMaps\Google"] = $dir . '/services/Google/Google.php';
+$wgResourceModules['ext.MultiMaps.Google'] = array(
+ 'scripts' => array( 'ext.google.js' ),
+ 'localBasePath' => $dir . '/services/Google',
+ 'remoteExtPath' => 'MultiMaps/services/Google',
+ 'group' => 'ext.MultiMaps',
+ );
+
/**
* Add files to phpunit test
* @codeCoverageIgnore
diff --git a/Settings.php b/Settings.php
index 24d057e..b99e6d0 100644
--- a/Settings.php
+++ b/Settings.php
@@ -25,8 +25,8 @@
// key - string, class name based on class \MultiMaps\BaseService
// value - string or array, service name for using in parameters
$egMultiMapsServices_showmap = array(
- "Leaflet" => "leaflet",
- //'googlemaps',
+ 'Leaflet' => 'leaflet',
+ 'Google' => 'google',
//'yandexmaps',
);
diff --git a/services/Google/Google.php b/services/Google/Google.php
new file mode 100644
index 0000000..55ecea9
--- /dev/null
+++ b/services/Google/Google.php
@@ -0,0 +1,31 @@
+<?php
+namespace MultiMaps;
+/**
+ * This groupe contains all Google related files of the MultiMaps extension.
+ *
+ * @defgroup Google
+ * @ingroup MultiMaps
+ */
+
+/**
+ *
+ *
+ * @file Google.php
+ * @ingroup Google
+ *
+ * @licence GNU GPL v2+
+ * @author Pavel Astakhov < [email protected] >
+ */
+class Google extends BaseService {
+
+ function __construct() {
+ parent::__construct();
+ $this->classname="google";
+ $this->resourceModules[] = 'ext.MultiMaps.Google';
+
+ $urlArgs = array();
+ $urlArgs['sensor'] = 'false';
+ $this->headerItem .= \Html::linkedScript(
'http://maps.googleapis.com/maps/api/js?'.wfArrayToCgi($urlArgs) ) . "\n";
+ }
+
+}
\ No newline at end of file
diff --git a/services/Google/ext.google.js b/services/Google/ext.google.js
new file mode 100644
index 0000000..5a6621f
--- /dev/null
+++ b/services/Google/ext.google.js
@@ -0,0 +1,235 @@
+/**
+ * JavaScript for Leaflet in the MultiMaps extension.
+ * @see http://www.mediawiki.org/wiki/Extension:MultiMaps
+ *
+ * @author Pavel Astakhov < [email protected] >
+ */
+
+(function ($, mw) {
+ $.fn.multimapsgoogle = function ( options ) {
+ var _this = this;
+ this.map = null;
+ this.options = options;
+
+ /**
+ * Convert properties given from multimaps extension to options
of map element
+ * @param {Object} properties Contains the fields lat, lon,
title, text and icon
+ * @return {Object} options of map element
+ */
+ this.convertPropertiesToGoogleOptions = function (properties) {
+ var options = {};
+
+ if( properties.icon !== undefined ) {
+ options.icon = new L.Icon({
+ iconUrl: properties.icon
+ });
+ }
+ if( properties.color !== undefined ) {
+ options.strokeColor = properties.color;
+ }
+ if( properties.weight !== undefined ) {
+ options.strokeWeight = properties.weight;
+ }
+ if( properties.opacity !== undefined ) {
+ options.strokeOpacity = properties.opacity;
+ }
+ if( properties.fill !== undefined ) {
+ options.fill = properties.fill;
+ }
+ if( properties.fillcolor !== undefined ) {
+ options.fillColor = properties.fillcolor;
+ }
+ if( properties.fillopacity !== undefined ) {
+ options.fillOpacity = properties.fillopacity;
+ }
+
+ var text = false;
+ if( properties.title !== undefined && properties.text
!== undefined ) {
+ options.title = properties.title;
+ text = '<strong>' + properties.title +
'</strong><hr />' + properties.text;
+ } else if( properties.title !== undefined ) {
+ options.title = properties.title;
+ text = '<strong>' + properties.title +
'</strong>';
+ } else if( properties.text !== undefined ) {
+ text = properties.text;
+ }
+
+ return { options:options, text:text };
+ };
+
+ /**
+ * Creates a new marker with the provided data,
+ * adds it to the map, and returns it.
+ * @param {Object} properties Contains the fields lat, lon,
title, text and icon
+ * @param {String} icon Global value for all icons
+ */
+ this.addMarker = function (properties, icon) {
+ if( icon ) {
+ if( !properties.icon ) {
+ properties.icon = icon;
+ }
+ }
+ var value =
this.convertPropertiesToGoogleOptions(properties);
+ value.options.position = new
google.maps.LatLng(properties.pos[0].lat, properties.pos[0].lon);
+ value.options.map = this.map;
+
+ var marker = new google.maps.Marker( value.options );
+
+ if( value.text ) {
+ var infowindow = new google.maps.InfoWindow({
content: value.text });
+ google.maps.event.addListener(marker, 'click',
function() {
+ infowindow.open(marker.get('map'),
marker);
+ });
+ }
+ };
+
+ this.addLine = function (properties) {
+ var value =
this.convertPropertiesToGoogleOptions(properties);
+
+ var latlngs = [];
+ for (var x = 0; x < properties.pos.length; x++) {
+ latlngs.push( new
google.maps.LatLng(properties.pos[x].lat, properties.pos[x].lon) );
+ }
+ value.options.path = latlngs;
+ value.options.map = this.map;
+
+ var polyline = new google.maps.Polyline(value.options);
+ if( value.text ) {
+ var infowindow = new google.maps.InfoWindow({
content: value.text });
+ google.maps.event.addListener(polyline,
'click', function() {
+ infowindow.open(polyline.get('map'),
polyline);
+ });
+ }
+ };
+
+ this.addPolygon = function (properties) {
+ var value =
this.convertPropertiesToGoogleOptions(properties);
+
+ var latlngs = [];
+ for (var x = 0; x < properties.pos.length; x++) {
+ latlngs.push( new
google.maps.LatLng(properties.pos[x].lat, properties.pos[x].lon) );
+ }
+ value.options.paths = latlngs;
+ value.options.map = this.map;
+
+ var polygon = new google.maps.Polygon(value.options);
+ if( value.text ) {
+ var infowindow = new google.maps.InfoWindow({
content: value.text });
+ google.maps.event.addListener(polygon, 'click',
function() {
+ infowindow.open(polygon.get('map'),
polygon);
+ });
+ }
+ };
+
+ this.addCircle = function (properties) {
+ var value =
this.convertPropertiesToGoogleOptions(properties);
+
+ value.options.center = new
google.maps.LatLng(properties.pos[0].lat, properties.pos[0].lon);
+ value.options.radius = properties.radius[0];
+ value.options.map = this.map;
+ var circle = new google.maps.Circle(value.options);
+ if( value.text ) {
+ var infowindow = new google.maps.InfoWindow({
content: value.text });
+ google.maps.event.addListener(circle, 'click',
function() {
+ infowindow.open(circle.get('map'),
circle);
+ });
+ }
+ };
+
+ this.addRectangle = function (properties) {
+ var value =
this.convertPropertiesToGoogleOptions(properties);
+
+ var bounds = new google.maps.LatLngBounds ();
+ bounds.extend( new
google.maps.LatLng(properties.pos[0].lat, properties.pos[0].lon) );
+ bounds.extend( new
google.maps.LatLng(properties.pos[1].lat, properties.pos[1].lon) );
+ value.options.bounds = bounds;
+ value.options.map = this.map;
+
+ var rectangle = new google.maps.Rectangle(
value.options );
+ if( value.text ) {
+ var infowindow = new google.maps.InfoWindow({
content: value.text });
+ google.maps.event.addListener(rectangle,
'click', function() {
+ infowindow.open(rectangle.get('map'),
rectangle);
+ });
+ }
+ };
+
+ this.setup = function () {
+
+ var mapOptions = {
+ center: new google.maps.LatLng(0, 0),
+ zoom: 1,
+ mapTypeId: google.maps.MapTypeId.ROADMAP
+ };
+ if (options.minzoom !== false ) mapOptions.minZoom =
options.minzoom;
+ if (options.maxzoom !== false ) mapOptions.maxZoom =
options.maxzoom;
+
+ var map = new google.maps.Map( this.get(0),
mapOptions); //.fitWorld();
+
+ this.map = map;
+
+ if (options.resizable) {
+ mw.loader.using('ext.maps.resizable', function
() {
+ _this.resizable();
+ });
+ }
+
+ // Add the markers.
+ for (var im in options.markers) {
+ this.addMarker( options.markers[im],
options.icon );
+ }
+
+ // Add lines
+ for (var il in options.lines) {
+ this.addLine(options.lines[il]);
+ }
+
+ // Add polygons
+ for (var ip in options.polygons) {
+ this.addPolygon(options.polygons[ip]);
+ }
+
+ // Add circles
+ for (var ic in options.circles) {
+ this.addCircle(options.circles[ic]);
+ }
+
+ // Add rectangles
+ for (var ir in options.rectangles) {
+ this.addRectangle(options.rectangles[ir]);
+ }
+
+ // Set map position (centre and zoom)
+ if( options.bounds ) {
+ map.fitBounds( new google.maps.LatLngBounds(
+ new
google.maps.LatLng(options.bounds.sw.lat, options.bounds.sw.lon),
+ new
google.maps.LatLng(options.bounds.ne.lat, options.bounds.ne.lon)
+ ) );
+ } else {
+ if( options.center ) {
+ map.setCenter( new
google.maps.LatLng(options.center.lat, options.center.lon) );
+ map.setZoom( options.zoom );
+ } else if ( options.zoom ) {
+ map.setZoom( options.zoom );
+ }
+ }
+ };
+
+ this.setup();
+
+ return this;
+
+ };
+})(jQuery, window.mediaWiki);
+
+(function( $, mw ) {
+
+ $( document ).ready( function() {
+
+ $( '.multimaps-map-google' ).each( function() {
+ var $this = $( this );
+ $this.multimapsgoogle( $.parseJSON(
$this.find('div').text() ) );
+ } );
+ } );
+
+})( window.jQuery, mediaWiki );
--
To view, visit https://gerrit.wikimedia.org/r/49614
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie661162f4e6cb82d283ead5bee1214310b70332b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultiMaps
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <[email protected]>
Gerrit-Reviewer: Pastakhov <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits