Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for inline styles #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,19 @@ class Map {
*/
private $places = false;

/**
* Styles flag
*
* @var bool
*/
private $styles = false;
/**
* Json array containing inline styling
*
* @var string json
*/
private $inline_style = '';

/**
* Autocomplete input id
*
Expand Down Expand Up @@ -690,6 +703,9 @@ public function __construct( array $options=null ) {
case 'places_autocomplete':
$this->enablePlacesAutocomplete( $option_val );
break;
case 'styles':
$this->inlineStyle($option_val);
break;

}
}
Expand Down Expand Up @@ -1797,6 +1813,9 @@ function getMapJS() {

$output = sprintf( "var %s;\nfunction phpgooglemap_%s() {\n\nthis.initialize = function() {\n\n", $this->map_id, $this->map_id );
$output .= "\tvar self = this;\n";

if($this->styles) $output.="\n\tvar inline_style = $this->inline_style\n\n";

$output .= "\tthis.map_options = {\n";
$output .= sprintf("\t\tzoom: %s,\n", $this->zoom );

Expand All @@ -1809,6 +1828,9 @@ function getMapJS() {
if ( !$this->draggable ) {
$output .= "\t\tdraggable: false,\n";
}
if ( $this->styles ) {
$output .= "\t\tstyles: inline_style,\n";
}

$output .= sprintf( "\t\tnavigationControl: %s,\n", $this->phpToJs( $this->navigation_control ) );
$output .= sprintf( "\t\tmapTypeControl: %s,\n", $this->phpToJs( $this->map_type_control ) );
Expand Down Expand Up @@ -2463,4 +2485,16 @@ function enablePlacesAutocomplete( array $options = array() ) {
}
}

/**
* Inline Style
*
* Add JSON array of styling to map options
*
* @param string $json variable with style var
*/
function inlineStyle($json) {
$this->styles = true;
$this->inline_style = $json;
}

}