/** * * @return GMapBounds * @author fabriceb * @since Jun 2, 2009 fabriceb */ public function getBoundsFromCenterAndZoom() { return GMapBounds::getBoundsFromCenterAndZoom($this->getCenterCoord(),$this->getZoom(),$this->getWidth(),$this->getHeight()); }
/** * * @param GMapMarker[] $markers array of MArkers * @param float $margin margin factor for the bounds * @return GMapBounds * @author fabriceb * @since 2009-05-02 * **/ public static function getBoundsContainingMarkers($markers, $margin = 0) { $coords = array(); foreach($markers as $marker) { array_push($coords, $marker->getGMapCoord()); } return GMapBounds::getBoundsContainingCoords($coords, $margin); }
/** * * @param GMapBounds $gmap_bounds * @return boolean $is_inside * @author fabriceb * @since Jun 2, 2009 fabriceb */ public function isInsideBounds(GMapBounds $gmap_bounds) { return $gmap_bounds->containsGMapCoord($this); }
$t->diag('->getBoundsContainingCoords Test'); $coord_1 = new GMapCoord(48.7887996681, 2.23631017383); $coord_2 = new GMapCoord(48.9243326339, 2.44230382617); $coord_3 = new GMapCoord(48.8, 2.4); $bounds_12 = GMapBounds::getBoundsContainingCoords(array($coord_1,$coord_2)); $bounds_123 = GMapBounds::getBoundsContainingCoords(array($coord_1,$coord_2,$coord_3)); $t->is($bounds_12->__toString(),'((48.7887996681, 2.23631017383), (48.9243326339, 2.44230382617))', 'The minimal bounds containing the coords is the rectangle containing the two coords'); $t->is($bounds_123->__toString(),'((48.7887996681, 2.23631017383), (48.9243326339, 2.44230382617))', 'The minimal bounds containing the coords is the rectangle containing the three coords'); $t->diag('->getBoundsContainingMarkers Test'); $marker_1 = new GMapMarker(48.7887996681, 2.23631017383); $marker_2 = new GMapMarker(48.9243326339, 2.44230382617); $marker_3 = new GMapMarker(48.8, 2.4); $bounds_12 = GMapBounds::getBoundsContainingMarkers(array($marker_1,$marker_2)); $bounds_123 = GMapBounds::getBoundsContainingMarkers(array($marker_1,$marker_2,$marker_3)); $t->is($bounds_12->__toString(),'((48.7887996681, 2.23631017383), (48.9243326339, 2.44230382617))', 'The minimal bounds containing the markers is the rectangle containing the two markers'); $t->is($bounds_123->__toString(),'((48.7887996681, 2.23631017383), (48.9243326339, 2.44230382617))', 'The minimal bounds containing the markers is the rectangle containing the three markers'); $t->diag('->getBoundsFromCenter Test'); $center_coord = new GMapCoord(48.856536,2.339307); $zoom = 11; $bounds = GMapBounds::getBoundsFromCenterAndZoom($center_coord, $zoom, 300, 300); $t->is($bounds->__toString(),'((48.7887237041, 2.23631017383), (48.9242565582, 2.44230382617))','On a déduit correctement les bounds à partir de la largeur de la carte, le centre et le zoom'); $bounds = GMapBounds::getBoundsFromCenterAndZoom($center_coord, $zoom, 1, 1); $t->is($bounds->__toString(),'((48.856536, 2.339307), (48.856536, 2.339307))','On a déduit correctement les bounds à partir de la largeur de la carte, le centre et le zoom'); $t->diag('Fin du test');
$lat = 0; $lng = 0; $zoom = 0; $pix = GMapCoord::fromLatToPix($lat, $zoom); $t->is($pix, 128, 'Latitude 0 is at the middle of the map for zoom 0'); $pix = GMapCoord::fromLngToPix($lng, $zoom); $t->is($pix, 128, 'Longitude 0 is at the middle of the map for zoom 0'); $lat = 0; $lng = -180; $zoom = 12; $pix = GMapCoord::fromLatToPix($lat, $zoom); $t->is($pix, 256 * pow(2, $zoom - 1), 'Latitude 0 is at the middle of the map whatever the zoom'); $pix = GMapCoord::fromLngToPix($lng, $zoom); $t->is($pix, 0, 'Longitude -180 is at the left of the map whathever the zoom'); $coord_paris = new GMapCoord(48.857939, 2.346611); $coord_le_mans = new GMapCoord(48.007381, 0.202131); $t->is(round(GMapCoord::distance($coord_le_mans, $coord_paris)), 257, 'Approximate distance between Le Mans and Paris is 257'); $t->is(round(GMapCoord::exactDistance($coord_le_mans, $coord_paris), 4), 184.5783, 'Approximate distance between Le Mans and Paris is 257'); $t->is(round(GMapCoord::exactDistanceSLC($coord_le_mans, $coord_paris), 4), 184.3091, 'Approximate distance between Le Mans and Paris is 257'); $coord_luxembourg = new GMapCoord(48.846559, 2.340689); $coord_saint_michel = new GMapCoord(48.853717, 2.344015); $t->is(round(GMapCoord::distance($coord_luxembourg, $coord_saint_michel) * 1000), 879, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters'); $t->is(round(GMapCoord::exactDistance($coord_luxembourg, $coord_saint_michel) * 1000, 4), 833.4828, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters'); $t->is(round(GMapCoord::exactDistanceSLC($coord_luxembourg, $coord_saint_michel) * 1000, 4), 832.2670000000001, 'Approximate distance between RER Luxembourg and Saint-Michel is 879 meters'); $coord_luxembourg = new GMapCoord(48.846559, 2.340689); $coord_saint_michel = new GMapCoord(48.853717, 2.344015); $center_of_the_world = new GMapCoord(0, 0); $bounds_paris = GMapBounds::createFromString('((48.791033113791144, 2.2240447998046875), (48.926559723513435, 2.4300384521484375))'); $t->ok($coord_saint_michel->isInsideBounds($bounds_paris), 'Saint-Michel Notre-Dame is in Paris'); $t->ok($coord_luxembourg->isInsideBounds($bounds_paris), 'RER Luxembourg is in Paris'); $t->ok(!$center_of_the_world->isInsideBounds($bounds_paris), 'Center of the world is not in Paris (amazingly)');
/** * * @param GMapMarker[] $markers array of MArkers * @return GMapCoord * @author fabriceb * @since 2009-05-02 * **/ public static function getCenterCoord($markers) { $bounds = GMapBounds::getBoundsContainingMarkers($markers); return $bounds->getCenterCoord(); }