Jandost Khoso


Hello,

i am facing a problem while passing queryString as coordinates to MapCrunch page.

i am getting an exception about object null in my xml. whereas if i don't pass querystring it works perfect.

function LoadPage()

{

var x=getQueryVariable("x");

var y=getQueryVariable("y");

var zoom = getQueryVariable("zoom");

SetMapSize();

window.onresize = SetMapSize;

map = new VEMap('Map');

map.LoadMap();

map.SetMapStyle('h');

layerList = MSR.CVE.ImportLayersFromAnchorHRef("CrunchedLayers"); ////////////////////////////// ERROR /////////////////////////

MSR.CVE.StartAutomaticLegends(map, layerList);

var permalinkProvided = MSR.CVE.ApplyPermalink(map, document.layerCheckboxForm);

if (!permalinkProvided) {

MSR.CVE.ActivateAlphaLayer(map, layerList, 'New Layer');

MSR.CVE.SetCenterAndZoomForLayer(map, layerList, 'New Layer');

}

var pinID = 1;

var pin = new VEPushpin(

pinID,

new VELatLong(x,y),

null,

'My pushpin',

'This is pushpin number '+pinID

);

map.AddPushpin(pin);

map.SetCenterAndZoom(new VELatLong(x,y),zoom);

}





Re: Exception while sending QueryString

JeffK_


hmmm,

x and y parameters

are you passing lat/lon geocoords or what







Re: Exception while sending QueryString

Jandost Khoso

Yes,

X and Y are longtitude and latitude that i want to pass. if i declare variables directly in the page it shows me correct result but if i want to pass them by quesy string it throws an exception.







Re: Exception while sending QueryString

JeffK_

hmmm,

is your page an aspx page

if yes, you can write the values directly in the rendered html, example:

...new VELatLong(parseFloat(<% Response.Write(Request.QueryString["x"]) %>),parseFloat(<% Response.Write(Request.QueryString["y"]) %>));

for your custom querystring jabbascript function i just dont know whats wrong, coz i dont have the sourcecode.






Re: Exception while sending QueryString

Jandost Khoso

Hello,

I am using html. i sent also whole src on this post. nothing more is there.




Re: Exception while sending QueryString

Derek Chan

whats this getqueryvariable function   It doesn't look like any known javascript function.  Sounds like this is where the object exception is being called.  If you don't have this function defined anywhere in your code then this is the problem. 

According to google this is what your missing:

function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[ i ].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 





Re: Exception while sending QueryString

Jandost Khoso

i have that function and it is used to return values of queryString. Sorry, i think i have forgotten to paste that function. But as i mentioned exception comes at line 58, where call to XML file is done.
I don't know that call is not related to queryString, so why exception is thrown !




Re: Exception while sending QueryString

JeffK_

hey,

put an alert(x + "," + y); before you use the variables, to check if they are empty.






Re: Exception while sending QueryString

Derek Chan

also copy and paste your exception into a post




Re: Exception while sending QueryString

Jandost Khoso

Hello,

Actually, as i explained earlier i want to open my Map by passing queryString.

What i did was: i just rendered Map using MapCruncher, and i used its sample page in my project. When i call that page using http://localhost:2879/Map/Mapcruncher/SamplePage.html. it exactly shows what i want BUT it is hard coded. I want to push a pin on my specified point.

Now, when i try sending my desired coordinate using http://localhost:2879/Map/Mapcruncher/SamplePage.html x=24&y=51&zoom=12. it shows default location of Map Point ( USA ). and i get following javascript error:

Line: 528, Char: 18
Error: 'ChildNodes' is null or not an Object.
Code: 0
URL: http://localhost:2879/Map/Mapcruncher/SamplePage.html x=24&y=51&zoom=12.

Here is my complete Code of SamplePage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<head>

<title>MapCruncher Mashup Sample Web Page</title>

<script src="http://research.microsoft.com/mapcruncher/scripts/v4/MapControl-CVE-obfuscated.js" type="text/javascript"></script>

<script src="http://research.microsoft.com/mapcruncher/scripts/v4/CrunchControl.js" type="text/javascript"></script>

<link href="http://research.microsoft.com/mapcruncher/scripts/v4/LegendStyle.css" rel="stylesheet" type="text/css">

<script type="text/javascript">

var div = null;

var map = null;

var layerList = null;

function ToggleLayer(name, active)

{

if (active == true)

{

MSR.CVE.ActivateAlphaLayer(map, layerList, name);

}

else

{

MSR.CVE.DeactivateAlphaLayer(map, name);

}

}

function searchboxactivate()

{

txt = document.getElementById('searchbox').value;

map.Find(txt, "");

}

function GetSize()

{

var myWidth = 0, myHeight = 0;

if( typeof( window.innerWidth ) == 'number' ) {

//Non-IE

myWidth = window.innerWidth;

myHeight = window.innerHeight;

} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

//IE 6+ in 'standards compliant mode'

myWidth = document.documentElement.clientWidth;

myHeight = document.documentElement.clientHeight;

} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

//IE 4 compatible

myWidth = document.body.clientWidth;

myHeight = document.body.clientHeight;

}

if (myWidth > 0)

{

var result = new Array();

result[0] = myWidth;

result[1] = myHeight;

return result;

}

else

{

return null;

}

}

function SetMapSize()

{

var browserSize = GetSize();

var div = document.getElementById("Map");

if (browserSize != null)

{

div.style.width = (browserSize[0] - 25) + "px";

div.style.height = (browserSize[1] * 0.75) + "px";

}

else

{

div.style.width = "800px";

div.style.height = "600px";

}

div.style.overflow = "hidden";

div.style.position = "relative";

}

function LoadPage()

{

var x=getQueryVariable("x");

var y=getQueryVariable("y");

var zoom = getQueryVariable("zoom");

SetMapSize();

window.onresize = SetMapSize;

map = new VEMap('Map');

map.LoadMap();

map.SetMapStyle('h');

layerList = MSR.CVE.ImportLayersFromAnchorHRef("CrunchedLayers");

MSR.CVE.StartAutomaticLegends(map, layerList);

var permalinkProvided = MSR.CVE.ApplyPermalink(map, document.layerCheckboxForm);

if (!permalinkProvided) {

MSR.CVE.ActivateAlphaLayer(map, layerList, 'New Layer');

MSR.CVE.SetCenterAndZoomForLayer(map, layerList, 'New Layer');

}

var pinID = 1;

var pin = new VEPushpin(

pinID,

new VELatLong(x,y),

null,

'My pushpin',

'This is pushpin number '+pinID

);

map.AddPushpin(pin);

map.SetCenterAndZoom(new VELatLong(x,y),zoom);

}

function getQueryVariable(variable) {

var query = window.location.search.substring(1);

var vars = query.split("&");

for (var i=0;i<vars.length;i++) {

var pair = varsIdea.split("=");

if (pair[0] == variable) {

return pair[1];

}

}

alert('Query Variable ' + variable + ' not found');

}

</script>

</head>

<body onload="LoadPage()">

</form>

<div id="Map"></div>

<div style="display:none">

<a id="CrunchedLayers" href="MapLayers.crunched.xml">CrunchedLayers</a>

</div>

<div id="legendBox">

<div id="legendBody">

Legends

</div>

</div>

<div id="selectedLegendBox">

<table bgcolor="white" width="100%">

<div id="closeLegendBox">

<tr>

<td>

<font face="Arial" color="#3030b0"><b>

<div id="selectedLegendTitle"></div>

</b></font>

</td>

<td width="20">

<font face="Arial" color="red">

<a href=DisplayLegend(null);">X</a>

</font>

</td>

</tr>

</div>

</table>

<div id="selectedLegendBody">

</div>

</div>

</body>

</html>