Uncaught TypeError: Cannot read property 'enable' of undefined. (Polygon added after map load)
See original GitHub issueI am loading a single pologon into the featureGroup after the map and feature group has been loaded, by doing an ajax call to a web service. Creating the polygon is successful, but when then attempting to edit the polygon through the “Edit Layers” control, a JS error is received: “Uncaught TypeError: Cannot read property ‘enable’ of undefined”. Objects are declared before data is received:
var myPolygon;
var myFeatureGroup = L.featureGroup();
var map = L.map('mapdiv').setView([-21.113887987117593, 149.14807319641113], 15);
L.tileLayer('http://{s}.tiles.mapbox.com/v3/##myaccount##/{z}/{x}/{y}.png', {
maxZoom: 18
}).addTo(map);
Then, when data is received from the AJAX function for the polygon, it is added to the featureGroup as follows:
function getPolygonDetails_CallBack(response) {
handleResponse(response.d.response);
myPolygon = omnivore.wkt.parse(response.d.polygonGeography);
myFeatureGroup.addLayer(myPolygon);
myFeatureGroup.addTo(map);
var drawControl = new L.Control.Draw({
edit: {
featureGroup: myFeatureGroup
},
draw: {
polygon:true,
polyline: false,
rectangle: false,
circle: false,
marker: false
}
}).addTo(map);
map.on('draw:created', function (e) {
myFeatureGroup.addLayer(e.layer);
});
}
Now - when the draw modify control is used, the error is displayed - as though it can no longer reference “myPolygon”.
Same result tested in leaflet 0.7.3 & 0.8-dev and leaflet.draw 0.2.2 & 0.2.3.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Leaflet Draw "Cannot read property 'enable' of undefined ...
I am trying to use leaflet's edit function on polygons that I loaded from my database. When I click on leaflet's ...
Read more >“Uncaught TypeError: Cannot read property 'x' of undefined ...
Hi, I'm getting the below error <b><i>most of the times</i></b> on every attempt to drag the map, after displaying a dynamically constructed polygon....
Read more >Error Messages | Maps JavaScript API - Google Developers
This page describes the error messages that can be returned by the Maps JavaScript API. The Maps JavaScript API writes error and warning...
Read more >Uncaught TypeError: Cannot read property of null - iDiallo
You are accessing a property of an object that is null. For example, document.getElementById('stuff') returns null. So adding .value will cause ...
Read more >React Google Maps Api Style Guide
LoadScript - Loads the Google Maps API script; GoogleMap - The map component inside which all other components render. The simplest way to...
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
@tyeware @dvector
Updated: https://jsfiddle.net/f9kmrhb7/86/
omnivore.wkt.parse()
returns a GeoJSON object, which by default, is a FeatureGroupSince FeatureGroup extends LayerGroup You can walk through the layers presented and add them individually to the FeatureGroup used for Leaflet.draw
That’s awesome - thanks for the assistance.