Ejemplo n.º 1
0
    public function map_url()
    {
        // parse settings
        $settings = $this->parseParameters();
        
        // we need to set auto_center to false, here's why:
        // this tag will only ever place one marker on the map, and because of
        // the situation, we'll always know its latitude and longitude; by not
        // setting auto_center to false, starting_zoom no longer works (as the
        // auto_center function will try to determine the best zoom within the
        // allowed min_zoom and max_zoom); setting this to false allows users
        // to start using starting_zoom again without having to worry about any
        // automagic stuff taking over and wrestling away control
        $settings['auto_center'] = 'false';
        
        $content_set = ContentService::getContentAsContentSet($settings['url']);
        
        // supplement
        $content_set->supplement(array(
            'locate_with'     => $settings['locate_with'],
            'center_point'    => $settings['center_point'],
            'pop_up_template' => $this->content
        ));

        // re-filter, we only want entries that have been found
        $content_set->filter(array('located' => true));
        $content = $content_set->get();

        // no results? no results.
        if (!count($content)) {
            return Parse::template($this->content, array('no_results' => true));
        }
        
        // check for valid center point
        if (!preg_match(Pattern::COORDINATES, $settings['center_point'], $matches)) {
            if (
                $settings['locate_with'] && 
                isset($content[0][$settings['locate_with']]) && 
                is_array($content[0][$settings['locate_with']]) &&
                isset($content[0][$settings['locate_with']]['latitude']) &&
                isset($content[0][$settings['locate_with']]['longitude'])
            ) {
                $settings['starting_latitude'] = $content[0][$settings['locate_with']]['latitude'];
                $settings['starting_longitude'] = $content[0][$settings['locate_with']]['longitude'];
            }
        } else {
            $settings['starting_latitude']  = $matches[1];
            $settings['starting_longitude'] = $matches[2];
        }
        
        // other overrides
        $settings['clusters'] = 'false';
        
        return $this->buildScript($content, $settings);
    }