Select to view content in your preferred language

Passing variables from external html page

721
5
10-19-2010 04:59 AM
CaseyBentz
Occasional Contributor II
Hello all,

I am working in adding Google Street View to my Flex application. I have it working as browser popup.  What I would like is for this browser to pass back the current lat/lon to my Flex application.  I have attempting to incorporate some code that I found, but it looks like it only works when the swf is embedded in the same page as the JavaScript.  Does anyone know how/if this can be done?
Tags (2)
0 Kudos
5 Replies
BjornSvensson
Esri Regular Contributor
There is an API sample that shows how to support URL parameters like ReadURL.html?ll=37.063,-95.677&scale=500000

http://help.arcgis.com/en/webapi/flex/samples/index.html?sample=ReadURL
0 Kudos
CaseyBentz
Occasional Contributor II
So, this really won't work for what I am doing.  What I am doing is opening a popup to display Google Street View data.  As the user clicks down a road, I want to have a graphic move on the map.  So, what I am thinking is that the popup will pass the lat/lon to the flex app.  I am pretty close, but I don't really like what I have to do to make it work.  I get the lat lon back in my index.template.html and it shows the alert. But, I don't know how to get that in my flex application.

Google Street Map Popup Window
[HTML]
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Street View</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/standard.css" rel="stylesheet" type="text/css" />
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
<script type="text/javascript">
  var position = "";
  function initialize() {
    lat = getParams('lat');
    lng = getParams('lng');
    var loc = new google.maps.LatLng(lat,lng);
    var panoramaOptions = {
      position: loc,
      pov: {
        heading: 34,
        pitch: 0,
        zoom: 1
      },
      visible: true
    };
    var panorama = new  google.maps.StreetViewPanorama(document.getElementById("pano"),panoramaOptions);
    
    google.maps.event.addListener(panorama, 'position_changed', function() {
        var positionCell = document.getElementById('position_cell');
        positionCell.firstChild.nodeValue = panorama.getPosition();
position = positionCell.firstChild.nodeValue;
        sendLatLon(position);
    });
  }
  function getParams( name ){ 
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
var regexS = "[\\?&]"+name+"=([^&#]*)"; 
var regex = new RegExp( regexS ); 
var results = regex.exec( window.location.href ); 
if( results == null )   
  return ""; 
else   
  return results[1];
  }

function sendLatLon(position)
{
  //Send the lat lon back to the parent window
  window.opener.callBack(position); 
}

</script>
</head>
<body onload="initialize()">
  <div id="pano" style="width: 100%; height: 640px;z:index: 0"></div>
  <div id="footer" style="height:30px;">
If no image appears StreetView is not available
  </div>
  <div id="panoInfo" style="width: 425px; height: 240 px;float:left">
  <table>
  <tr>
    <td><b>Position</b></td><td id="position_cell"> </td>
  </tr>
  </table>
  </div>
</body>
</html>
[/HTML]

Function from my index.template.html
var flexParams = "latlon=";
function callBack(latlon){
   flexParams = "latlon=" + latlon;
   alert(flexParams);
}


Function that I use to display the street view popup.
private function mouseDownHandler(e:MapMouseEvent):void
{
 Model.instance.streetViewVis = true;
 var mapPoint:MapPoint = WebMercatorUtil.webMercatorToGeographic(e.mapPoint) as MapPoint;
 var lng:String = mapPoint.x.toFixed(13);
 var lat:String = mapPoint.y.toFixed(13);
 // launch street view
 var url:String  = "StreetView.html?lat=" + lat + "&lng=" + lng;
 var window:String = "StreetView";
 var features:String = "toolbar=no,location=no,resizable=no,directories=no,status=no,scrollbars=no,copyhistory=no,width=610,height=700";
 var WINDOW_OPEN_FUNCTION : String = "window.open";
 ExternalInterface.call( WINDOW_OPEN_FUNCTION, url, window, features );
}
0 Kudos
CaseyBentz
Occasional Contributor II
I finally got this figured out.  I will share my code when I have all the bugs worked out.  I added a callback function to my flex code, and that made all the difference.
0 Kudos
FrankRoberts
Occasional Contributor III
Don't know if this will help, but I've got some code you can look at in my Street View and more widget at:

http://www.arcgis.com/home/item.html?id=dc56d2ab11534d24a5559ea9dc8f5119
0 Kudos
CaseyBentz
Occasional Contributor II
I am about to roll this functionality into my application on my test server. I thought I would share what I did. I have attached the files I used.
0 Kudos