Register  |  Login
ThinkGeo - GPS Tracking and Mapping Solutions  |  Home  |  Cygnus Track  |   Code Community

Discussion Forums

The online community for users of Map Suite GIS components

RSS Feed Available AddThis - Bookmarking and Sharing Button Printer Friendly

PrevPrev NextNext

Map Suite Silverlight Edition 4.0 QuickStart Guide

Posted by ThinkGeo on 12-18-2008 10:21 AM

The Map Suite Silverlight Edition illustrated QuickStart Guide will guide you through the process of creating a sample application and will help you become familiar with Map Suite. This edition of the QuickStart Guide supports Silverlight Edition 4.0.0.0 or higher.

Download Sample Code From This Exercise - C#

Download Sample Code From This Exercise - VB.NET

Welcome to Map Suite™ Silverlight Edition from ThinkGeo, a full-featured mapping control that makes it easy for any Microsoft .NET developer to add mapping functionality to a Microsoft .NET and Silverlight application quickly and efficiently. Using the intuitive object model, even developers inexperienced in Geographic Information Systems (GIS) can have fully functional maps working in minutes.

The purpose of this guide is to help you quickly get started building your own spatially aware applications. Like any new software, there is some learning to be done along the way.

How do we start to learn how to take advantage of the power of Map Suite? The best way is to make a sample application with it.

(For the purposes of this guide, let's assume we have installed the Map Suite Silverlight Edition 4.0 to the default folder "C:\Program Files\ThinkGeo\Map Suite Silverlight Evaluation Edition 4.0\")

Setting up the Environment

Before you begin, you'll need to download and install one of the following:

These add-ons for Visual Studio or Visual Web Developer Express will install the necessary Visual Studio updates, Silverlight project templates, developer runtime, and SDK.

Let's start with a new ASP.NET Silverlight Application in Visual Studio.NET 2008 IDE and call it "HelloWorld" (see Figures 1, 2, and 3). Set the Templates to ".NET Framework 3.5" for the project.

Screenshot

Figure 1. Creating a new project in Visual Studio.NET 2008 IDE.

Screenshot

Figure 2. Select Silverlight Application and name it "HelloWorld".

Screenshot

Figure 3. Choose "Add a new ASP.NET Web project to the solution to host Silverlight."

Adding the Map Control to the Visual Studio.NET IDE Toolbox

1. When you first open the Visual Studio.NET IDE after installing Map Suite, you may not see the control in the Toolbox. You will need to follow these steps to add the control.

First of all, let's add the control for the Silverlight Toolbox. Double-click Page.xaml in the HelloWorld project, make sure your toolbox contains Silverlight XAML controls, then hover over the Toolbox and right-click anywhere on the list of controls. You will get a pop-up menu. Select "Choose Items..." (See Figure 4)

Screenshot

Figure 4. Select "Choose Items."

2. The "Choose Toolbox Items" dialogue will appear. Within this dialogue, switch to the Silverlight Components tab; then click the "Browse..." button. Finally, navigate to the "C:\Program Files\ThinkGeo\Map Suite Silverlight Evaluation Edition 4.0\Developer Reference\Silverlight Edition\Client\SilverlightEdition.dll" file.

Screenshot

Screenshot

The "Map" control will appear in the Choose Toolbox Items list. Click OK to confirm this operation.

3. You should now have the Map control available in your Toolbox as shown in Figure 6 below.

Screenshot

Figure 6. Silverlight Map is now available in the toolbox.

4. Let's go to the XAML code area, and make the UserControl bigger. We'll set it to 800x600. (See Figure 7)

Screenshot

Figure 7. Set the user control's size to 800x600.

5. Drag the map icon from the toolbox into the XAML code, then set its name to "Map1" and its size to 800x600. (See Figure 8)

Screenshot

Figure 8. The Silverlight map namespace is now added into XAML automatically.

Add the SilverlightMapConnector to the Toolbox

Screenshot

Screenshot

Screenshot

Screenshot

Now the SilverlightMapConnector can be dragged onto your aspx page. Let's drag one into the Default.aspx page now. In order to work with a Silverlight map, you also need to drag a ScriptManager onto the web page.

Screenshot

Map Suite Silverlight "Hello World" Sample

1. Copy Shape data files (SHP, SHX, DBF, IDS, IDX...) into Silverlight application, and set their build action to "Content".

Silverlight applications run at the client's machine, so these Shape files will be integrated into the XAP file and run at the client side. Later, we'll introduce a way to render your map at the server side.

Screenshot

2. Add "SilverlightEdition.dll", "SilverlightMapSuiteCore.dll", "SilverlightGeoApi.dll", and "SilverlightNetTopologySuite.dll" to the Silverlight project reference.

Here we use ShapeFileFeatureLayer, so we can access the files in isolated storage or load them from resource. For this example, we'll choose to load them from resource. If you want to load from isolated storage, please remove the StreamLoading event line from the code below.


using System;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Resources;
using ThinkGeo.MapSuite.SilverlightEdition;

namespace HelloWorld
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Page_Loaded);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            
         Map1.MapUnit = GeographyUnit.DecimalDegree;

        ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer("STATES.SHP");
        
        // Add a handler to load shape files from resource.
        // If you remove this handler, the map control will find Shape files from isolatedStorage,
        // so in that case, please make sure your Shape file is in the isolatedStorage first.
            ((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading += new EventHandler<StreamLoadingEventArgs>(StatesLoadAShapeFile_StreamLoading);

        // Set the statesLayer's style
            statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);

        // This setting will apply from ZoonLevel01 to ZoomLevel20.
        // That means we display the map in the same style as ZoomLevel01 at all times, no matter how far we zoom in or out.
            statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        // We need to add the world layer to its overlay.
            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.Layers.Add(statesLayer);

        // We need to add the overlay to the map.
            Map1.Overlays.Add(layerOverlay);

        // Set a proper center and zoom level Id for the map; that's the place you want it to display.
        // Please see the overload of this method.
            Map1.ZoomTo(new PointShape(-100, 35), 4);
        }

    // Load Shape files from resource.
        private void StatesLoadAShapeFile_StreamLoading(object sender, StreamLoadingEventArgs e)
        {
            switch (System.IO.Path.GetExtension(e.AlternateStreamName).ToLower())
            {
                case ".shp":
                    StreamResourceInfo sr = Application.GetResourceStream(new Uri(@"App_Data/STATES.SHP", UriKind.RelativeOrAbsolute));
                    e.AlternateStream = sr.Stream;
                    break;
                case ".dbf":
                    e.AlternateStream = Application.GetResourceStream(new Uri("App_Data/STATES.DBF", UriKind.RelativeOrAbsolute)).Stream;
                    break;
                case ".shx":
                    e.AlternateStream = Application.GetResourceStream(new Uri("App_Data/STATES.SHX", UriKind.RelativeOrAbsolute)).Stream;
                    break;
                case ".idx":
                    e.AlternateStream = Application.GetResourceStream(new Uri("App_Data/STATES.idx", UriKind.RelativeOrAbsolute)).Stream;
                    break;
                case ".ids":
                    e.AlternateStream = Application.GetResourceStream(new Uri("App_Data/STATES.ids", UriKind.RelativeOrAbsolute)).Stream;
                    break;
                default:
                    break;
            }
        }

    }
}

If you compile and run what you have now, your map should look like the one below. (See Figure 9)

Screenshot

Figure 9. A simple map of the US.

Navigate the Map

With the code above, not only can you display a map, but you can also navigate it. You can pan by dragging the map; track zoom in by drawing a rectangle with your left mouse button mouse while holding the shift key; navigate by using the controls at the top left corner of the map, or zoom in and out by using the mouse wheel. Very powerful for just couple lines of code, isn't it?

How to Use the TextStyle

TextStyle

The TextStyle is used to label items on map. Because every Shape file has a related .dbf file that includes descriptions for each record, the most common way to use the TextStyle is for labeling. For example, the Shape file containing the names of the states of the US has a corresponding .dbf file that contains the field "STATE_NAME". We can use this field to label the states on our map. (See Figure 10)

Screenshot

Figure 10. The STATE_NAME column in the DBF file.

Map Suite has many TextStyles built in that will help us quickly design attractive labels for the states on our map. We can just pick the TextStyle we like and use it.


private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Map1.MapUnit = GeographyUnit.DecimalDegree;
            
        ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer("STATES.SHP");
        ((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading += new EventHandler<StreamLoadingEventArgs>(StatesLoadAShapeFile_StreamLoading);
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);
    
        // We'll use a preset TextStyle. Here we passed in the "STATE_NAME", which is the name of the field we want to display on map.
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Canal1("STATE_NAME");
        statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            
        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(statesLayer);
        Map1.Overlays.Add(layerOverlay);
    
        // Set the center and zoom level Id to locate the map's position.
        Map1.ZoomTo(new PointShape(-100, 35), 4);
    }

The result is as follows (Figure 11):

Screenshot

Figure 11. Map of the US with states labeled.

Now that we know how to render text and render symbols, let's define two different ZoomLevels for one single layer.


private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Map1.MapUnit = GeographyUnit.DecimalDegree;
    
        // Set the background color to make the map beautiful.
        Map1.Background = new SolidColorBrush(Color.FromArgb(255, 156, 187, 216));
            
        ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer("STATES.SHP");
        ((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading += new EventHandler<StreamLoadingEventArgs>(StatesLoadAShapeFile_StreamLoading);
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Canal1("STATE_NAME");
        statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level05;
        
        statesLayer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromHtml("#EFEFEF"), GeoColor.FromHtml("#CCCCCC"), 1);
        statesLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = TextStyles.Capital3("STATE_NAME");
        statesLayer.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        
        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(statesLayer);
        Map1.Overlays.Add(layerOverlay);
        
        Map1.ZoomTo(new PointShape(-100, 35), 4);
    }

Can you imagine what the map will look like now? Figures 12 and 13 below demonstrate the result. At first it looks the same as it did in Figure 11. Now zoom in, and watch the map change to resemble Figure 13 as you do.

Screenshot

Figure 12. Map of US states with two ZoomLevels, before zooming in.

Screenshot

Figure 13. Map of US states two ZoomLevels, after zooming in.

How to Render a Map at the Server Side

If there are too many shapes drawn at the client side, the performance of your Silverlight application will slow down. To get around this, you can choose to render an overlay at the server side. The following steps will show you how to do that.

ServerLayerOverlay

This overlay helps you create a simple WMS server, which is used by the map control to get map tile images.

First, copy the country shape file data into the web project:

Screenshot

You may be asking how the ServerOverlay gets rendered on the client side. In the SilverlightEdition.dll, there is a ServerOverlay object which, on the client side, is just a "shell" that will accept the actual overlay that is created on the server side by the SilverlightMapConnector.dll. We use a connector ID to keep track of these overlays as they pass from the server to the client side.

Code in Default.aspx.cs in the Silverlight project:


using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.SilverlightEdition;

namespace HelloWorld.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                
                ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/app_data/cntry02.shp"));
                worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);
                worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
                ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer");
                layerOverlay.Layers.Add(worldLayer);

                SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay);
            }
        }
    }
}

Code in Page.xaml.cs in the Silverlight project:


private void Page_Loaded(object sender, RoutedEventArgs e)
    {
        Map1.MapUnit = GeographyUnit.DecimalDegree;
        Map1.Background = new SolidColorBrush(Color.FromArgb(255, 156, 187, 216));
        
        ServerLayerOverlay serverOverlay = new ServerLayerOverlay("NativeServer", "SilverlightMapConnector1");
        Map1.Overlays.Add(serverOverlay);
        
        ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer("STATES.SHP");
        ((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading += new EventHandler<StreamLoadingEventArgs>(StatesLoadAShapeFile_StreamLoading);
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 243, 239, 228), GeoColor.FromArgb(255, 218, 193, 163), 1);
        statesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.Canal1("STATE_NAME");
        statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level05;
        
        statesLayer.ZoomLevelSet.ZoomLevel06.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromHtml("#EFEFEF"), GeoColor.FromHtml("#CCCCCC"), 1);
        statesLayer.ZoomLevelSet.ZoomLevel06.DefaultTextStyle = TextStyles.Capital3("STATE_NAME");
        statesLayer.ZoomLevelSet.ZoomLevel06.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        
        LayerOverlay layerOverlay = new LayerOverlay();
        layerOverlay.Layers.Add(statesLayer);
        Map1.Overlays.Add(layerOverlay);
        
        Map1.ZoomTo(new PointShape(-100, 35), 4);
    }

Don't forget to set the "Default.aspx" file as the Start Page. Click "Run" to see what the map looks like.

Screenshot

Screenshot

Summary

You now know the basics of using Map Suite Silverlight Edition and are able to start adding this functionality into your own applications. Let's recap what we have learned about the object relationships and how the pieces of Map Suite work together:

  1. It is of the utmost importance that the units of measurement (feet, meters, decimal degrees, etc.) be set properly for the map, based on the requirements of your data.
  2. Shape files provide the data used by Map Suite to render a map. You can choose to load them from a resource or memory.
  3. A Map is the basic class that contains all of the other objects that are used to define how the map will be rendered.
  4. A Map has one-to-many Overlays. An Overlay contains one-to-many Layers. A Layer contains the data (from Shape files or other data source) for drawing.
  5. A Layer can have one-to-many ZoomLevels. ZoomLevels help to define ranges of when a layer should be shown or hidden.

If you have questions about anything covered in this QuickStart Guide, the ThinkGeo Support Team is ready and available to help. If we can be of any assistance, please contact us using one of the methods below:

Free Discussion Forums: ThinkGeo Discussion Forums
Pre-Sales & Customer Support: ThinkGeo Customer Portal
Support Phone: 1-866-847-7510
1-785-727-4133 (Outside North America)
Web Site: http://thinkgeo.com

Download Sample Code From This Exercise - C#

Download Sample Code From This Exercise - VB.NET



57 Comments

ThinkGeoUser is Offline
04-09-2009 01:39 AM
Avatar

Don't forget to check out the Silverlight Edition support forum for swift answers to all of your questions about Map Suite Silverlight Edition.



ClintUser is Offline
04-29-2009 11:59 AM
Avatar
Can you please post the code for this hello world project? I tired to recreate it and I'm having troubles.


BenUser is Offline
04-30-2009 05:44 AM
Avatar
We will review this guide and post the corresponding project, sorry for the inconvenience.

Thanks,

Ben


GordonUser is Offline
05-14-2009 06:17 AM
Avatar
In the first active code window above, you're inserting a Handler to override a particular method; however, I'm trying to do this in VB and can't seem to work out the correct code. The line which is puzzling me is:

((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading += new EventHandler(StatesLoadAShapeFile_StreamLoading);

It's really the object which is having an event handler assigned to it that I can't understand, i.e. the notation of ((ShapeFileFeatureSource)statesLayer.FeatureSource).StreamLoading.

Have you any hints on where I can look for an answer to my confused state ?


HowardUser is Offline
05-15-2009 02:14 AM
Avatar

Gordon,

In Silverlight, we can’t open a local file on client side because of the security issue. In the HelloWorld sample, we load the resource stream directly instead of loading from File; also we support loading files from isolated storage, but as far as I tested, it’s much slower than loading from the stream. So we recommend you to use the method in our sample.

Here attached the VB code for Silverlight project. Also we’ll attach the VB sample on the website soon.

Any questions please let me know.

Thanks,

Howard

GordonUser is Offline
05-15-2009 05:24 AM
Avatar
Hello Howard,

Thanks very much for your swift reply. You certainly answered my question, but I was wondering if there was another way of getting hold of the VB code that you kindly attached to the message above as I don't seem to be able to save it to file from this page.

Regards,

Gordon


HowardUser is Offline
05-18-2009 01:38 AM
Avatar
Hi Gordon,

Sorry for the bad link, we attached the HelloWorld sample for VB at the beginning of this page,

If you have more queries please let me know.

Thanks,

Howard


DanielUser is Offline
05-19-2009 10:57 PM
Avatar
Hi,

I'm trying to get the server-generated overlay part of the demo working but I'm getting a problem. When I hit Default.aspx I get an error page, the important bits seem to be:

Parser Error Message: Could not load file or assembly 'System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

and

LOG: Post-policy reference: System.Web.Silverlight, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/a0fe9c51/763ab2c7/System.Web.Silverlight.DLL.
LOG: Attempting download of new URL file:///c:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/Temporary ASP.NET Files/root/a0fe9c51/763ab2c7/System.Web.Silverlight/System.Web.Silverlight.DLL.
LOG: Attempting download of new URL file:///C:/temp/MapTest/MapTest/MapTest.Web/bin/System.Web.Silverlight.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

I'm in a SL 3.0 beta environment, but I havent had a problem using the control before this. I'm pretty new to ASP, .NET and SL so I'm not sure whats going on here. All the appropriate references seem to appear in the project view.

The intellisense is also telling me it doesnt understand SilverlightMapConnector even though I added it to the toolbox and theres a 'Register Assembly' directive at the top of Default.aspx about it as well. What have I missed here??


BenUser is Offline
05-25-2009 06:16 AM
Avatar

Daniel,

Sorry for the delay on our end. Seems that's because the bin folder is removed, please have a look at one post here.

http://silverlight.net/forums/t/50608.aspx

I'm not sure why your intellisense cannot find the SilverLightMapConnector. Can you send your project to us so we can recreate it? Also, we will have our SilverLight Beta 2 released very soon (tomorrow maybe) and please have a try on that one.

Thanks,

Ben



ChristianUser is Offline
07-06-2009 02:25 AM
Avatar
I am attempting to get the server side rendering to work. I followed the instructions here but on the line below I get "Object reference not set to an instance of an object". However, when I hover my mouse over the three objects (Map1, Map1.Overlays, serverOverlay), all objects ARE set to instances of objects. What could be going wrong?

Map1.Overlays.Add(serverOverlay);


HowardUser is Offline
07-06-2009 04:43 PM
Avatar
Hi Christian,

Did you set default.aspx as start page or just use the default one (TestPage.aspx)? The start page need to be the with the server-rendering code (Many users just click F5 to run this sample when coding completed; but in Silverlight Application, TestPage.aspx is the default start page, and it's not what we want to start).

On the other hand, please check the parameters of the ServerLayerOverlay on both Silverlight Side and Server Side, they need to be cooperate to make the server rendering right.

If you still has some issue, please send us your project and we'll find the issue for you.

Thanks,
Howard


ChristianUser is Offline
07-06-2009 07:45 PM
Avatar
I don't really understand what you are telling me. Why is the start page important? I didn't create an application from scratch; I put a new page in my existing web solution, and copied the code from this page. The code is exactly as posted here. I added the shape files to the App_Data folder of the web app. I added a SilverlightMapConnector to my ASP page. I added the PageLoaded events to my Silverlight app and ASP page as specified here. I can create an app from scratch but I don't really see the point. Has someone already created a HelloWorld app where the rendering is done on the server side?


ChristianUser is Offline
07-06-2009 08:02 PM
Avatar

Sorry, it seems as though the HelloWorld sample DOES do server side rendering. I thought that it was doing client side rendering because the Silverlight app has data in the App_Data folder. I will just attempt to copy what it does.



HowardUser is Offline
07-06-2009 08:04 PM
Avatar
Christian,

Start page is very important; if the start page is not the one you put the MapConnector, the server side rendering won't render correctly. We have the quick start sample at the end of this quick start, please download it and see how it works.

Any question please let me know.

Thanks,
Howard


HowardUser is Offline
07-06-2009 08:09 PM
Avatar
Christian,

There is a button at the bottom left of this reply; click it and this page will enter an advanced reply page. You can attach you sample there.

Any questions please let me know.

Thanks,
Howard


ChristianUser is Offline
07-06-2009 08:21 PM
Avatar

"Start page is very important; if the start page is not the one you put the MapConnector, the server side rendering won't render correctly"

Well, this could be my problem. Our start page is a login page where it does not make sense to put a MapConnector control. However, we do have a masterpage. Can I put the control on there?

If I put the control in the MasterPage, how can I set it up so that the Silverlight app is only launched when I run a certain ASPX page from the menu? It doesn't really make sense for the MapConnector to exist on the MasterPage because then it is being loaded every time a user navigates from page to page.



ChristianUser is Offline
07-06-2009 08:30 PM
Avatar

The ideal situation for us is to create something like a web service over the top of our shapes files, and then have the Silverlight application talk to the web service. Is this possible? Does the silverlight component talk to web services at all? If so, do we have to implement a whole OGC compliant WMS? The problem is that we really don't have the option of creating a full WMS from scratch.




ChristianUser is Offline
07-07-2009 01:10 AM
Avatar
I've had more luck with getting this to work. My problem was that the Map control had not been loaded in the Page_Loaded Silverlight event. So now I fire the code in the Map_Loaded event. It works but I keep getting this JavaScript error:

Sys.InvalidOperationException: ImageError error #4001 in control 'ctl00_mainContent_SilverlightMapConnector1':AG_E_NETWORK_ERROR

However, this is not our major issue. Our major issue is that if we delete the shapes files from the App_Data folder in the SILVERLIGHT application, we get the error "Object reference not set to an instance of an object" on the line below.

e.AlternateStream = sr.Stream;

Can we confirm that we need to put the shape files in the Xap package? The shape files could 100 meg or more!


HowardUser is Offline
07-07-2009 04:06 PM
Avatar

Christian,

Please do not put too much data to the XAP file which will transfer to the client’s machine. How do you think your customer wait half an hour for the starting of your application? I strongly recommend you to use server side rendering if you have so much data to render.

Actually, XAP is a zipped file which you can unpack it with WinRAR or other tools. If your resource’s build action is content, then you can find them in the unpacked files.

Silverlight Edition runs fine in the master page; I cannot figure out why you have the issue, but you can check the following list which may causes your issue.
1, resources in Silverlight App’s build action is “Content”.
2, check the connector Id and ServerLayerOverlay’s Id is the same on Silverlight App and Web App.

Here is a quick sample working in the Master Page, please copy the data from our installed sample.

If the issue still exists, please send us your demo.

Thanks,
Howard

ChristianUser is Offline
07-07-2009 07:38 PM
Avatar

"Please do not put too much data to the XAP file which will transfer to the client’s machine. How do you think your customer wait half an hour for the starting of your application? I strongly recommend you to use server side rendering if you have so much data to render."

That is exactly why I wrote what I wrote. We definitely want to use server side rendering. My question was "Can we confirm that we need to put the shape files in the Xap package? [even with server side rendering]" . This is what we need to know.

The sample application that you sent is missing Default.aspx. Secondly, your Silverlight application includes the shape files as content, this is our problem and this is what you were recommending against. We can't send out a Xap file which has shape files in it because they are too large.

This sample app is a perfect example of the same problem we are having. If you unzip it in to a new folder and run it exactly as is, you get repeated "Image Error" JavaScript errors.



ChristianUser is Offline
07-07-2009 09:09 PM
Avatar

OK, I have got a sample application working which does exactly what we want. I.e. it renders everything on the server side and no shape files are deployed via the Xap file. Here is the link

http://www.transferbigfiles.com/Get...bbd046eac7

Now, we just need to get this working inside our application. Our application has a MasterPage with a ScriptManager inside it. When we navigate to a page called SilverlightTaskPage.aspx, the Silverlight app should be loaded using the SilverlightMapConnector control. The Silverlight application starts up but the map does not load. I only get a series of JavaScript errors saying that there is an "Image Error". The full error is mentioned in one of my posts above.

 



HowardUser is Offline
07-08-2009 11:48 AM
Avatar
Christian,

You don’t need put the ShapeFiles in the XAP file if you using Server-Side rendering. Only if you want to render shapes on the client-side.

On my last sample, it specifies how to render on both client and side. So there are some shape files which is “content” in the Silverlight App. It doesn’t contain a default.aspx file because I’m using MasterPage and remove all useless files to make sure this app won’t confuse you.

Please paste your quick project here, we can quickly find what’s going in your application. Or could you tell me what is the Microsoft Silverlight Version are you using?

Thanks,
Howard


ChristianUser is Offline
07-08-2009 06:56 PM
Avatar
Howard,

"It doesn’t contain a default.aspx file because I’m using MasterPage and remove all useless files to make sure this app won’t confuse you. "

The web application does not compile without default.aspx. But as mentioned, if I run the Silverlight app by itself, it fires repeated JavaScript errors. This is the same problem we have in our application.

"You don’t need put the ShapeFiles in the XAP file if you using Server-Side rendering. Only if you want to render shapes on the client-side."

Yes. This is understood. The original sample was a mixture of server side and client side rendering.







HowardUser is Offline
07-09-2009 03:05 PM
Avatar

Christian,

Let’s say first of all, you need our map works in a page which works with a Master Page; secondly, the page which contains the map is not startup page; thirdly, you need a sample using server-side rendering and WMS only.

The attached file is a sample to satisfy your scenario; also please see the screenshot.

[Figure 1 : Startup Page]

[Figure 2 : Map With WmsOverlay And ServerLayerOverlay]

[Figure 3 : WmsOverlay Only]

[Figure 4 : ServerLayerOverlay Only]


Any questions please let me know.

Thanks,
Howard

TimUser is Offline
08-11-2009 11:20 AM
Avatar
Is there an easy way to color shapes in a .shp file based on a column heading?


HowardUser is Offline
08-11-2009 04:05 PM
Avatar

Tim,

Yes. We have two ways to rendering map in our Silverlight control. One is server rendering as mentioned in the quick start while another one is rendering on the client side. Both these two methods renders based on a column heading.

ValuseStyle is what your wanted. Here is the code:
ValueStyle valueStyle = new ValueStyle();   
valueStyle.ColumnName = "CNTRY_NAME";   
valueStyle.ValueItems.Add(new ValueItem("United States", new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightGreen)))); 

Also we'll release our latest version 3.0.382 these days which includes the client rendering part sample.Please see the screenshots below.

Please let me know if you have any queries.

Thanks,
Howard



TimUser is Offline
08-12-2009 12:38 AM
Avatar
Howard,

Thanks for the reply. Do you add the valueStyle to the CustomStyles of the zoomStyle? Like:
worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);


HowardUser is Offline
08-12-2009 10:33 AM
Avatar
Tim,

Yeah. One thing I want to point out is that if you set the custom style, the default style such as DefaultPointStyle is unavailable again.

Please let me know if you have any questions.

Thanks,
Howard


TimUser is Offline
08-12-2009 10:49 AM
Avatar
I'm getting the error:
Sys.InvalidOperationException: ImageError error #4001 in control 'SilverlightMapConnector1':


when I run this code:
if (!Page.IsPostBack)
{
SilverlightMapConnector1.MapUnit = GeographyUnit.DecimalDegree;
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/cntry02.shp"));
ValueStyle valueStyle = new ValueStyle();
valueStyle.ColumnName = "LANDLOCKED";
valueStyle.ValueItems.Add(new ValueItem("Y", new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.LightGreen))));
valueStyle.ValueItems.Add(new ValueItem("N", new AreaStyle(new GeoSolidBrush(GeoColor.StandardColors.Black))));
worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer");
layerOverlay.Layers.Add(worldLayer);
SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay);
}


HowardUser is Offline
08-12-2009 12:26 PM
Avatar
Tim,

I cannot figure out the issue without seeing both client code and server code. Could you provide me the quick sample so that I can check it for you?

Thanks,
Howard


TimUser is Offline
08-12-2009 12:36 PM
Avatar
Howard,

I realized my error. I didn't change my start page to the one with the server side code. Thank you for your help.


HowardUser is Offline
08-12-2009 01:24 PM
Avatar
Tim,

No problem. That's really a part which people usually miss.

Please let me know if you have more questions.

Thanks,
Howard


DiamondUser is Offline
08-12-2009 02:03 PM
Avatar
Good Day,

We are attempting to use the server-side render functionality to display a shapefile grid. The demonstration code was very helpful and allowed us to build a sample application using the shapefiles that ThinkGeo provided in the demo. Unfortunately, when we switch to referencing our own shapefile, this Javascript error results: Sys.InvalidOperationException: ImageError error #4001 in control 'ctl00_mainContent_SilverlightMapConnector1':AG_E_NETWORK_ERROR.

Do you have any idea what would cause this? I would send the shapefile for your review, but the attachment button under the advanced reply function is elluding me.

Any thoughts would be appreciated,

diamond


HowardUser is Offline
08-12-2009 04:51 PM
Avatar
Hi Diamond,

Please send the shape file to support@thinkgeo.com and ask them to forward to me. I'll check it. Also if you installed our Web Edition or Desktop Edition, there is an explore in the installed directory which you can try to open your shape file in that tool to check whether is the issue of the shape file.

By the way, could you please create another topic in the Map Suite Silverlight Edition 3.0 Support forum if you want to follow up. I think it's not easily for the other users to find their answer in this long topic.

Please let me know if you have any questions.

Thanks,
Howard


RicUser is Offline
12-15-2009 01:52 AM
Avatar
Good day to all.

i downloaded the demo in Quick Start guide, add all required references, and presss F5 (in VS2008) to run, the VS2008 JIT debugger came out:

"An unhandled exception in Silverlight Application An exception occured during the operation, making the result invalid. Check System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNeces.....

but if i right click Default.aspx then View in Browser, the page displays correctly without errors. Can someone tell me why?


SunUser is Offline
12-15-2009 04:44 AM
Avatar
Hi Ric,

This issue may happen if you haven’t specify the start page, please set the Default.aspx as start page and have a try to see what happens.

Any more questions please let us know.

Thanks,

Sun


MaximUser is Offline
12-16-2009 08:39 AM
Avatar
Hello everybody,
When trying to run the example from this topic, after opening the Web Page I try to zoom the map and get the following message drawn in the browser all over the screen "The evaluation edition has not been installed".

But I did install the Evaluation Edition from this link
http://gis.thinkgeo.com/Products/MapSuiteFreeTrialDownloads/tabid/152/Default.aspx
And I can see the map when I open the browser. So what exactly is the problem?

Thanks in advance!

Maxim


MaximUser is Offline
12-16-2009 08:43 AM
Avatar
And yet another question. I tried to insert some ESRI shape files, but they all lack .ids and .idx files, so I couldn't run the example with it.
What are those two files and how do I get it? My ESRI shapes have .dbf, .prj, .sbn, .sbx, .shp, .shp.xml, .shx files.

Thanks!


RyanUser is Offline
12-16-2009 03:10 PM
Avatar

Maxim,

You can create the .ids and .idx files with Map Suite using the following method:
ShapeFileFeatureSource.BuildIndexFile(@"C:\tmp\Countries02.shp",@"C:\tmp\Countries02.idx","CNTRY_NAME", ".*land", BuildIndexMode.Rebuild);

If you only have a couple of shapefiles you can have the indexes built for you by loading the shapefile in Map Suite Explorer. It these indexes do not exist Map Suite Explorer will prompt you to let it build them.
 

 



RicUser is Offline
12-17-2009 11:40 PM
Avatar

Hi all,

Im trying to render map at server side, following the instructions above. At this line:

SilverlightMapConnector1.MapUnit = GeographyUnit.DecimalDegree;

But strangely, SilverlightMapConnector1 has no "MapUnit" property. Also, when i compile, this error occur: Object reference not set to an instance of an object, on the 3rd line of StatesLoadAShapeFile_StreamLoading method in MainPage.xaml.cs:


case ".shp":
    StreamResourceInfo sr = Application.GetResourceStream(new Uri(@"App_Data/STATES.SHP", UriKind.RelativeOrAbsolute));
    e.AlternateStream = sr.Stream;
    break;

Can someone tell me how to solve this? since the map files are too big to put in XAP, we have no choice but to render it on the server side. 
 



HowardUser is Offline
12-18-2009 04:44 AM
Avatar
Ric,

Sorry for the inconvenience, the map unit needs to be set in our previous version. It's removed in our final release. So you don't need to set it anymore. For another question; the code is for client rendering, you don't need use it for server rendering. Please refer to the default.aspx.cs for detail.

Please let me know if you have anymore questions.

Thanks,
Howard


RicUser is Offline
12-18-2009 11:29 AM
Avatar

Hi Howard,

You mean the "sample code for this exercise" is already rendering the map from server side? i see the build action of cntry02 files in App_Data of Website are "None", STATES files in App_Data of Silverlight are "Content".


Also, when i run it, the Visual Studio JIT Debugger error occur: An unhandled exception (Unhandled Error in Silverlight Application Code 4004... did i forget something? I did set Default.aspx as start page.



HowardUser is Offline
12-20-2009 10:26 PM
Avatar
Ric,

The exercise sample has both client rendering and server rendering. On the client side, we need to set the build action to "Content" so that the files can download by Silverlight plug-in; while "None" in web site is only for server rendering. It's a normal way to access a file on the server side.

Please double check Silverlight Version is 3.0, and the HelloWorldForVB.Web or HelloWorld.Web is startup project. Also, does the attached sample works?

Looking forward your feedback.

Thanks,
Howard


RicUser is Offline
02-03-2010 01:24 AM
Avatar
Howard,

I've been busy with other projects, its just now i have time to test the Silverlight edition. i still was not able to run the demo on this page... i downloaded it, update all its references (both Silverlight and web), i set Default.aspx as start page, when i run it, the US map is displayed together with a popup titled "Visual Studio Just-In-Time Debugger", message is:
An unhandled exception ("Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError
Message: System.Reflection.TargetInvocationException: An exception occured during the operation, making the result invalid"

i wonder why no other people ask the same question here. Is there any configurations i should do with my VS2008?


JohnnyUser is Offline
02-03-2010 04:36 AM
Avatar
Ric,

The exception will be thrown when you don't set the HelloWorld.Web as the startup project event if you have set the Default.aspx as start page. Please try it again and any question please let me know.

Thanks

Johnny,


RicUser is Offline
02-03-2010 07:24 AM
Avatar
Johnny,

I forgot to set the .Web to be the startup project. After i done that, it worked, sorry.

I do have another concern. Since my map data is big, around 300+ meg, it is impossible to render it at client side. i would like to render it at server side. So when users pan/zoom, the effect is much like using Google Earth: map tiles "stream" over the internet from server. i know the sample do have both client and server rendering, but i can't figure out exactly how it worked on server side. Can you modify it so it only renders from server, storing no map data on the .xap file?


KhalilUser is Offline
02-04-2010 12:24 AM
Avatar

Ric,

Yes, we do have client and server rendering, and server rendering won’t store any map data on the .xap file but client rendering will do. We suggest that you refer to SimpleServerRendering sample in our installed samples which you can find its source code at “Samples\ServerRendering\SimpleServerRendering.xaml”. In order to use server rendering, you need to add ServerLayerOverlay to map control with the specified ID of overlay and ID of SilverlightMapConnector on the client side, the code likes below:


  ServerLayerOverlay serverLayerOverlay = new ServerLayerOverlay("NativeServer", "SilverlightMapConnector1");
            Map1.Overlays.Add(serverLayerOverlay);

And on the server side, you also need to add ServerLayerOverlay to SilverlightMapConnector with ID of overlay which is the same as client side, and then you could add any layers to this ServerLayerOverlay. The code likes below:

                ServerLayerOverlay layerOverlay = new ServerLayerOverlay("NativeServer");
                layerOverlay.Layers.Add(worldLayer);
                SilverlightMapConnector1.ServerLayerOverlays.Add(layerOverlay);

Thanks,
Khalil
 



RicUser is Offline
04-07-2010 09:11 AM
Avatar

Yes the server side rendering worked when you run it on a local computer, for example pressing F5 in VS2008, the map displayed correctly by tiles. I tried this "HowDoISamples", it runs without problems on local computer. However, when i put this Silverlight sample on IIS and tried to access it, all samples worked except the "ServerRendering" category. There are no errors on the browser, but the map simply didnt display, in other words, the map tiles were not served from the server over the internet.

I also made a simple Silverlight app, the result is the same, map tiles are not served from the server when hosting in IIS. On both Internet Explorer and Firefox, the status bar says "Waiting for xx.xx.xx.xx...",  seems like waiting for the map tiles. Can you tell me how to do this properly when hosting Silverlight apps in IIS with your Silverlight Edition?



KhalilUser is Offline
04-07-2010 09:33 PM
Avatar
Hi, Ric, if you have deployed your app on IIS 5.1, please add the default.aspx or other your own home page to the URL, just like http://macau/SliverlightSamples/default.aspx but not http://macau/SliverlightSamples. And if you work on IIS 7, you need to set it under classic mode to make it work well. Sorry for the inconvenience. If you still have this problem please let me know.

Thanks,
Khalil


RicUser is Offline
04-08-2010 09:01 AM
Avatar
You mean the Application Pools? am using IIS 7, i set the "Managed Pipeline Mode" to Classic instead of Integrated, but the result is still the same, maps not displayed. My shape files are in App_Data folder of the web (SilverlightApplication1.Web), and all files there has build action of Content. Anything else that i should configure?


KhalilUser is Offline
04-09-2010 12:45 AM
Avatar
Ric, you also need to add the default.aspx or other your own home page to the URL whatever version of iis you are using. Please have a try.
If it still can't display maps, please pay attention to whether there is error message. If yes, please provide the message for us. and if no, check whether you have set the right data folder.
Yes, it only runs well in Classic Pipeline Mode".

Thanks,
Khalil


RicUser is Offline
04-09-2010 09:40 AM
Avatar
Hi Khalil,

It is still not working, i wonder how other people get it to work. In IIS 7, i made Default.aspx as default document. Although im using Windows 7 64-bit, but it runs well when i use ASP.NET Developement Server (F5). Can you try this to replicate the problem: In your trial version, copy the whole .Web folder (C:\Program Files (x86)\ThinkGeo\Map Suite Silverlight Evaluation Edition 3.0\Samples\CSharp HowDoISamples.Web) to C:\inetpub\wwwroot, then set the Default.aspx as Default document. Then set the application pool that this site is using to Classic mode, and the Bindings of the site to http port 80 . If the IP of the server is 11.22.33.44, i use other computer on other internet to browse to 11.22.33.44. Then you will see the HowDoISample display the maps correctly for non-server rendering, try to click on "Simple Server rendering" under the "ServerRendering" category, the map didnt display. On IE, there is an error icon on the lower left. On Firefox, it says "Waiting for 11.22.33.44...".

i believe most people will be using server-side rendering for Silverlight edition because maps are normally big files. Will appreciate much if you can tell us how to make it work. And if possible, i hope the Silverlight edition has some features on controling the way tiles are served to the SL clients. For example, when our client program detects the user is not using his bandwidth, we can request the server to serve adjacent tiles in advance so when user pans, it is already in their memory, so no delays.


KhalilUser is Offline
04-11-2010 10:21 PM
Avatar
Hi, Ric

Please refer to the post below:
http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/28/aft/7362/afv/topic/afpgj/1/Default.aspx#16220

Thanks,
Khalil


LeonUser is Offline
07-14-2010 07:00 PM
Avatar

Hello,

I am following the steps outlines above and I am getting the same error that Ric got above, An unhandled exception ("Unhandled Error in Silverlight Application Code: 4004
Category: ManagedRuntimeError
Message: System.Reflection.TargetInvocationException: An exception occured during the operation, making the result invalid"

HelloWorld.Web is set as the startup project. I am using Silverlight 3. Is there anything else to try and fix this problem.

UPDATE:  I FIXED the above problem:   Under properties for HelloWorld.Web, on the "Web" tab, I change the "Start Action" from "Sepecfic Page" to "Current page"  I will continue on with the step by step instructions

However I still have the error below when I download the already completed example code:

When I download the code above (c#) and try and run it, I get the following error: Line: 437
Error: Sys.InvalidOperationException: ImageError error #4001 in control 'SilverlightMapConnector1': AG_E_NETWORK_ERROR

UPDATE: I completed the first tutorial section and I get the exact same error with the project that I coded along with the Quick Start Guide as I did with the already coded project that I downloaded.  I downloaded the C# program example. 

Any help would be much appreciate.

UPDATE:  Any help on the error below would be appreciated.  I am dead in the water right now as far as evaluating your product

 Line: 437 Error: Sys.InvalidOperationException: ImageError error #4001 in control 'SilverlightMapConnector1': AG_E_NETWORK_ERROR

I am using Visual Studio 2008 sp1 with silverlight 3 and asp.net 3.51.  I can get the client side layers in the tutorial to run fine.  I only get this error when I try doing the server side layers

I get this same error with the C# code I downloaded from this page, the example C# project that came with the evaluation, and the code I create while following along with the exampels on this page.

UPDATE: From looking in the Forum, I see this can be caused it the applicaiton can not find the shape files.  I have been debugging in Visual Studio 2008.  I tried publishing the website but I get the same error (client side shapre layer is fine).  Here is the line of code that sets the path

ShapeFileFeatureLayer

worldLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/Countries02.shp"));

My Website directory contains APP_Data that is immediately off of the root of the site.  APP_Data also contains a cile called Countries02.shp.  I got this file from the Evaluations sample form your company.   Does relative pathing work?  Does it need to be hard coded to the actual windows path?

 



JohnnyUser is Offline
07-19-2010 02:23 AM
Avatar

 

Leon,
I downloaded the c# samples which run fine. Here are the steps I tried:
1.       Download the c# sample from http://download.thinkgeo.com/HelloW...CSharp.zip
2.       Reference all the DLLs for both client side and server side. Please make sure two projects are needed to replace.
3.       Set the “HelloWorld.Web” project as startup project and “Default.aspx” as startup page.
4.       Press “F5” to run the sample, and all works fine.
The “4001” exception is a very common error, which can be caused by various server errors. Please following the steps above and try it again. Can you send your error sample to me if it still runs into error?
Thanks,
Johnny


LeonUser is Offline
07-19-2010 01:38 PM
Avatar
Thank you Johnny,

I now have the project running. I set HelloWorld.Web to the start up project and I "thought" i had set Default.aspx as the startup page but apprently I did not. After double checking AND setting Default.aspx to the start up page, it works! A simple problem, thank you for your patience and reply.

I will be evaluating your software over the next month or so to see if it will meet our needs. I might have some more qeustions, but if I do, I will head over to the support forums.

thanks again for your reply,
Leon


JohnnyUser is Offline
07-20-2010 08:42 PM
Avatar
Leon,

That's very nice. Any questions please let us know during your evaluation.

Thanks,
Johnny


You are not authorized to post a reply.
Active Forums 4.2