From 172d16c11be8d9d08044aeac5d196ac279b7452e Mon Sep 17 00:00:00 2001 From: Sebastian Castro <90scastro@gmail.com> Date: Fri, 26 Oct 2018 11:17:31 +0200 Subject: [PATCH] Improve default map bounds selection. Close #23 --- .../SonataAdminBundle/views/layout.html.twig | 6 +- .../Admin/ConfigurationMapAdmin.php | 23 +++++--- .../custom-fields/viewport-picker.html.twig | 59 +++++++++++++++++++ .../core_custom/form_admin_fields.html.twig | 2 + 4 files changed, 82 insertions(+), 8 deletions(-) create mode 100644 src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/custom-fields/viewport-picker.html.twig diff --git a/app/Resources/SonataAdminBundle/views/layout.html.twig b/app/Resources/SonataAdminBundle/views/layout.html.twig index 04efa31b..5d93e13c 100755 --- a/app/Resources/SonataAdminBundle/views/layout.html.twig +++ b/app/Resources/SonataAdminBundle/views/layout.html.twig @@ -53,7 +53,9 @@ - + + + + + {% endblock %} {% block sonata_sidebar_search %} diff --git a/src/Biopen/CoreBundle/Admin/ConfigurationMapAdmin.php b/src/Biopen/CoreBundle/Admin/ConfigurationMapAdmin.php index 940767c9..1cdeb160 100755 --- a/src/Biopen/CoreBundle/Admin/ConfigurationMapAdmin.php +++ b/src/Biopen/CoreBundle/Admin/ConfigurationMapAdmin.php @@ -26,20 +26,29 @@ protected function configureFormFields(FormMapper $formMapper) $mailStyle = array('class' => 'col-md-12 col-lg-6'); $featureFormOption = ['delete' => false, 'required'=> false, 'label_attr'=> ['style'=> 'display:none']]; $featureFormTypeOption = ['edit' => 'inline']; + $container = $this->getConfigurationPool()->getContainer(); + $em = $container->get('doctrine_mongodb')->getManager(); + $config = $em->getRepository('BiopenCoreBundle:Configuration')->findConfiguration(); + $formMapper ->tab('Paramètres de la carte') - ->with('Map', array('class' => 'col-md-6')) + ->with('Map') ->add('defaultTileLayer', 'sonata_type_model', array( 'class'=> 'Biopen\CoreBundle\Document\TileLayer', 'required' => true, 'choices_as_values' => true, - 'label' => 'Fond de carte par défaut')) - ->add('defaultNorthEastBoundsLat') - ->add('defaultNorthEastBoundsLng') - ->add('defaultSouthWestBoundsLat') - ->add('defaultSouthWestBoundsLng') + 'label' => 'Fond de carte par défaut (enregistez pour voir apparaitre le fond délectionné sur la carte ci-dessous)')) + ->add('defaultViewPicker', 'hidden', array('mapped' => false, 'attr' => [ + 'class' => 'gogo-viewport-picker', + 'data-title-layer' => $config->getDefaultTileLayer()->getUrl(), + 'data-default-bounds' => json_encode($config->getDefaultBounds()) + ])) + ->add('defaultNorthEastBoundsLat', 'hidden', ['attr' => ['class' => 'bounds NELat']]) + ->add('defaultNorthEastBoundsLng', 'hidden', ['attr' => ['class' => 'bounds NELng']]) + ->add('defaultSouthWestBoundsLat', 'hidden', ['attr' => ['class' => 'bounds SWLat']]) + ->add('defaultSouthWestBoundsLng', 'hidden', ['attr' => ['class' => 'bounds SWLng']]) ->end() - ->with('Cookies', array('class' => 'col-md-6')) + ->with('Cookies') ->add('saveViewportInCookies', 'checkbox', array('label' => "Sauvegarder la position courante de la carte dans les cookies", 'required' => false)) ->add('saveTileLayerInCookies', 'checkbox', array('label' => "Sauvegarder le choix du fond de carte dans les cookies", 'required' => false)) ->end() diff --git a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/custom-fields/viewport-picker.html.twig b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/custom-fields/viewport-picker.html.twig new file mode 100644 index 00000000..0a02d8cd --- /dev/null +++ b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/custom-fields/viewport-picker.html.twig @@ -0,0 +1,59 @@ + +
+ + + \ No newline at end of file diff --git a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/form_admin_fields.html.twig b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/form_admin_fields.html.twig index 111b82a9..85a28d26 100755 --- a/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/form_admin_fields.html.twig +++ b/src/Biopen/GeoDirectoryBundle/Resources/views/admin/core_custom/form_admin_fields.html.twig @@ -18,6 +18,8 @@ {% include '@BiopenAdmin/core_custom/custom-fields/form-builder.html.twig' %} {% elseif attr.class == "gogo-form-fields" %} {% include '@BiopenAdmin/partials/show_element_form_fields.html.twig' %} + {% elseif attr.class == "gogo-viewport-picker" %} + {% include '@BiopenAdmin/core_custom/custom-fields/viewport-picker.html.twig' %} {% else %} {% set attr = attr|merge({'class': attr.class|default('') ~ ' form-control'}) %} {{ parent() }}