瀏覽代碼

Agregado de la consulta de la variables de latitud y longitud en los mapas

gabriel 7 年之前
父節點
當前提交
f62c3ce0a0
共有 2 個文件被更改,包括 51 次插入44 次删除
  1. 31 35
      Resources/public/js/leaflet-map.js
  2. 20 9
      Resources/views/Leaflet/map.html.twig

+ 31 - 35
Resources/public/js/leaflet-map.js

@@ -1,56 +1,55 @@
 window.SONATA_CONFIG.USE_ICHECK = false;
 
 var map,
-        defaultCoords,
-        drawnItems,
-        marker,
-        loc,
-        dataValue;
+    defaultCoords,
+    drawnItems,
+    marker,
+    loc,
+    dataValue;
 
 $(document).ready(function () {
-    defaultCoords = new L.latLng(39.791312, -2.6949709); // España
+    defaultCoords = new L.latLng(_MAP_LATITUDE, _MAP_LONGITUDE);
     map = new L.Map('map', {zoom: getZoomLevel(), center: getDataCoords()});
     drawnItems = L.featureGroup().addTo(map);
 
     drawMarker();
 
     L.control.layers(
-            {
-                'openstreetmap': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
-                        {
-                            maxZoom: 18,
-                            attribution: '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
-                        }).addTo(map),
-                "google": L.tileLayer('http://www.google.com.ar/maps/vt?lyrs=y@189&gl=cn&x={x}&y={y}&z={z}',
-                        {
-                            maxZoom: 18,
-                            attribution: 'google'
-                        })
-            },
-            {
-                'drawlayer': drawnItems
-            },
-            {
-                position: 'topleft',
-                collapsed: false
-            }).addTo(map);
+        {
+            'openstreetmap': L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
+                {
+                    maxZoom: 18,
+                    attribution: '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
+                }).addTo(map),
+            "google": L.tileLayer('http://www.google.com.ar/maps/vt?lyrs=y@189&gl=cn&x={x}&y={y}&z={z}',
+                {
+                    maxZoom: 18,
+                    attribution: 'google'
+                })
+        },
+        {
+            'drawlayer': drawnItems
+        },
+        {
+            position: 'topleft',
+            collapsed: false
+        }).addTo(map);
 
     map.on('zoomend', function () {
         setDataValue();
     });
-    
+
 });
 
 // Espera que el tab mostrado tenga la clase CSS 'active' y hace un refresh del mapa
 // debido a que al estar oculto en un tab no se muestra con el tamaño correcto
 var tab_id;
-$('.nav-tabs a').on('click', function() {
+$('.nav-tabs a').on('click', function () {
     tab_id = $(this).attr('href');
     checkForChanges();
 });
 
-function checkForChanges()
-{
+function checkForChanges() {
     if ($(tab_id).hasClass('active')) {
         map._onResize();
     } else {
@@ -58,8 +57,7 @@ function checkForChanges()
     }
 }
 
-function getDataCoords()
-{
+function getDataCoords() {
     var jsonParseData = {};
     if ($('[name$="[extraData]"]').val()) {
         dataValue = $('[name$="[extraData]"]').val();
@@ -75,8 +73,7 @@ function getDataCoords()
     return loc;
 }
 
-function drawMarker()
-{
+function drawMarker() {
     if (marker) {
         drawnItems.removeLayer(marker);
     }
@@ -85,8 +82,7 @@ function drawMarker()
     drawnItems.addLayer(marker);
 }
 
-function getZoomLevel()
-{
+function getZoomLevel() {
     var jsonParseData = {};
     var zoomLevel = 18;
     if ($('[name$="[extraData]"]').val()) {

+ 20 - 9
Resources/views/Leaflet/map.html.twig

@@ -2,12 +2,14 @@
 
 <style type="text/css">
     .leaflet-map-widget {
-        height: 400px; 
+        height: 400px;
         border: 1px solid #CCCCCC;
     }
+
     .leaflet-control-search.search-exp.leaflet-control {
         width: 400px !important;
     }
+
     .search-input {
         width: 370px !important;
     }
@@ -15,21 +17,30 @@
 {% include 'LeafletBundle:Leaflet:resources.html.twig' %}
 
 {% if object is defined %}
-<script type="text/javascript">
-    {% if object.location.extraData is defined %}
+    <script type="text/javascript">
+        {% if object.location.extraData is defined %}
         var dataValue = '{{ object.location.extraData|raw }}';
-    {% elseif object.extraData is defined %}
+        {% elseif object.extraData is defined %}
         var dataValue = '{{ object.extraData|raw }}';
-    {% endif %}
-</script>
+        {% endif %}
+    </script>
 {% endif %}
 
+<script type="application/javascript">
+    {% if config_manager is defined %}
+    var _MAP_LATITUDE = {{ config_manager.getValue('location', 'location', 'latitude') }};
+    var _MAP_LONGITUDE = {{ config_manager.getValue('location', 'location', 'longitude') }};
+    {% else %}
+    var _MAP_LATITUDE = 0;
+    var _MAP_LONGITUDE = 0;
+    {% endif %}
+</script>
 <script src="{{ asset('bundles/leaflet/js/leaflet-map.js') }}"></script>
 
 {% if draw is defined %}
-<script src="{{ asset('bundles/leaflet/js/leaflet-map-draw.js') }}"></script>
+    <script src="{{ asset('bundles/leaflet/js/leaflet-map-draw.js') }}"></script>
 {% endif %}    
 {% if extra_js is defined %}
-<script src="{{ script_google_maps }}"></script>
-<script src="{{ asset('bundles/leaflet/js/leaflet-map-widget.js') }}"></script>
+    <script src="{{ script_google_maps }}"></script>
+    <script src="{{ asset('bundles/leaflet/js/leaflet-map-widget.js') }}"></script>
 {% endif %}