Guillermo Espinoza пре 8 година
родитељ
комит
d9e287e39c

+ 25 - 0
Resources/public/js/leaflet-map-draw.js

@@ -0,0 +1,25 @@
+$(document).ready(function () {
+
+    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();
+    });
+
+});

+ 0 - 22
Resources/public/js/leaflet-map.js

@@ -35,28 +35,6 @@ $(document).ready(function () {
                 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();
     });

+ 1 - 1
Resources/views/Form/Type/leaflet_map_widget.html.twig

@@ -1,7 +1,7 @@
 {% block leaflet_map_widget %}
     {% spaceless %}
         <div class="form-group">
-            {% include 'LeafletBundle:Leaflet:map.html.twig' with { 'extra_js': true } %}
+            {% include 'LeafletBundle:Leaflet:map.html.twig' with { 'extra_js': true, 'draw': true } %}
             
             {{ block('hidden_widget') }}
         </div>

+ 3 - 0
Resources/views/Leaflet/map.html.twig

@@ -22,6 +22,9 @@
 
 <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>
+{% endif %}    
 {% if extra_js is defined %}
 <script src="{{ script_google_maps }}"></script>
 <script src="{{ asset('bundles/leaflet/js/leaflet-map-widget.js') }}"></script>