r83357 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83356‎ | r83357 | r83358 >
Date:02:10, 6 March 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
follow up to r83356
Modified paths:
  • /branches/SemanticMaps0.8/SM_Settings.php (modified) (history)
  • /branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php (modified) (history)

Diff [purge]

Index: branches/SemanticMaps0.8/SM_Settings.php
@@ -38,6 +38,8 @@
3939 # Commenting or removing a mapping service will cause Semantic Maps to completely ignore it, and so improve performance.
4040 # Google Maps API v2
4141 include_once $smgDir . 'includes/services/GoogleMaps/SM_GoogleMaps.php';
 42+ # Google Maps API v3
 43+ include_once $smgDir . 'includes/services/GoogleMaps3/SM_GoogleMaps3.php';
4244 # OpenLayers API
4345 include_once $smgDir . 'includes/services/OpenLayers/SM_OpenLayers.php';
4446 # Yahoo! Maps API
Index: branches/SemanticMaps0.8/includes/queryprinters/SM_MapPrinter.php
@@ -68,7 +68,7 @@
6969 $this->service->addParameterInfo( $parameterInfo );
7070
7171 $validator = new Validator( $this->getName(), false );
72 - $validator->setParameters( $mapProperties, $parameterInfo );
 72+ $validator->setParameters( $params, $parameterInfo );
7373 $validator->validateParameters();
7474
7575 $fatalError = $validator->hasFatalError();
@@ -95,12 +95,16 @@
9696 public final function getResultText( /* SMWQueryResult */ $res, $outputmode ) {
9797 if ( $this->fatalErrorMsg !== false ) {
9898 global $wgParser;
99 - $mapName = $this->service->getMapId();
10099
101 - $queryHandler = SMQueryHandler( $res, $outputmode, $this->parameters );
102 - $locations = $queryHandler->getLocations();
 100+ $params = $this->parameters;
103101
104 - return $this->getMapHTML( $this->parameters, $wgParser, $mapName ) . $this->getJSON( $this->parameters, $wgParser, $mapName );
 102+ $queryHandler = new SMQueryHandler( $res, $outputmode, $params );
 103+
 104+ $this->handleMarkerData( $params, $queryHandler->getLocations() );
 105+
 106+ $mapName = $this->service->getMapId();
 107+
 108+ return $this->getMapHTML( $params, $wgParser, $mapName ) . $this->getJSON( $params, $wgParser, $mapName );
105109 }
106110 else {
107111 return $this->fatalErrorMsg;
@@ -146,65 +150,33 @@
147151 }
148152
149153 /**
150 - * Adds the static locations (specified via the staticlocations parameter) to the map.
 154+ * Converts the data in the coordinates parameter to JSON-ready objects.
 155+ * These get stored in the locations parameter, and the coordinates on gets deleted.
151156 *
152 - * TODO
 157+ * @since 0.8
153158 *
154 - * @since 0.7
 159+ * @param array &$params
 160+ * @param array $queryLocations
155161 */
156 - protected function addStaticLocations() {
 162+ protected function handleMarkerData( array &$params, array $queryLocations ) {
157163 global $wgTitle;
158 -
159 - // New parser object to render popup contents with.
 164+
160165 $parser = new Parser();
161 -
162 - $this->title = $parser->parse( $this->title, $wgTitle, new ParserOptions() )->getText();
163 - $this->label = $parser->parse( $this->label, $wgTitle, new ParserOptions() )->getText();
164 -
165 - // Each $location is an array containg the coordinate set as first element, possibly followed by meta data.
166 - foreach ( $this->staticlocations as $location ) {
167 - $markerData = MapsCoordinateParser::parseCoordinates( array_shift( $location ) );
168 -
169 - if ( !$markerData ) continue;
170 -
171 - $markerData = array( $markerData['lat'], $markerData['lon'] );
172 -
173 - if ( count( $location ) > 0 ) {
174 - // Parse and add the point specific title if it's present.
175 - $markerData['title'] = $parser->parse( $location[0], $wgTitle, new ParserOptions() )->getText();
 166+ $iconUrl = MapsMapper::getImageUrl( $params['icon'] );
 167+ $params['locations'] = array();
 168+
 169+ foreach ( array_merge( $params['coordinates'], $queryLocations ) as $location ) {
 170+ if ( $location->isValid() ) {
 171+ $jsonObj = $location->getJSONObject( $params['title'], $params['label'], $iconUrl );
176172
177 - if ( count( $location ) > 1 ) {
178 - // Parse and add the point specific label if it's present.
179 - $markerData['label'] = $parser->parse( $location[1], $wgTitle, new ParserOptions() )->getText();
180 -
181 - if ( count( $location ) > 2 ) {
182 - // Add the point specific icon if it's present.
183 - $markerData['icon'] = $location[2];
184 - }
185 - }
 173+ $jsonObj['title'] = strip_tags( $parser->parse( $jsonObj['title'], $wgTitle, new ParserOptions() )->getText() );
 174+ $jsonObj['text'] = $parser->parse( $jsonObj['text'], $wgTitle, new ParserOptions() )->getText();
 175+
 176+ $params['locations'][] = $jsonObj;
186177 }
187 -
188 - // If there is no point specific icon, use the general icon parameter when available.
189 - if ( !array_key_exists( 'icon', $markerData ) ) {
190 - $markerData['icon'] = $this->icon;
191 - }
192 -
193 - if ( $markerData['icon'] != '' ) {
194 - $markerData['icon'] = MapsMapper::getImageUrl( $markerData['icon'] );
195 - }
196 -
197 - // Temporary fix, will refactor away later
198 - // TODO
199 - $markerData = array_values( $markerData );
200 - if ( count( $markerData ) < 5 ) {
201 - if ( count( $markerData ) < 4 ) {
202 - $markerData[] = '';
203 - }
204 - $markerData[] = '';
205 - }
206 -
207 - $this->locations[] = $markerData;
208 - }
 178+ }
 179+
 180+ unset( $params['coordinates'] );
209181 }
210182
211183 /**

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r83356matching changes in mapsjeroendedauw02:00, 6 March 2011

Status & tagging log