[mapguide-users] Re: Getting layer's maxscale to Viewer API

Johannes Foell jfoell at uos.de
Thu Feb 18 09:57:14 EST 2010


You have exactly pointed out what i need.

Unfortunately I'm using code inline and not codebehind. The first way, which
you presented doesn't work in my code.

As newbie to JSON i've tested your second solution, but i do'nt get the
scale to the client there, too.
Does anyone here knows, how to deliver a JSON-object from the server to the
client? What is wrong in my code?

The important lines are:
In VB.NET:

Sub reload (ByVal o As Object, ByVal e As EventArgs)

  MaxSc is the double-variable, which contains the MaxScale for the Layer.

  Dim MString As String = "{" + Chr(34) + "double" + Chr(34) + ":" + Chr(34)
+ MaxSc.ToString + Chr(34) + "}" ' e.g. the JSON-Object:
{"double":"31456.57"}

  Dim serializer As New JavaScriptSerializer

  Dim json As String = serializer.Serialize(MString)
End Sub


In JS:

function ZoomToView()
{
var url; //the current aspx-file
var maxsc;
var maxsc2;
try {
  var request = new XMLHttpRequest();
} catch(ex) {
  try {
    var request = new ActiveXObject("MSXML2.XMLHTTP");
  } catch (ex) {
    var request = new ActiveXObject("Microsoft.XMLHTTP");
  }
}
request.onreadystatechange = function() {

if(request.readyState == 4) {
  maxsc2 = eval("(" + request.responseText + ")"); //what do i have to call
here?
}
}
request.open("GET", url, true);
request.send();
maxsc = maxsc2.double; //the double-field of the object
maxsc -= 0.1; //to show the layer in the map
parent.KartenFrame.viewerFrame.mapFrame.ZoomToView(xcoord,ycoord,maxsc,true);
//the coordinates are no problem. if i set here a number as maxsc, e.g.
15000, it works
}



Thanks for any help.
Regards,
Johannes Foell



Kenneth Skovhede, GEOGRAF A/S wrote:
> 
> Not sure this is what you are asking but, this is how I understand your 
> question.
> 
> Basically the output of an ASPX page is html (or any format really).
> Since you want to output the scale, you would want the following html 
> output:
> <html><body><script>
> var maxScale = <%=serverGeneratedMaxScale%>;
> GetMap().ZoomToView(x, y, maxScale);
> </script></body></html>
> 
> (I've left out the GetMap() and x, y code).
> 
> The <%=serverGeneratedMaxScale%> gets processed by the ASP.Net runtime,
> and inserts the value of the variable named "serverGeneratedMaxScale" in 
> th output.
> 
> In your codebehind file, just declare a public instance variable with 
> that name,
> and insert the above code in the aspx (below the codebehind declaration),
> and it should come out.
> 
> 
> Another slightly more sophisticated way of doing this, is to issue and 
> AJAX call
> and have the page return a JSON object string like:
> {x: 333, y: 444, maxScale: 555}
> 
> Then in your Ajax callback handler do this:
> var obj = eval('(' + responseText + ')');
> GetMap().ZoomToView(obj.x, obj.y, obj.maxScale);
> 
> I can't remember what the AJAX stuff is called in the viewer, but there
> are
> plenty of free AJAX helper code avalible online.
> 
> The benefit of using an AJAX call is that the user cannot pres "back",
> there is no "click" sound, and you don't need to mess with hidden frames.
> 
> Regards, Kenneth Skovhede, GEOGRAF A/S
> 
> On 15-02-2010 16:25, Johannes Foell wrote:
>> Hi List,
>>
>> I'm new to MG (and JS) and have a question about the layer's maxscale. I
>> can
>> read the maxscale out of the Layerdefinition using a XML-File. Having the
>> maxscale read out for each layer, I need the highest maximum for the
>> layergroup at the Viewer API to zoom to a given coordinate and this
>> maxscale.
>> Currently i compare the different maxscales and save the largest number
>> as
>> double. Writing this double to a new XML-File, i can't read it to the
>> Viewer
>> API.
>>
>> Is there a way to get this maxscale to the Viewer API and the method
>> ZoomToView()?
>>
>> I'm using VB.Net and JS.
>>
>> Or is there just another solution?
>>
>> Thanks for any hint in advance.
>> Best regards,
>> Johannes Foell
>>    
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> 
> 

-- 
View this message in context: http://n2.nabble.com/Getting-layer-s-maxscale-to-Viewer-API-tp4575036p4592172.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list