Development

/plugins/sfEasyGMapPlugin/trunk/test/unit/GMapCoordTest.php

You must first sign up to be able to contribute.

root/plugins/sfEasyGMapPlugin/trunk/test/unit/GMapCoordTest.php

Revision 17896, 1.8 kB (checked in by fabriceb, 4 years ago)

[sfEasyGMapPlugin]
* Corrected the Mercator projections for the GMapCoord::fromPixToLat and GMapCoord::fromLatToPix functions
* Used PHP pi() and deg2rad functions for better precision
* Created tests for the Mercator projections
* Added the GMapBounds::getBoundsContainingMarkers($markers) function
* Added the GMap::centerAndZoomOnMarkers() function which enables to guess zoom and center of the map to fit the markers. Center is easy to guess. Zoom uses width and height of smallest bound, pixel width and height of the map and Mercator projection

  • Property svn:executable set to *
Line 
1 <?php
2 /**
3  * Teste la sauvegarde d'équipes dans le backend
4  * @author fabriceb
5  * @since Feb 16, 2009 fabriceb
6  */
7 include(dirname(__FILE__).'/../bootstrap/unit.php');
8 //$app='frontend';
9 //include(dirname(__FILE__).'/../bootstrap/functional.php');
10
11
12 $t = new lime_test(286, new lime_output_color());
13
14 $t->diag('GMapCoords Tests');
15
16 for ($zoom=0; $zoom<15;$zoom += 3)
17 {
18   for($lat=90; $lat>=-90; $lat-=10)
19   {
20     $t->is(GMapCoord::fromPixToLat(GMapCoord::fromLatToPix($lat, $zoom),$zoom),(float)$lat,'les projections mercator sur les latitudes marchent');
21   }
22   for($lng=-180; $lng<=180; $lng+=10)
23   {
24     $t->is(GMapCoord::fromPixToLng(GMapCoord::fromLngToPix($lng, $zoom),$zoom),(float)$lng,'les projections mercator sur les longitudes marchent');
25   }
26 }
27
28 $lat = 0;
29 $lng 0;
30 $zoom = 0;
31
32 $pix = GMapCoord::fromLatToPix($lat, $zoom);
33 $t->is($pix,128,'Latitude 0 is at the middle of the map for zoom 0');
34 $pix = GMapCoord::fromLngToPix($lng, $zoom);
35 $t->is($pix,128,'Longitude 0 is at the middle of the map for zoom 0');
36
37
38 $lat = 0;
39 $lng =  -180;
40 $zoom = 12;
41 $pix = GMapCoord::fromLatToPix($lat, $zoom);
42 $t->is($pix,256*pow(2,$zoom-1),'Latitude 0 is at the middle of the map whatever the zoom');
43 $pix = GMapCoord::fromLngToPix($lng, $zoom);
44 $t->is($pix,0,'Longitude -180 is at the left of the map whathever the zoom');
45
46
47 $coord_paris = new GMapCoord(48.857939,2.346611);
48 $coord_le_mans = new GMapCoord(48.007381,0.202131);
49 $t->is(round(GMapCoord::distance($coord_le_mans, $coord_paris)),257,'Approximate distance between Le Mans and Paris is 257');
50
51 $coord_luxembourg = new GMapCoord(48.846559,2.340689);
52 $coord_saint_michel = new GMapCoord(48.853717,2.344015);
53 $t->is(round(GMapCoord::distance($coord_luxembourg, $coord_saint_michel)*1000),879,'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters');
Note: See TracBrowser for help on using the browser.