Przeglądaj źródła

Refactory vista edit map

Guillermo Espinoza 8 lat temu
rodzic
commit
ba249fd22a

+ 3 - 8
Resources/public/js/leaflet-map-widget.js

@@ -2,7 +2,7 @@ var geocoder;
 
 $(document).ready(function () {
     placeholder = 'Buscar...';
-    
+
     geocoder = new google.maps.Geocoder();
 
     map.addControl(new L.Control.Search({
@@ -21,10 +21,6 @@ $(document).ready(function () {
         textPlaceholder: placeholder
     }));
 
-    map.on('zoomend', function () {
-        setDataValue();
-    });
-
     $('.search-button').on('click', function () {
         if (loc && $('.search-input').val() !== placeholder) {
             drawMarker();
@@ -40,8 +36,8 @@ $(document).ready(function () {
             setDataValue();
         }
     });
-    
-    $('.search-tooltip').on('click', function() {
+
+    $('.search-tooltip').on('click', function () {
         var tooltip = $(this).children('.search-tip');
         var location = '';
         if (tooltip) {
@@ -53,7 +49,6 @@ $(document).ready(function () {
             $('.search-button').trigger('click');
         }
     });
-    
 });
 
 function setDataValue()

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

@@ -1,19 +1,17 @@
 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
     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',
@@ -34,6 +32,32 @@ $(document).ready(function () {
                 position: 'topleft',
                 collapsed: false
             }).addTo(map);
+
+    var drawControl = new L.Control.Draw({
+        draw: {
+            polygon: false,
+            rectangle: false,
+            polyline: false,
+            circle: false
+        },
+        edit: {
+            featureGroup: drawnItems,
+            edit: false
+        }
+    });
+
+    map.addControl(drawControl);
+
+    map.on(L.Draw.Event.CREATED, function (e) {
+        var layer = e.layer;
+        loc = new L.latLng(layer._latlng);
+        drawMarker();
+        setDataValue();
+    });
+
+    map.on('zoomend', function () {
+        setDataValue();
+    });
 });
 
 function getDataCoords()