Open new browser window on map click

1055
5
Jump to solution
08-27-2014 06:48 AM
RyanSellman
Occasional Contributor II

I am working on a simple app that lets you click on the map and open a new browser window showing oblique imagery at that point.  It takes the point coordinates, passes them to a url and opens a new browser page using the created url.  I think I am close, but with what I have now, when the page loads and you click on the map I get an error saying, "Cannot read property 'y' of undefined".  However if I click again my function works and the page opens properly.  If you continue to fire the function it continues to work.  It gets messed up with only the first attempt.  Any ideas???

Here is the app: JSFiddle

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
RiyasDeen
Occasional Contributor III

Hi Ryan,

In your fiddle move line 92 to after line 89. Like below:

                    gsvc.project([point], outSR, function (projectedPoints) {

                            pt = projectedPoints[0];

  window.open("http://fiscalims.summitoh.net/GVViewer/ViewerAX.htm?res=2&lat=" + pt.y.toFixed(5) + "&lon=" + pt.x.toFixed(5));

                        });  

What's happening is,

your window.open will always get executed before project is completed. For the first time it'll fail because pt would be null, from next time on it'll use the X and Y from your previous project operation.

View solution in original post

5 Replies
RiyasDeen
Occasional Contributor III

Hi Ryan,

In your fiddle move line 92 to after line 89. Like below:

                    gsvc.project([point], outSR, function (projectedPoints) {

                            pt = projectedPoints[0];

  window.open("http://fiscalims.summitoh.net/GVViewer/ViewerAX.htm?res=2&lat=" + pt.y.toFixed(5) + "&lon=" + pt.x.toFixed(5));

                        });  

What's happening is,

your window.open will always get executed before project is completed. For the first time it'll fail because pt would be null, from next time on it'll use the X and Y from your previous project operation.

RyanSellman
Occasional Contributor II

Awesome.  That was it.  I appreciate the help as well as the explanation as to what was going on.

Thank you!

0 Kudos
RyanSellman
Occasional Contributor II

Hi Riyas,

You have answered my initial question, but I have stumbled upon another problem with my app and rather than start a new discussion I thought it would be appropriate to reply in this one.

What I am trying to do now is create a simple checkbox that will enable or disable the openGeovista function on click.  Like with the first issue, I am close.  Right now when the page loads, the box is checked but the function won't fire.  When I toggle the checkbox off, then back on again, the function works.  Here is the fiddle - JSFiddle. I have to be missing something really small.  Any help is much appreciated!

0 Kudos
RiyasDeen
Occasional Contributor III

Hi Ryan,

Two corrections in your code.

  • You did't wire the map load event to MapReady function. Add below line before your map.addLayers([orthos]);

map.on("load", mapReady);

  • In your map ready function id of your checkbox is wrong.It should be gvmCheckbox not popupCheckbox
RyanSellman
Occasional Contributor II

Hi Riyas!

Sorry for the delay in my response. That was it!  I knew it was something small that I was missing!

Thanks so much for your help, again!

Ryan

0 Kudos