leaflet.draw

Add existing leaflet polygons to an existing leaflet layer

我的未来我决定 提交于 2019-12-08 02:43:28
I have a bunch of polygons which are stored in a database. I would like to add them to the map in such a way that they can be edited using the leaflet-draw toolbar. Although, now the polygons get added to the map, I am unable edit them. I think this is because they are not added to the layerGroup() to which newly drawn shapes are added. Please help. Manuel You have to add your polygons to the featureGroup drawnItems ! Let's say, var polyLayers = dbArray; is your database array with polygons. First create a feature group with your drawn items: var drawnItems = new L.FeatureGroup(); and add it

change default icon toolbar (Leaflet)

走远了吗. 提交于 2019-12-07 18:11:51
问题 how can i change default toolbar icon to something else on leaflet.. picture above show the default view of icon.. i want to customize and change the icon to something else for example the first icon i want to look like as a bridge and second text icon and so on.. i already tried a few ways but did not work. here my code var electricpole = L.Icon.extend({ options: { shadowUrl: null, iconAnchor: new L.Point(12, 12), iconSize: new L.Point(30,30), iconUrl: 'image/electricpole.png' } }); L

Django RF: POST geometry from Leaflet Draw to PostGIS

▼魔方 西西 提交于 2019-12-04 16:26:55
I'm trying to store some geometry in a PostGIS DB which is created using Leaflet Draw . The following answer only covers the first part: how to transform the drawn shape into GeoJSON, i.e.: map.on(L.Draw.Event.CREATED, function (e) { var type = e.layerType var layer = e.layer; // Do whatever else you need to. (save to db, add to map etc) drawnItems.addLayer(layer); //Export to DB (source: https://stackoverflow.com/a/24019108/3976696) var shape = layer.toGeoJSON() shape_for_db = JSON.stringify(shape); For example, shape_for_db contains: { "type": "Feature", "properties": {}, "geometry": { "type

How can I grab a selection of markers with Leaflet.draw?

北城以北 提交于 2019-12-04 10:40:54
问题 Context: I've made a map, and populated it with around 300 random markers. I can 'select' the markers by clicking on a link in the popup and activate a selection to display data from. I also have the Leaflet.draw plugin to draw shapes like circles, rectangles and custom shapes, and I would like to use it to 'select' a couple of markers. The issue How can I grab the leaflet marker object of the markers that fall inside a drawn leaflet.draw shape so I can edit them? I cannot seem to make a

Disable leaflet-draw “delete” button

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 05:34:40
问题 How can I disable/remove the delete button in the leaflet-draw edit toolbar? The "edit" button should remain enabled. 回答1: Regarding to the docs in chapter Disabeling a Toolbar Item you can do the following: map.addControl(new L.Control.Draw({ edit: { featureGroup: drawnItems, remove: false } })); This adds a new Control bar without the delete Button, but the edit button will remain 来源: https://stackoverflow.com/questions/40414970/disable-leaflet-draw-delete-button

How can I grab a selection of markers with Leaflet.draw?

被刻印的时光 ゝ 提交于 2019-12-03 06:24:39
Context: I've made a map, and populated it with around 300 random markers. I can 'select' the markers by clicking on a link in the popup and activate a selection to display data from. I also have the Leaflet.draw plugin to draw shapes like circles, rectangles and custom shapes, and I would like to use it to 'select' a couple of markers. The issue How can I grab the leaflet marker object of the markers that fall inside a drawn leaflet.draw shape so I can edit them? I cannot seem to make a selection, It either selects none of the markers, or all of them. Code snippet, stripped from unnecessary

leaflet-draw delete button remove “clear all” action

眉间皱痕 提交于 2019-12-01 18:16:07
问题 How can I remove the "clear all" action from the delete button in the leaflet-draw edit toolbar? I know you can remove the whole delete button but still need to remove individual items. Basically looking for a way to prevent the user from deleting every item from the map. 回答1: The edit toolbar tests the existence of a removeAllLayers member on the button handler. So, a simple but probably heavy handed way to disable the clear all action is to nuke removeAllLayers on the L.EditToolbar.Delete

leaflet-draw delete button remove “clear all” action

好久不见. 提交于 2019-12-01 18:07:42
How can I remove the "clear all" action from the delete button in the leaflet-draw edit toolbar? I know you can remove the whole delete button but still need to remove individual items. Basically looking for a way to prevent the user from deleting every item from the map. The edit toolbar tests the existence of a removeAllLayers member on the button handler. So, a simple but probably heavy handed way to disable the clear all action is to nuke removeAllLayers on the L.EditToolbar.Delete module: L.EditToolbar.Delete.include({ removeAllLayers: false }); new L.Control.Draw({ edit: { featureGroup:

rotate polygon around point in leaflet map

二次信任 提交于 2019-12-01 01:55:54
I have an issue, in my leaflet map I've created a triangle from polygon: var polygon = L.polygon([ [parseFloat(decimal_lat),parseFloat(decimal_lon)], [parseFloat(decimal_lat) + 1, parseFloat(decimal_lon) - 1], [parseFloat(decimal_lat) + 1, parseFloat(decimal_lon) + 1] ], { color:'green' }); polygon.addTo(map); and I want to rotate this polygon around Point[decimal_lon, decimal_lat] . But I'm not able to solve it.. I've created DEMO , where I'm rotating polynom the same I want to rotate my triangle (polygon) to show you my problem. One way to do it is through matrix rotation. https://en

How to click a button and start a new polygon without using the Leaflet.draw UI

元气小坏坏 提交于 2019-11-30 07:30:18
问题 What I'm struggling with is how to click a button and start a new polygon without using the Leaflet.draw UI. e.g. $('#draw_poly').click(function() { }); I'm able to put an existing polygon into edit mode no problem. $('.edit_polygon').click(function() { var name = $(this).text(); geojson_layer.eachLayer(function (layer) { if (name == layer.feature.properties.name){ layer.editing.enable(); } }); return false; }); Thanks to Jacob Toye for assistance. I've made a little demo. <!DOCTYPE html>