public function testMultipleBuildWithReset()
 {
     $this->mapBuilder->setPrefixJavascriptVariable('foo')->setHtmlContainerId('bar')->setAsync(true)->setAutoZoom(true)->setLibraries(array('foo'))->setLanguage('fr')->setCenter(1, 2, false)->setBound(1, 2, 3, 4, true, false)->setMapOptions(array('foo' => 'bar'))->setStylesheetOptions(array('bar' => 'foo'));
     $map1 = $this->mapBuilder->build();
     $this->mapBuilder->reset();
     $map2 = $this->mapBuilder->build();
     $this->assertSame('foo', substr($map1->getJavascriptVariable(), 0, 3));
     $this->assertSame('bar', $map1->getHtmlContainerId());
     $this->assertTrue($map1->isAsync());
     $this->assertTrue($map1->isAutoZoom());
     $this->assertSame(array('foo'), $map1->getLibraries());
     $this->assertSame('fr', $map1->getLanguage());
     $this->assertSame(1, $map1->getCenter()->getLatitude());
     $this->assertSame(2, $map1->getCenter()->getLongitude());
     $this->assertFalse($map1->getCenter()->isNoWrap());
     $this->assertSame(1, $map1->getBound()->getSouthWest()->getLatitude());
     $this->assertSame(2, $map1->getBound()->getSouthWest()->getLongitude());
     $this->assertTrue($map1->getBound()->getSouthWest()->isNoWrap());
     $this->assertSame(3, $map1->getBound()->getNorthEast()->getLatitude());
     $this->assertSame(4, $map1->getBound()->getNorthEast()->getLongitude());
     $this->assertFalse($map1->getBound()->getNorthEast()->isNoWrap());
     $this->assertSame(array('mapTypeId' => MapTypeId::ROADMAP, 'zoom' => 3, 'foo' => 'bar'), $map1->getMapOptions());
     $this->assertSame(array('width' => '300px', 'height' => '300px', 'bar' => 'foo'), $map1->getStylesheetOptions());
     $this->assertSame('map_', substr($map2->getJavascriptVariable(), 0, 4));
     $this->assertSame('map_canvas', $map2->getHtmlContainerId());
     $this->assertFalse($map2->isAsync());
     $this->assertFalse($map2->isAutoZoom());
     $this->assertEmpty($map2->getLibraries());
     $this->assertSame('en', $map2->getLanguage());
     $this->assertSame(0, $map2->getCenter()->getLatitude());
     $this->assertSame(0, $map2->getCenter()->getLongitude());
     $this->assertTrue($map2->getCenter()->isNoWrap());
     $this->assertFalse($map2->getBound()->hasCoordinates());
     $this->assertSame(array('mapTypeId' => MapTypeId::ROADMAP, 'zoom' => 3), $map2->getMapOptions());
     $this->assertSame(array('width' => '300px', 'height' => '300px'), $map2->getStylesheetOptions());
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $this->mapBuilder->setHtmlContainerId($view->vars['id'] . '_map_canvas');
     $this->mapBuilder->setAutoZoom(true);
     $this->mapBuilder->setMapOptions(['minZoom' => 3, 'maxZoom' => 18, 'disableDefaultUI' => true]);
     $this->mapBuilder->setStylesheetOptions(['width' => '100%', 'height' => '320px']);
     $map = $this->mapBuilder->build();
     $marker = new Marker();
     /** @var \Ivory\GoogleMap\Base\Coordinate $coordinate */
     if (null !== ($coordinate = $form->getData())) {
         if (null !== $coordinate->getLatitude() && null !== $coordinate->getLongitude()) {
             $marker->setPosition($coordinate);
         }
     }
     $map->addMarker($marker);
     $config = ['map_var' => $map->getJavascriptVariable(), 'marker_var' => $marker->getJavascriptVariable()];
     $view->vars['map'] = $map;
     $view->vars['config'] = $config;
 }