Changeset 1408
- Timestamp:
- Sep 25, 2010, 6:31:38 PM (10 years ago)
- Location:
- cpc/trunk/project
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
cpc/trunk/project/apps/frontend/config/routing.yml
r1385 r1408 164 164 url: /circonscription/image/:circo/:w/:h 165 165 param: {module: circonscription, action: getCircoimagepng} 166 deptmts_image_png: 167 url: /circonscription/cartedepts/:w/:h 168 param: {module: circonscription, action: getDeptmtsimagepng} 166 169 redirect_parlementaires_circo: 167 170 url: /circonscription/:code -
cpc/trunk/project/apps/frontend/modules/circonscription/actions/actions.class.php
r1300 r1408 149 149 * If only one of $w and $h is given, preserve the svg ratio. 150 150 */ 151 private static function compute_areas($dom, $w, $h, $regexp )151 private static function compute_areas($dom, $w, $h, $regexp, $deptitle = 0) 152 152 { 153 153 $areas = ""; … … 177 177 $cs = self::compose_transform($path); 178 178 $points = self::convert_path($path->getAttribute('d'), $cs, $ratio_w, $ratio_h); 179 $title = self::get_title($path); 180 $href = url_for("@redirect_parlementaires_circo?code=".$path->getAttribute('id')); 181 $areas .= "<area href=\"".$href."\" title=\"".$title."\" ". 179 if ($deptitle) { 180 $title = $path->getAttribute('title'); 181 $id = preg_replace('/d/', '', $path->getAttribute('id')); 182 $href = url_for("@list_parlementaires_circo_search?search=$id"); 183 } else { 184 $id = $path->getAttribute('id'); 185 $title = self::get_title($path); 186 $href = url_for("@redirect_parlementaires_circo?code=".$path->getAttribute('id')); 187 } 188 $areas .= "<area id=\"map$id\" href=\"".$href."\" title=\"".$title."\" ". 182 189 "shape=\"poly\" coords=\"".$points."\"></area>\n"; 183 190 } … … 229 236 } 230 237 231 232 private static function generateSvgDom($circo, $w, $h) 233 { 238 private static function generateSvgDep($w, $h) { 234 239 $dom = new DOMDocument(); 235 240 $dom->preserveWhiteSpace = FALSE; 236 241 // FIXME Use loadXML to load from a string instead (database) 237 $dom->load("circo.svg"); 238 239 if(preg_match("/^\d\d[\dab]$/",$circo)) 240 self::crop_svg($dom, "/^$circo-\d\d$/", 10); 241 242 $dom->load("france_deptmts.svg"); 242 243 return $dom; 243 244 } 245 246 /* $circo is a three digits string, or "full" for the full map */ 247 public static function echoCircoMap($circo, $w, $h) 248 { 249 $dom = self::generateSvgDom($circo, $w, $h); 250 251 if($circo == "full") 252 $regexp = "/^\d\d[\dab]-(0[1-9]|[1-9]\d)$/"; 253 else 254 $regexp = "/^$circo-(0[1-9]|[1-9]\d)$/"; 255 256 $r = self::compute_areas($dom, $w, $h, $regexp); 244 } 245 246 public static function echoDeptmtsMap($w, $h) { 247 $dom = self::generateSvgDep($w, $h); 248 $r = self::compute_areas($dom, $w, $h, '/^d\d+/', 1); 257 249 $w = $r['w']; 258 250 $h = $r['h']; 259 251 260 $src = url_for("@ circo_image_png?circo=$circo&w=$w&h=$h");261 262 echo "<img class=\"carte_departement\" src=\"$src\" usemap=\"# $circo\" ";252 $src = url_for("@deptmts_image_png?w=$w&h=$h"); 253 254 echo "<img class=\"carte_departement\" src=\"$src\" usemap=\"#deptmts\" "; 263 255 echo 'style="width:'.$w.'px; height:'.$h.'px;" />'; 264 echo "<map name=\" $circo\">";256 echo "<map name=\"deptmts\">"; 265 257 echo $r['areas']; 266 258 echo "</map>"; 267 259 } 268 260 269 /* $circo is a three digits string, or "full" for the full map */ 270 private static function echoCircoImage($circo, $w, $h) 271 { 272 273 /* If you want to resize a vector-graphics image (such as SVG) to a 274 * certain dimension in pixels, without losing quality, you have to do 275 * this 276 * http://www.php.net/manual/en/function.imagick-setresolution.php 277 */ 278 279 $dom = self::generateSvgDom($circo, $w, $h); 261 private static function echoDeptmtsImage($w, $h) { 262 $dom = self::generateSvgDep($w, $h); 280 263 281 264 $im = new Imagick(); … … 290 273 $im->setImageFormat("png"); 291 274 echo $im; 275 } 276 277 private static function generateSvgDom($circo, $w, $h) 278 { 279 $dom = new DOMDocument(); 280 $dom->preserveWhiteSpace = FALSE; 281 // FIXME Use loadXML to load from a string instead (database) 282 $dom->load("circo.svg"); 283 284 if(preg_match("/^\d\d[\dab]$/",$circo)) 285 self::crop_svg($dom, "/^$circo-\d\d$/", 10); 286 287 return $dom; 288 289 } 290 291 /* $circo is a three digits string, or "full" for the full map */ 292 public static function echoCircoMap($circo, $w, $h) 293 { 294 $dom = self::generateSvgDom($circo, $w, $h); 295 296 if($circo == "full") 297 $regexp = "/^\d\d[\dab]-(0[1-9]|[1-9]\d)$/"; 298 else 299 $regexp = "/^$circo-(0[1-9]|[1-9]\d)$/"; 300 301 $r = self::compute_areas($dom, $w, $h, $regexp); 302 $w = $r['w']; 303 $h = $r['h']; 304 305 $src = url_for("@circo_image_png?circo=$circo&w=$w&h=$h"); 306 307 echo "<img class=\"carte_departement\" src=\"$src\" usemap=\"#$circo\" "; 308 echo 'style="width:'.$w.'px; height:'.$h.'px;" />'; 309 echo "<map name=\"$circo\">"; 310 echo $r['areas']; 311 echo "</map>"; 312 } 313 314 /* $circo is a three digits string, or "full" for the full map */ 315 private static function echoCircoImage($circo, $w, $h) 316 { 317 318 /* If you want to resize a vector-graphics image (such as SVG) to a 319 * certain dimension in pixels, without losing quality, you have to do 320 * this 321 * http://www.php.net/manual/en/function.imagick-setresolution.php 322 */ 323 324 $dom = self::generateSvgDom($circo, $w, $h); 325 326 $im = new Imagick(); 327 $im->readImageBlob($dom->saveXML()); 328 $res = $im->getImageResolution(); 329 $x_ratio = $res['x'] / $im->getImageWidth(); 330 $y_ratio = $res['y'] / $im->getImageHeight(); 331 $im->removeImage(); 332 $im->setResolution($w * $x_ratio, $h * $y_ratio); 333 $im->readImageBlob($dom->saveXML()); 334 335 $im->setImageFormat("png"); 336 echo $im; 337 } 338 339 public function executeGetDeptmtsimagepng(sfWebRequest $request) { 340 $w = $request->getParameter('w'); 341 $h = $request->getParameter('h'); 342 header("Content-type: image/png"); 343 self::echoDeptmtsImage($w, $h); 344 return sfView::NONE; 292 345 } 293 346 -
cpc/trunk/project/apps/frontend/modules/circonscription/templates/listSuccess.php
r1396 r1408 1 <h1 class="list_inter">Toutes les circonscriptions par département</h1><?php1 <h1>Toutes les circonscriptions par département</h1><?php 2 2 $sf_response->setTitle('Toutes les circonscriptions électorales par département - NosDéputés.fr'); ?> 3 3 <?php // CirconscriptionActions::echoCircoMap("full", 900, 0); ?> … … 12 12 } ?> 13 13 </div> 14 <?php echo include_partial('circonscription/mapDeptmts', array()); ?>14 <?php CirconscriptionActions::echoDeptmtsMap(600, 546); ?> 15 15 <div class="list_circo borderleft"> 16 16 <?php $ct = 0; -
cpc/trunk/project/apps/frontend/modules/parlementaire/templates/_top.php
r1393 r1408 62 62 $weeks = (strtotime($parlementaire->fin_mandat) - strtotime($parlementaire->debut_mandat))/(60*60*24*7); 63 63 echo '<h2>'; 64 printf(' Bilan de ses %d semaines de mandat:</h2>', $weeks);64 printf('Activité sur %d semaines :</h2>', $weeks); 65 65 } 66 66 ?>
Note: See TracChangeset
for help on using the changeset viewer.