Cannot add graphic with a reproject

3967
7
Jump to solution
02-11-2015 08:01 AM
MarkYerington
Occasional Contributor III

I cannot figure this out.  I am trying to add a graphic to the map and zoom to it based on a reproject.  My location entry is in lat/long and my map is in state plane.  I am passed back the coordinates correctly, but cannot do add or centerat.  Says they are undefined.

I am attaching a word document with what I am using.  I have been trying to figure this out since yesterday.

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Great - so the cheat way is to assign this to 'that' right before the function --> var that = this;

Then inside the function use: that.map.....

From what I can tell, the fancy way is to use lang.hitch from dojo (dojo/_base/lang — The Dojo Toolkit - Reference Guide)) .

View solution in original post

0 Kudos
7 Replies
by Anonymous User
Not applicable

I have two thoughts:

  1. When you create your new SimpleMarkerSymbol pass it parameters for size and color so it will draw on the map [new SimpleMarkerSymbol(style, size, color)]
  2. I have run into undefined errors when the scope of the function can no longer reach the map. It is possible that 'this.map' is undefined within your callback so the function to 'add' is not available. There are fancy dojo hitch functions to deal with this but for testing to see if that's the issue, you could try to print 'this.map' to the console and see if it is undefined.
0 Kudos
MarkYerington
Occasional Contributor III

I got the map, but when it gets to the graphics shows undefined for some reason.

0 Kudos
by Anonymous User
Not applicable

That's an interesting image you attached...I'm no expert but it looks like the 'map' that is printing is actually the HTML map div element, not the javascript map object. Is it possible that earlier in your code the 'map' variable was overwritten by referencing the div (maybe by using it's id, 'map')?

Because it is returning the HTML, the graphics property would definitely be undefined.

0 Kudos
by Anonymous User
Not applicable

try printing just 'this' and see what it is actually referencing, maybe it's the DOM.

0 Kudos
MarkYerington
Occasional Contributor III

Yes it is losing the this.map as soon as I get into the project function.

gsvc.project([inpoint], outSR, function(projPoints) {

once I enter this the reference to the map is lost.

0 Kudos
by Anonymous User
Not applicable

Great - so the cheat way is to assign this to 'that' right before the function --> var that = this;

Then inside the function use: that.map.....

From what I can tell, the fancy way is to use lang.hitch from dojo (dojo/_base/lang — The Dojo Toolkit - Reference Guide)) .

0 Kudos
MarkYerington
Occasional Contributor III

Thank you so much Sarah.

0 Kudos