Skip to content

Commit

Permalink
feat: Setting to prevent Google Maps auto load.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDanielczok committed Jun 5, 2018
1 parent cafe782 commit e158dc4
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 21 deletions.
3 changes: 3 additions & 0 deletions bricks.xml
Expand Up @@ -617,6 +617,9 @@
</description>

<settings>
<setting name="preventLoadMap" type="checkbox">
<locale group="quiqqer/bricks" var="brick.control.simplegooglemaps.settings.preventLoadMap"/>
</setting>
<setting name="place">
<locale group="quiqqer/bricks" var="brick.control.simplegooglemaps.settings.place"/>
</setting>
Expand Down
8 changes: 8 additions & 0 deletions locale.xml
Expand Up @@ -942,6 +942,10 @@ M&ouml;chten Sie die Bausteine aus der Bausteinzone entfernen?</p>]]></de>
<pl><![CDATA[Ustawienia mapy]]></pl>
</locale>

<locale name="brick.control.simplegooglemaps.settings.preventLoadMap">
<de><![CDATA[Das automatische Laden von Google Maps verhindern. Der Benutzer muss sie manuell aktivieren.]]></de>
<en><![CDATA[Prevent auto-load Google Maps. User must activate it manually.]]></en>
</locale>
<locale name="brick.control.simplegooglemaps.settings.place">
<de><![CDATA[Google Place]]></de>
<en><![CDATA[Google Place]]></en>
Expand Down Expand Up @@ -977,6 +981,10 @@ M&ouml;chten Sie die Bausteine aus der Bausteinzone entfernen?</p>]]></de>
<en><![CDATA[API Key]]></en>
<pl><![CDATA[Klucz API]]></pl>
</locale>
<locale name="brick.control.simplegooglemaps.frontend.buttonShow">
<de><![CDATA[Google Maps aktivieren]]></de>
<en><![CDATA[Enable Google Maps]]></en>
</locale>

<!-- Box Content -->
<locale name="bricks.BoxContent.title">
Expand Down
26 changes: 23 additions & 3 deletions src/QUI/Bricks/Controls/SimpleGoogleMaps.css
@@ -1,14 +1,34 @@
.simpleGoogleMap {
position: relative;
height: 100%;

min-height: 300px;
display: flex;
justify-content: center;
align-items: stretch;
}

.simpleGoogleMap-iframe {
background: none;
border: none;
display: block;
height: 100%;
min-height: 300px;
height: auto;
position: relative;
width: 100%;
}
}

.btn-active-map {
align-self: center;
color: #333;
border-color: #333;
background: none;
font-size: 1.2rem;
background-position: center;
background-size: cover;
}

.btn-active-map:hover,
.btn-active-map:active{
color: #333;
background: #33333311;
}
2 changes: 2 additions & 0 deletions src/QUI/Bricks/Controls/SimpleGoogleMaps.html
Expand Up @@ -11,5 +11,7 @@ <h1>{$this->getAttribute('frontendTitle')}</h1>
{/if}

<div class="simpleGoogleMap">
{if !$preventLoadMap}
<iframe class="simpleGoogleMap-iframe" src="{$url}"></iframe>
{/if}
</div>
47 changes: 29 additions & 18 deletions src/QUI/Bricks/Controls/SimpleGoogleMaps.php
Expand Up @@ -20,20 +20,19 @@ class SimpleGoogleMaps extends QUI\Control
*
* @param array $attributes
*/
public function __construct($attributes = array())
public function __construct($attributes = [])
{
// default options
$this->setAttributes(array(
'title' => ''
));
$this->setAttributes([
'title' => '',
'preventLoadMap' => false
]);

parent::__construct($attributes);

$this->addCSSFile(
dirname(__FILE__) . '/SimpleGoogleMaps.css'
);

// $this->setAttribute('qui-class', "package/quiqqer/bricks/bin/Controls/SimpleGoogleMaps");
}

/**
Expand All @@ -43,28 +42,40 @@ public function __construct($attributes = array())
*/
public function getBody()
{
$Engine = QUI::getTemplateManager()->getEngine();
$brickPlace = $this->getAttribute('place');
$brickZip = $this->getAttribute('zip');
$brickStreet = $this->getAttribute('street');
$brickCity = $this->getAttribute('city');
$zoom = $this->getAttribute('zoom');
$Engine = QUI::getTemplateManager()->getEngine();
$brickPlace = $this->getAttribute('place');
$brickZip = $this->getAttribute('zip');
$brickStreet = $this->getAttribute('street');
$brickCity = $this->getAttribute('city');
$zoom = $this->getAttribute('zoom');
$preventLoadMap = $this->getAttribute('preventLoadMap');
$imgUrl = '';

if (!$zoom) {
$zoom = 15;
}

$query = http_build_query(array(
$query = http_build_query([
'key' => trim($this->getAttribute('api')),
'q' => "{$brickPlace},{$brickZip},{$brickStreet},{$brickCity}"
));
]);

$url = 'https://www.google.com/maps/embed/v1/place?' . $query . "&zoom=" . $zoom;
if ($preventLoadMap) {
$imgUrl = URL_OPT_DIR . 'quiqqer/bricks/bin/images/SimpleGoogleMapsBackground1.png';

$this->setAttributes([
'qui-class' => "package/quiqqer/bricks/bin/Controls/SimpleGoogleMaps",
'data-qui-url' => $url,
'data-qui-imgUrl' => $imgUrl
]);
}

$Engine->assign(array(
'this' => $this,
'url' => $url
));
$Engine->assign([
'this' => $this,
'url' => $url,
'preventLoadMap' => $preventLoadMap
]);

return $Engine->fetch(dirname(__FILE__) . '/SimpleGoogleMaps.html');
}
Expand Down

0 comments on commit e158dc4

Please sign in to comment.