Skip to content

Commit

Permalink
Re add image overlay support
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenDeDauw committed Jun 14, 2014
1 parent bc7e67a commit 574093d
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Maps.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,8 @@
$wgParamDefinitions['wmsoverlay'] = array(
'string-parser' => 'Maps\WmsOverlayParser',
);

$wgParamDefinitions['mapsimageoverlay'] = array(
'string-parser' => 'Maps\ImageOverlayParser',
);
} );
1 change: 1 addition & 0 deletions docs/RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ These are the release notes for the [Maps extension](../README.md).
* Removed support for the deprecated Google JavaScript API
* Updated the translations to use the new MediaWiki JSON format
* Re added support for fill color and fill opacity parameters for circles
* Re added image overlay support for Google Maps

## Maps 3.0.1

Expand Down
47 changes: 47 additions & 0 deletions includes/parsers/ImageOverlayParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Maps;

use Maps\Elements\ImageOverlay;
use Maps\Elements\WmsOverlay;
use ValueParsers\GeoCoordinateParser;
use ValueParsers\ParseException;
use ValueParsers\StringValueParser;

/**
* @since 3.1
*
* @licence GNU GPL v2+
* @author Jeroen De Dauw < [email protected] >
*/
class ImageOverlayParser extends StringValueParser {

/**
* @since 3.1
*
* @param string $value
*
* @return WmsOverlay
* @throws ParseException
*/
protected function stringParse( $value ) {
$parameters = explode( '~', $value );
$imageParameters = explode( ':', $parameters[0], 3 );

if ( count( $imageParameters ) === 3 ) {
$boundsNorthEast = $this->stringToLatLongValue( $imageParameters[0] );
$boundsSouthWest = $this->stringToLatLongValue( $imageParameters[1] );
$imageUrl = \MapsMapper::getFileUrl( $imageParameters[2] );

return new ImageOverlay( $boundsNorthEast, $boundsSouthWest, $imageUrl );
}

throw new ParseException( 'Need 3 parameters for an image overlay' );
}

private function stringToLatLongValue( $location ) {
$parser = new GeoCoordinateParser( new \ValueParsers\ParserOptions() );
return $parser->parse( $location );
}

}
7 changes: 3 additions & 4 deletions includes/services/GoogleMaps3/Maps_GoogleMaps3.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,11 @@ public function addParameterInfo( array &$params ) {
);

$params['imageoverlays'] = array(
'type' => 'integer',
'type' => 'mapsimageoverlay',
'default' => array(),
'message' => 'maps-googlemaps3-par-imageoverlays',
'islist' => true,
'delimiter' => ';',
// new MapsParamImageOverlay('~') FIXME
'islist' => true,
'message' => 'maps-googlemaps3-par-imageoverlays',
);

$params['kml'] = array(
Expand Down
24 changes: 19 additions & 5 deletions src/Maps/Elements/ImageOverlay.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
class ImageOverlay extends Rectangle {

/**
* @since 3.0
*
* @var string
*/
protected $image;
private $imageUrl;

/**
* Constructor.
Expand All @@ -39,7 +37,7 @@ public function __construct( LatLongValue $boundsNorthEast, LatLongValue $bounds
}

parent::__construct( $boundsNorthEast, $boundsSouthWest );
$this->image = $image;
$this->imageUrl = $image;
}

/**
Expand All @@ -48,7 +46,23 @@ public function __construct( LatLongValue $boundsNorthEast, LatLongValue $bounds
* @return string
*/
public function getImage() {
return $this->image;
return $this->imageUrl;
}

/**
* @since 3.0
*
* @param string $defText
* @param string $defTitle
*
* @return array
*/
public function getJSONObject( $defText = '' , $defTitle = '' ) {
$data = parent::getJSONObject( $defText , $defTitle );

$data['image'] = $this->imageUrl;

return $data;
}

}
1 change: 0 additions & 1 deletion src/Maps/Elements/Rectangle.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public function setRectangleNorthEast( LatLongValue $rectangleNorthEast ) {
* @return array
*/
public function getJSONObject( $defText = '' , $defTitle = '' ) {

$parentArray = parent::getJSONObject( $defText , $defTitle );
$array = array(
'ne' => array(
Expand Down

0 comments on commit 574093d

Please sign in to comment.