Layer Type defaults to Polygon even when drawing Rectangles
See original GitHub issueThe draw:created event’s e.layer
, when converted to geoJSON says that geometry.type
is a Polygon, even after drawing a Rectangle. Therefore, in Edit mode - the Rectangles are not movable/vertices can be pulled to warp the shape. Any idea what might be causing this? It’s using the default L.Draw.Rectangle and options.rectangle for the nodeHandlers (as it does out of the box), so not sure why the created
event says its a Polygon.
Issue Analytics
- State:
- Created 7 years ago
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Create rectangular features
The Rectangle tool creates planar rectangular or square single-part features ... clip existing polygons on the same layer if they overlap your new...
Read more >Сreating polygons with straight lines and right angles in QGIS
The Orthogonal Digitizing tool is still drawing vertexes exactly where I point. My CADTools version is 0.5.9 and QGIS version 1.8. I've tried...
Read more >how to prevent drawing polygons on an existing shapes layer
I have recently started working on web mapping with leaflet js 1.0 . I started working with leaflet-draw but I don't find a...
Read more >How to create and modify live shapes in Illustrator
You can now draw circles, ellipses, polygons, and lines as Live ... Live shapes are displayed as a different object type in the...
Read more >Photoshop Shapes And Shape Layers Essentials
By default, the Rectangle Tool is the one that's visible in the Tools panel, ... Photoshop actually lets us draw three very different...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I use a similar trick to @Sandbird’s that I found somewhere else, where I define the geojson’s
onEachFeature
to something like:Which works fine at making the rectangle be edited as a rectangle instead of a polygon.
Unfortunately, this trick seems to prevent click event handlers added to rectangles to work (they do work for other shapes where no trick was applied), as shown in this fiddle (open, click the big rectangle in the middle, ensure nothing happens). If, however, the conversion to
L.rectangle()
is commented out (as in this other fiddle), the event handler is properly called (open, click the big rectangle in the middle, close annoying alert).Oddly enough, it works once again (even with the trick enabled) if the click handling is defined inside
onEachFeature
, as this final fiddle shows.There is a way to do it. Treat is as a MultiPolygon. A typical Polygon’s coordinates has 2 brackets. a MultiPolygon has 3, (so you can add ‘cuts’ into the polygon):
So all you have to do is add an extra [ ] to your geojson coordinates and name it type: MultiPolygon. I am creating my geojson object via PHP/MySQL so this is how i create a layer to place the objects inside: Looking at the type, i decide which of the 3 types to create in the Layer. (i dont use markers so Points is used for circles…i just need to send the radius as well) And here is the final result in edit mode: