Cannot read property 'Marker' of undefined

3,513 views
Skip to first unread message

Gabriele Barni

unread,
Mar 14, 2017, 5:38:20 AM3/14/17
to Leaflet

Hi everybody,

I hope to be in the right section, and eventually apologize in advance.

I cannot get away from this error whenever I try to draw anything on my map, in particular during the initialization of the Marker object.

Some code:

new L.Marker(latlng,options);

where

latlng:
lat:1.3486810687613844 lng: 103.96888822317123
options:
icon:{ _initHooksCalled:true, options:Object, __proto__:NewClass }
innerIcon:undefined
states:Array[0]
style:null
The stack error is the following:


TypeError: Cannot read property 'Marker' of undefined
at MetagisMarker. (leaflet.draw.js:9)
at MetagisMarker.proto.callInitHooks (leaflet-src.js:292)
at MetagisMarker.NewClass [as constructor] (leaflet-src.js:234)
at MetagisMarker (MetagisMarker.js:12)
at pointToLayer (MetagisLayer.js:74)
at MetagisLayer.geometryToLayer (MetagisLayer.js:183)
at MetagisLayer.addGeometry (MetagisLayer.js:123)
at MetagisLayer.addData (MetagisLayer.js:28)
at OntowizardMap.addObject (OntowizardMap.js:52)
at UserProfileOutputController.addProfile (UserProfileOutputController.js:112) "Possibly unhandled rejection: {}"



MetagisMarker is just a class which extends the Leaflet marker class.


Similar behaviour I get when I try to draw a Polygon or Polilyne:


TypeError: Cannot read property 'draw' of undefined
at
DrawPolylineHandler.initialize (leaflet.draw.js:9)
at
DrawPolylineHandler.NewClass [as constructor] (leaflet-src.js:229)
at
DrawPolylineHandler (DrawPolylineHandler.js:12)
at
DrawControl.drawGeometry (DrawControl.js:99)
at
DrawControl.create (DrawControl.js:44)
at
OntowizardMap.createObject (OntowizardMap.js:64)


I am using:

  • Leaflet 1.0.3
  • Leaflet-draw-with-touch 0.2.3
  • angular 1.4.6

Thanks in advance for your help...anything is appreciated

devque...@gmail.com

unread,
Mar 21, 2017, 2:50:36 PM3/21/17
to Leaflet
undefined object error usually indicates that you are trying to access object properties before it is created or on  a wrong object.  Did you try to check the object properties in the browser ? 

In chrome you can use 'developer tools' to inspect java script objects. 

Gabriele Barni

unread,
Mar 21, 2017, 6:28:04 PM3/21/17
to Leaflet
I inspected the object L at every step, since it is basically created. I really dont know anymore what to investigate :(

Gabriele Barni

unread,
Mar 28, 2017, 12:18:25 PM3/28/17
to Leaflet
Update:

If this can help to confuse even more: I noticed that while debugging with the 'Developer tools' of Chrome, during the execution of some functions among those listed in the error stack, the objewct L.Edit, magically is there, while during the execution of others this is not the case!

Plus, in case I watch a variable, L (of Leaflet), the object L.Edit never shows up while hoovering with the mouse, this sometimes appears...

This is really strange...some has any idea on what else I could check ?

Thanks everybody

G.
Reply all
Reply to author
Forward
0 new messages