I want the user to enter manual coordinates of a polygon and then to click on a button to draw the polygon.
My code:
<body>
<div>
Polygon: <input type="text" name="coordPolygon" id="coordPolygon"/><br>
<input type="button" onclick="drawPolygon()" value="Draw"/><br>
</div>
<script>
function drawPolygon() {
var latlngs = document.getElementById("coordPolygon").value;
polygon = L.polygon(latlngs, {color:'red'});
polygon.addTo(mymap);
}
</script>
</body>
When the user enters for example [[48,-3],[50,5],[44,11],[43,-2]] the console tells me:
TypeError: latlngs is null
Note: I didn't test Leaflet.draw, I want to try with it later