ThinkGeo.com    |     Documentation    |     Premium Support

Silverlight's Map Control Size

Hi everybody


Is it possible to set silverlight's Map control size to stretch through the entire silverlight's page?. If possible, how? If not possible, what is the maximum allowable width and height?


Best Regards,


Vincent



Hi, Vincent


Generally you can't set the Map Control width in % like 100% so that the Silverlight contents can spread in the full screen.
 
It is possible to programmatically resize the Silverlight Map Control through the HTML DOM. To get the 100% width of screen you need to get the screen with and height and set it dynamically when window resizes.
 
Please refer to the attached sample.
 
Thanks,
 
Khalil 

AutosizeSilverlightMapControl.zip (18 KB)

Hello, 
  
 Can you explain code line : control.Content.MainPage.UpdateSize(); 
 I can’t find any documentation about this… 
  
 Thank you

 


Hi Ivan,
In fact the UpdateSize method is not a pubic API of MapSuiteSilverlightEdition, so you can’t find any documentation of it. As you can see from the project SilverlightApplicationForVincent, in the file MainPage.xaml.cs, there’s a public method called UpdateSize, it’s been marked with an attribute ScriptableMember. To call this method on page, you’ll have to use the code line control.Content.MainPage.UpdateSize() in JavaScript in order to implement the AutoResize function of Map Control on html page.
Further questions please let me know.
Thanks.
James

Hello James, 
  
 Thanks for you help. But I have the same trouble with you control. Please help me. (Sorry for my bad English :) ) 
 My code 
  
 MainPage.xaml.cs 
 
public partial class MainPage
{
    private double MapWidth { set { map.Width = value; } }
    private double MapHeight { set { map.Height = value; } }

    private void MainPageLoaded(object sender, RoutedEventArgs e)
    {
      InitializeMapProperties();
      HtmlPage.RegisterScriptableObject(“MainPage”, this);

      SetLayersIntoMap();

      map.ZoomTo(new PointShape(46969, 7912.9083084551612), 5);
      map.ZoomToScale(2252);
    }

    [ScriptableMember()]
    public void UpdateSize(double width, double height)
    {
      MapWidth = width;
      MapHeight = height;
    }
}
 
  
 Code in MapPage.aspx 
 
<%@ Page Language=“C#” MasterPageFile="~/MasterPages/Core.Master" AutoEventWireup=“true”
         CodeBehind=“MapPage.aspx.cs” Inherits=“sLive.Web.PublicPages.MapPage” %>
<%@ Register Assembly=“SilverlightMapConnector” Namespace=“ThinkGeo.MapSuite.SilverlightEdition”
             TagPrefix=“thinkGeo” %>

<asp:Content ID=“HeadContent” ContentPlaceHolderID=“HeadPlaceHolder” runat=“server”>
  <script type=“text/javascript”>
    function resizeContent() {
      var docHeight = $(window).height() - 2;
      var headerHeight = $(’#header’).height();
      var footerHeight = $(’#footer’).height();

      $(’#container’).height(docHeight);
      $(’#page’).height(docHeight - headerHeight - footerHeight);

      updateSize($(’#map’).width(), $(’#map’).height());
    }

    function updateSize(width, height) {
      var control = $(’#<%= SilverlightMapConnector1.ClientID %>’);
      control.Content.MainPage.UpdateSize(width. height);
    }
  </script>
</asp:Content>



<asp:Content ID=“BodyContent” ContentPlaceHolderID=“BodyPlaceHolder” runat=“server”>
  <div id=“map”>
    <thinkGeo:SilverlightMapConnector runat=“server” ID=“SilverlightMapConnector1”
        Source="~/ClientBin/sLive.Web.Map.xap" Height=“100%” Width=“100%”>
    </thinkGeo:SilverlightMapConnector>
  </div>
</asp:Content>
 
  
 In browser I see the following error: 
 Uncaught TypeError: Cannot read property ‘MainPage’ of undefined

 


Ivan,
As far as I can see from your code sample, the error is most probably caused by the code line below:
HtmlPage.RegisterScriptableObject("MainPage", this);
 
I’m wondering if this usage is right because register a Silverlight object into Html page is rarely seen. According to the error message, I’m guessing that either the browser cannot recognize the MainPage object in Html or the process is conflict with the MainPage object initialization.
Could you please be more specific about your requirement, so that we can figure out the best way to implement what you want?
Thanks.
James

But you use this line in the sample for Vincent and in the same function (Load event) and all alright… Why are you wondering, i don’t understand 
 HtmlPage.RegisterScriptableObject(“MainPage”, this); 

 


Ivan,
After reviewing the demo Khalil provided, I found that it’s correct to use RegisterScriptableObject of HtmlPage like that and it should be working fine, thank you for the amending.
Therefore, I went back to the code sample you provided, and compared it with the code sample that works fine. It seems that the way you try to get access the SilverlightMapConnector1 in the MapPage.aspx is a little bit different from the sample that works fine, so, I checked the Html source of the sample, and I guess I figured out why you encountered the problem you described.
In fact, SilverlightMapConnector is a compound control, when being generated on the client, it’s created with the ID “SilverlightMapConnector1”, so the code line “var control = $('#<%= SilverlightMapConnector1.ClientID %>')” in the updateSize function may not work.
 
Could you please try to modify it or replace it with the code line in Khalil’s sample, which is, var control = document.getElementById('SilverlightMapConnector1'), to see if it works fine?
 
If’s the problem is still there, would you like to send us the sample that produces this error? We can have a thorough debug with our source code and have the bug fixed.
 
Thanks.
James