2amigos / yii2-leaflet-extension

Yii 2 Extension library to display interactive maps with Leaflet .
http://yiiwheels.com
Other
30 stars 26 forks source link

Make it possible to omit the height CSS property from the inline CSS #23

Closed Okeanos closed 8 years ago

Okeanos commented 8 years ago

The Map widget will currently inject a height CSS property with a value of 200px into the output by default. The only possible setting here is to enter a different numerical value by providing it in the echo $leaflet->widget(['height' => '500']) call. Values are always interpreted as pixel values (Map, lines 60 and 64). This makes it impossible to generate maps with a relative height or otherwise provide a height value with an external stylesheet by omitting the definition from the widget entirely.

A possible solution would be to remove the px constant from the property, thus allowing different scales, and doing a null check before assigning the height to the style output and only assign it if any value has been set, thus allowing external height definitions for the widget.

class Map extends Widget {
    // ...
    public function init()
    {
        if ($inlineStyles) {
            // remove any height properties from the inline styles to prevent duplicates in the result; $this->height takes precedent and will be used
            $inlineStyles = preg_replace('/height\:([ \t])*\d*\w+;?/', '', $inlineStyles);
            $styles = explode(';', $inlineStyles);
            $styles[] = null !== $this->height ? "height:{$this->height}" : null;
            $this->options['style'] = implode(";", array_filter($styles));
        } else {
            // @codeCoverageIgnoreStart
            if(null !== $this->height) {
                $this->options['style'] = "height:{$this->height};";
            }
            // @codeCoverageIgnoreEnd
        }
    }
    // ..
}
tonydspaniard commented 8 years ago

:+1:

tonydspaniard commented 8 years ago

It fixed by version tag 1.0.2