<commit_before><?php

namespace Ivory\GoogleMapBundle\Templating\Helper;

use Ivory\GoogleMapBundle\Model\Marker;
use Ivory\GoogleMapBundle\Model\Map;

/**
 * Marker helper allows easy rendering
 *
 * @author GeLo <<EMAIL>>
 */
class MarkerHelper
{
    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\CoordinateHelper
     */
    protected $coordinateHelper;

    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\InfoWindowHelper
     */
    protected $infoWindowHelper;
    
    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\MarkerImageHelper
     */
    protected $markerImageHelper;

    /**
     * Constructs a marker helper
     *
     * @param Ivory\GoogleMapBundle\Templating\Helper\CoordinateHelper $coordinateHelper
     * @param Ivory\GoogleMapBundle\Templating\Helper\InfoWindowHelper $infoWindowHelper
     * @param Ivory\GoogleMapBundle\Templating\Helper\MarkerImageHelper $markerImageHelper
     */
    public function __construct(CoordinateHelper $coordinateHelper, InfoWindowHelper $infoWindowHelper, MarkerImageHelper $markerImageHelper)
    {
        $this->coordinateHelper = $coordinateHelper;
        $this->infoWindowHelper = $infoWindowHelper;
        $this->markerImageHelper = $markerImageHelper;
    }
    
    /**
     * Renders the marker
     *
     * @param string $googleMapJavascriptVariable
     * @param Ivory\GoogleMapBundle\Model\Marker $marker
     * @return string HTML output
     */
    public function render(Marker $marker, Map $map)
    {
        $markerJSONOptions = sprintf('{"map":%s,"position":%s',
            $map->getJavascriptVariable(),
            $this->coordinateHelper->render($marker->getPosition())
        );
        
        $markerOptions = $marker->getOptions();

        if($marker->hasIcon())
        {
            if($marker->getIcon() instanceof MarkerImage)
                $markerJSONOptions .= ', "icon":'.$this->markerImageHelper->render($marker->getIcon());
            else
                $markerOptions['icon'] = $marker->getIcon();
        }

        if($marker->hasShadow())
            $markerOptions['shadow'] = $marker->getShadow();

        if(!empty($markerOptions))
            $markerJSONOptions .= ','.substr(json_encode($markerOptions), 1);
        else
            $markerJSONOptions .= '}';

        $html = array();

        $html[] = sprintf('var %s = new google.maps.Marker(%s);'.PHP_EOL,
            $marker->getJavascriptVariable(),
            $markerJSONOptions
        );

        if($marker->hasInfoWindow())
        {
            $html[] = $this->infoWindowHelper->render($marker->getInfoWindow(), false);
            
            if($marker->getInfoWindow()->isOpen())
                $html[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map);
        }

        return implode('', $html);
    }
}<commit_msg>Fix bug in marker image rendering<commit_after><?php

namespace Ivory\GoogleMapBundle\Templating\Helper;

use Ivory\GoogleMapBundle\Model\Marker;
use Ivory\GoogleMapBundle\Model\Map;

/**
 * Marker helper allows easy rendering
 *
 * @author GeLo <<EMAIL>>
 */
class MarkerHelper
{
    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\CoordinateHelper
     */
    protected $coordinateHelper;

    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\InfoWindowHelper
     */
    protected $infoWindowHelper;
    
    /**
     * @var Ivory\GoogleMapBundle\Templating\Helper\MarkerImageHelper
     */
    protected $markerImageHelper;

    /**
     * Constructs a marker helper
     *
     * @param Ivory\GoogleMapBundle\Templating\Helper\CoordinateHelper $coordinateHelper
     * @param Ivory\GoogleMapBundle\Templating\Helper\InfoWindowHelper $infoWindowHelper
     * @param Ivory\GoogleMapBundle\Templating\Helper\MarkerImageHelper $markerImageHelper
     */
    public function __construct(CoordinateHelper $coordinateHelper, InfoWindowHelper $infoWindowHelper, MarkerImageHelper $markerImageHelper)
    {
        $this->coordinateHelper = $coordinateHelper;
        $this->infoWindowHelper = $infoWindowHelper;
        $this->markerImageHelper = $markerImageHelper;
    }
    
    /**
     * Renders the marker
     *
     * @param string $googleMapJavascriptVariable
     * @param Ivory\GoogleMapBundle\Model\Marker $marker
     * @return string HTML output
     */
    public function render(Marker $marker, Map $map)
    {
        $html = array();
        
        $markerJSONOptions = sprintf('{"map":%s,"position":%s',
            $map->getJavascriptVariable(),
            $this->coordinateHelper->render($marker->getPosition())
        );
        
        $markerOptions = $marker->getOptions();

        if($marker->hasIcon())
        {
            if($marker->getIcon() instanceof MarkerImage)
            {
                $html[] = $this->markerImageHelper->render($marker->getIcon());
                $markerJSONOptions .= ', "icon":'.$marker->getIcon()->getJavascriptVariable();
            }
            else
                $markerOptions['icon'] = $marker->getIcon();
        }

        if($marker->hasShadow())
            $markerOptions['shadow'] = $marker->getShadow();

        if(!empty($markerOptions))
            $markerJSONOptions .= ','.substr(json_encode($markerOptions), 1);
        else
            $markerJSONOptions .= '}';

        $html[] = sprintf('var %s = new google.maps.Marker(%s);'.PHP_EOL,
            $marker->getJavascriptVariable(),
            $markerJSONOptions
        );

        if($marker->hasInfoWindow())
        {
            $html[] = $this->infoWindowHelper->render($marker->getInfoWindow(), false);
            
            if($marker->getInfoWindow()->isOpen())
                $html[] = $this->infoWindowHelper->renderOpen($marker->getInfoWindow(), $map);
        }

        return implode('', $html);
    }
}
{'fraction_non_alphanumeric': 0.13548276453438518, 'fraction_numerical': 0.0003429943405933802, 'mean_word_length': 2.5845113706207745, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3291066', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1591, 'n_words': 245}