~brian-killermonk/yiigeo/trunk

« back to all changes in this revision

Viewing changes to libraries/Result.php

  • Committer: Brian Armstrong
  • Date: 2009-12-03 05:57:13 UTC
  • Revision ID: brian@killermonk.com-20091203055713-hctptucu3s10lpfq
Adding ability to render mutliple results to a single map

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        private $_driver = null;
40
40
 
41
41
        /**
 
42
         * Holds the types of the containers that have maps in them
 
43
         * @var array
 
44
         */
 
45
        private static $_map_containers = array();
 
46
 
 
47
        /**
 
48
         * The number of maps we have rendered
 
49
         * @var integer
 
50
         */
 
51
        private static $_map_count = 0;
 
52
 
 
53
        /**
 
54
         * The number of points we have rendered
 
55
         * @var integer
 
56
         */
 
57
        private static $_point_count = 0;
 
58
 
 
59
        /**
42
60
         * The attributes array to hold all of our data
43
61
         * @var array
44
62
         */
133
151
         */
134
152
        public function renderMap($container_id, $options = array(), $type = null)
135
153
        {
136
 
                // Get the type for this if it was not sent
137
 
                if ($type === null) $type = $this->_driver->getDriverName();
138
 
                // Lowercase the map type
139
 
                $type = strtolower($type);
140
 
 
 
154
                if (!isset(self::$_map_containers[$container_id]))
 
155
                {
 
156
                        // Get the type for this if it was not sent
 
157
                        if ($type === null) $type = $this->_driver->getDriverName();
 
158
                        // Lowercase the map type
 
159
                        $type = strtolower($type);
 
160
 
 
161
                        // Save the container id and the type
 
162
                        self::$_map_containers[$container_id] = $type;
 
163
 
 
164
                        // Render the view
 
165
                        $map_script = $this->render("{$type}/map", array(
 
166
                                'query' => $this->query,
 
167
                                'latitude' => $this->latitude,
 
168
                                'longitude' => $this->longitude,
 
169
                                'container_id' => $container_id,
 
170
                                'options' => $options
 
171
                        ), true);
 
172
 
 
173
                        // Register the javascript
 
174
                        Yii::app()->getClientScript()->registerScript("{$type}_map_js".(self::$_map_count++), $map_script, CClientScript::POS_READY);
 
175
                }
 
176
 
 
177
                // Render the map point
 
178
                $this->renderPoint($this->latitude, $this->longitude, $container_id, $this->clean_query);
 
179
        }
 
180
 
 
181
        /**
 
182
         * Render a point on the map. By default it will render the points associated
 
183
         * with the result in the last used container with the last used type. Make sure
 
184
         * that you have already made a call to render map with the given container_id
 
185
         *
 
186
         * @param float $lat
 
187
         * @param float $lon
 
188
         * @param string $container_id
 
189
         * @param string $description
 
190
         */
 
191
        public function renderPoint($lat, $lon, $container_id, $description=null)
 
192
        {
 
193
                // Validate the container
 
194
                if (!isset(self::$_map_containers[$container_id]))
 
195
                        throw new GeoCode_Exception("Unknown map container '{$container_id}'");
 
196
 
 
197
                // Get our type
 
198
                $type = self::$_map_containers[$container_id];
141
199
                // Render the view
142
 
                $map_script = $this->render("{$type}_map", array(
143
 
                        'query' => $this->clean_query,
144
 
                        'latitude' => $this->latitude,
145
 
                        'longitude' => $this->longitude,
146
 
                        'container_id' => $container_id,
147
 
                        'options' => $options
 
200
                $point_script = $this->render("{$type}/point", array(
 
201
                        'query' => $description,
 
202
                        'latitude' => ($lat === null) ? $this->latitude : $lat,
 
203
                        'longitude' => ($lon === null) ? $this->longitude : $lon,
148
204
                ), true);
149
205
 
150
206
                // Register the javascript
151
 
                Yii::app()->getClientScript()->registerScript("{$type}_map_js", $map_script, CClientScript::POS_READY);
 
207
                Yii::app()->clientScript->registerScript("{$type}_point_js".(self::$_point_count++), $point_script, CClientScript::POS_READY);
152
208
        }
153
209
 
154
210
        /**