terra-draw
terra-draw copied to clipboard
[Bug] Silent Failure of draw.start() (esri-leaflet + TerraDraw)
Describe the bug When using both esri-leaflet and TerraDraw with Leaflet, the draw.start() method shows no response and no error.
Terra Draw npm version [email protected] [email protected]
To Reproduce Reproduce code as follows:
<html>
<head>
<meta charset="utf-8" />
<title>Style polygons</title>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" crossorigin="" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" crossorigin=""></script>
<!-- Load Esri Leaflet from CDN -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet.js"></script>
<!-- Load Esri Leaflet Vector from CDN -->
<script src="https://unpkg.com/[email protected]/dist/esri-leaflet-vector.js" crossorigin=""></script>
<script src="https://unpkg.com/[email protected]/dist/terra-draw.umd.js"></script>
<script src="https://unpkg.com/[email protected]/dist/terra-draw-leaflet-adapter.umd.js"></script>
<style>
html,
body,
#map {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
color: #323232;
}
</style>
</head>
<body>
<div id="map"></div>
<div style="
position: absolute;
top: 40px;
z-index: 1000;
width: 100%;
margin: auto 0;
display: flex;
justify-content: center;
">
<button id="polygon">Polygon</button>
</div>
<script>
const accessToken = "AAPTxy8BH1VEsoebNVZXo8HurPfazxvdCXPKJrVhXN0ToM2S1n0Qu_jozI6yVfnrwnv_8n5r7vy4ZHdMARwd5lNmmQNcm4hb0pNmW-E0BPnjlK61FfJvTTQ7q4Y4hZfHqHX5NuA8SCRbd9JVnBdZyA7BElCLtXSAplq3lAWO_yn5IvEpOeCUYr27AXP12uwx9jhA5ZTBADVEJozyi9ahSN324GRkiNU0l7FwrFXucxydj8MdIBBGDGoSNz1I1LsIQ1LhAT1_JB2G6yHe";
const map = L.map("map").setView([33.836, -118.22], 8);
L.esri.Vector.vectorBasemapLayer("arcgis/light-gray", {
token: accessToken
}).addTo(map);
L.esri
.featureLayer({
url: "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/USA_119th_Congressional_Districts/FeatureServer/0",
simplifyFactor: 0.5,
precision: 5,
style: function (feature) {
if (feature.properties.PARTY === "Democrat") {
return { color: "blue", weight: 2 };
} else if (feature.properties.PARTY === "Republican") {
return { color: "red", weight: 2 };
} else {
return { color: "white", weight: 2 };
}
}
})
.addTo(map);
const draw = new terraDraw.TerraDraw({
adapter: new terraDrawLeafletAdapter.TerraDrawLeafletAdapter({ lib: L, map }),
modes: [new terraDraw.TerraDrawPolygonMode()]
});
document.getElementById("polygon").onclick = function () {
draw.start();
draw.setMode("polygon");
console.log("Drawing started");
};
</script>
</body>
</html>
Expected behavior Clicking the polygon button produces no response; I hope it works properly for drawing.
Desktop (please complete the following information):
- OS: [e.g. windows11]
- Browser [e.g. chrome]
- Version [e.g. 136]