Example #1
0
 public function testPrePersistWithAutozoom()
 {
     $this->map->setCenter(-1.1, -2.2);
     $this->map->setBound(1, 2, 3, 4);
     $this->map->setAutoZoom(true);
     $this->map->prePersist();
     $this->assertNull($this->map->getCenter());
     $this->assertSame(1, $this->map->getBound()->getSouthWest()->getLatitude());
     $this->assertSame(2, $this->map->getBound()->getSouthWest()->getLongitude());
     $this->assertSame(3, $this->map->getBound()->getNorthEast()->getLatitude());
     $this->assertSame(4, $this->map->getBound()->getNorthEast()->getLongitude());
 }
Example #2
0
 public function testCenterWithLatitueAndLongitude()
 {
     $this->map->setCenter(1, 2, false);
     $this->assertEquals(1, $this->map->getCenter()->getLatitude());
     $this->assertEquals(2, $this->map->getCenter()->getLongitude());
     $this->assertFalse($this->map->getCenter()->isNoWrap());
 }
    public function testRender()
    {
        $map = new Map();
        $map->setJavascriptVariable('map');
        $map->getCenter()->setJavascriptVariable('map_center');
        $expected = <<<EOF
<div id="map_canvas" style="width:300px;height:300px;"></div>
<style type="text/css">
#map_canvas{
width:300px;
height:300px;
}
</style>
<script type="text/javascript">
function load_ivory_google_map_api () { google.load("maps", "3", {"other_params":"language=en&sensor=false"}); };
</script>
<script type="text/javascript" src="//www.google.com/jsapi?callback=load_ivory_google_map_api"></script>
<script type="text/javascript">
map_container = {"map":null,"coordinates":{},"bounds":{},"points":{},"sizes":{},"circles":{},"encoded_polylines":{},"ground_overlays":{},"polygons":{},"polylines":{},"rectangles":{},"info_windows":{},"marker_images":{},"marker_shapes":{},"markers":{},"marker_cluster":null,"kml_layers":{},"event_manager":{"dom_events":{},"dom_events_once":{},"events":{},"events_once":{}},"closable_info_windows":{},"functions":{"to_array":function (object) { var array = []; for (var key in object) { array.push(object[key]); } return array; }}};
map_container.coordinates.map_center = map_center = new google.maps.LatLng(0, 0, true);
map_container.map = map = new google.maps.Map(document.getElementById("map_canvas"), {"mapTypeId":google.maps.MapTypeId.ROADMAP,"zoom":3});
map.setCenter(map_center);
</script>

EOF;
        $this->assertSame($expected, $this->mapHelper->render($map));
    }
Example #4
0
 /**
  * Computes the coordinates of a map.
  *
  * @param \Ivory\GoogleMap\Map $map The map.
  *
  * @return array The computed coordinated.
  */
 protected function computeCoordinates(Map $map)
 {
     $coordinates = array();
     if (!$map->isAutoZoom() && !in_array($map->getCenter(), $coordinates)) {
         $coordinates[] = $map->getCenter();
     }
     foreach ($this->computeBounds($map) as $bound) {
         if (!$bound->hasExtends() && $bound->hasCoordinates()) {
             if (!in_array($bound->getSouthWest(), $coordinates)) {
                 $coordinates[] = $bound->getSouthWest();
             }
             if (!in_array($bound->getNorthEast(), $coordinates)) {
                 $coordinates[] = $bound->getNorthEast();
             }
         }
     }
     foreach ($map->getCircles() as $circle) {
         if (!in_array($circle->getCenter(), $coordinates)) {
             $coordinates[] = $circle->getCenter();
         }
     }
     foreach ($map->getInfoWindows() as $infoWindow) {
         if (!in_array($infoWindow->getPosition(), $coordinates)) {
             $coordinates[] = $infoWindow->getPosition();
         }
     }
     foreach ($map->getMarkers() as $marker) {
         if (!in_array($marker->getPosition(), $coordinates)) {
             $coordinates[] = $marker->getPosition();
         }
     }
     foreach ($map->getPolygons() as $polygon) {
         foreach ($polygon->getCoordinates() as $polygonCoordinate) {
             if (!in_array($polygonCoordinate, $coordinates)) {
                 $coordinates[] = $polygonCoordinate;
             }
         }
     }
     foreach ($map->getPolylines() as $polyline) {
         foreach ($polyline->getCoordinates() as $polylineCoordinate) {
             if (!in_array($polylineCoordinate, $coordinates)) {
                 $coordinates[] = $polylineCoordinate;
             }
         }
     }
     return $coordinates;
 }