Select to view content in your preferred language

Change map extent through button outside of the Silverlight application

1093
4
11-03-2010 10:30 AM
NingningKong
Emerging Contributor
I have a silverlight application with a query function. When I draw a box on the map, the application will open a new html page with a list of the features existing in the specified query box. Now, I want to add a button for each of the features in the html page, so that if the users click on the button, the silverlight map will zoom to the selected feature.
Is it possible?
Thanks!
0 Kudos
4 Replies
PatrickBrooke
Emerging Contributor
Hi Nicole,

Do you have any information/attribute(s) about the features you can send back to your silverlight application from the HTML page?

For example, a parcel number, etc... In my application, users can send a query into the silverlight app through a query like so: http://[applicationlocation]/default.aspx?value='123456789'. I put the function on the default.aspx page and listen for a query, if query does not appear, the app ignores the function a loads.

The string is generated by a client application, in our case, our building permit app. It opens a browser with the app URL plus the query string. Is this what you are looking for?
0 Kudos
Charles__Jamie_Phillips
Occasional Contributor
I would use the javascript bridge that is part of silverlight to do that. I hope this links can help.  Basically, you make a javascript method that sends your object_id to the registered silverlight method that would then find the feature and zoom to it.  If you need more help, I can post some code that I created.

http://blogs.silverlight.net/blogs/msnow/archive/2008/07/08/tip-of-the-day-15-communicating-between-...

http://forums.silverlight.net/forums/t/192171.aspx
0 Kudos
NingningKong
Emerging Contributor
Thank you Charles and Patrick!

I add the codes to allow javascript talks to the silverlight application. But my problem is after the map zooms, the silverlight application refreshes, and the map extent goes back to the full extent. Any idea? Thanks!

Here is the code I use:
MainPage.xaml.cs:
namespace SilverlightApplication
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            HtmlPage.RegisterScriptableObject("Page", this);
            ...
          }
....
[ScriptableMember]
            public void MapZoom(double x1, double y1, double x2, double y2)
            {
                map.ZoomTo(new ESRI.ArcGIS.Client.Geometry.Envelope(x1, y1, x2, y2));
            }
}
}
Javascript:
function zoommap() {
            var MapPlugin = document.getElementById("SLP");
            MapPlugin.Content.Page.MapZoom(3911247.03270758, 5232320.39063176, 3911547.03270758, 5232920.3906317);
        }
0 Kudos
NingningKong
Emerging Contributor
Never mind. It's my fault. I figured it out. Thanks!
0 Kudos