ArcGIS API for Silverlight when the DataGrid selects an item, the map focuses on the pop-up window and can play the audio file

Source: Internet
Author: User
Tags silverlight

Original: ArcGIS API for Silverlight when the DataGrid selects an item, the map focuses on the popup window and can play the audio file

Look first, then on the code:


<usercontrol x:class= "Mapclient.picmusic" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d= "http://schemas.microsoft.com/expression/blend/ "Xmlns:mc=" http://schemas.openxmlformats.org/markup-compatibility/2006 "mc:ignorable=" D "d:designheight=" 250 "D:designwidth=" > <grid x:name= "LayoutRoot" background= "white" horizontalalignment= "left" width= "300" height= "verticalalignment=" Top > <border margin= "0" borderbrush= "#FF95C8F7" borderthickness= "1" Cornerra dius= "8" > <Border.Background> <lineargradientbrush endpoint= "0.5,1" startpoint= "0.5, 0 "> <gradientstop color=" white "offset=" 0 "/> <gradientstop color=" #FFBBD 7EF "offset=" 0.194 "/> </LinearGradientBrush> </Border.Background> < Border borderbrush= "#FF95C8F7" Borderthickness= "1" margin= "7,31,7,7" background= "white" > <grid margin= " -5,-26,-11,-8" > < grid.rowdefinitions> <rowdefinition height= "0.096*"/> <rowdefini  tion height= "0.904*"/> </Grid.RowDefinitions> <border margin= "6,4,13,96" grid.row= "1" borderthickness= "0.5" > <border margin= "30,0" > &lt ;                            border.background> <imagebrush stretch= "Fill" imagesource= "Images/bg.png"/>                        </Border.Background> <image x:name= "gcimg" margin= "8,5"/> </Border> </Border> <grid height= "margin=" 0 "G Rid. row= "1" verticalalignment= "Bottom" > <scrollviewer margin= "6,-9,12,9" scrollviewer.horizontals crollbarvisibility="Hidden" scrollviewer.verticalscrollbarvisibility= "Auto" borderthickness= "0.5" > <textbloc K x:name= "Tbskshortmes" textwrapping= "Wrap" text= "Here is more information about reservoirs" fontsize= "14.667" fontfamily= "Microsoft Yahei" height= "width=" 276 "horizontalalignment=" Center "verticalalignment=" center "/> </scrollvi ewer> </Grid> <stackpanel horizontalalignment= "right" width= "Orienta" tion= "Horizontal" margin= "0,-4,13,4" > <image x:name= "Imgstart" horizontalalignment= "left" He ight= "margin=" 3,0,5,-5 "width=" "source=" Images/button_grey_play.png "mouseleftbuttondown=" ImgStart_ MouseLeftButtonDown "mouseleftbuttonup=" Imgstart_mouseleftbuttonup "tooltipservice.tooltip=" Play "Cursor=" Hand "/ > <image x:name= "imgpause" horizontalalignment= "left" height= "" margin= "5,0,5,-5" Width= "22 "Source=" Images/button_grey_pause.png "mouseleftbuttondown="Imgpause_mouseleftbuttondown "mouseleftbuttonup=" Imgpause_mouseleftbuttonup "tooltipservice.tooltip=" Pause "Cursor=" Hand "/> <image x:name=" imgend "horizontalalignment=" left "height=" "margin=" 5,0,0,-5 "Width = "Source=" "Images/button_grey_stop.png" mouseleftbuttondown= "Imgend_mouseleftbuttondown" MouseLeftButtonUp= "                    Imgend_mouseleftbuttonup "tooltipservice.tooltip=" Stop "cursor=" Hand "/> </StackPanel> <textblock x:name= "GCNM" margin= "105,0,129,3" textwrapping= "Wrap" text= "Dongfeng Reservoir" fontweight= "Bold" cursor= "Hand"                    Fontsize= "14.667" fontfamily= "Microsoft Yahei" foreground= "#FF0056FF" d:layoutoverrides= "Width, Height"/> <mediaelement x:name= "Media" horizontalalignment= "right" margin= "0,0,104,3" width= ""/> </g rid> </Border> </Border> </grid></usercontrol>using system;using S Ystem. Collections.generic;using System.Linq;Using system.net;using system.windows;using system.windows.controls;using system.windows.documents;using System.windows.input;using system.windows.media;using system.windows.media.animation;using System.Windows.Shapes; Using system.text;using system.windows.controls.primitives;using system.windows.media.imaging;using mapclient.servicereference1;using system.collections.objectmodel;namespace mapclient{public partial class PicMusic:        UserControl {SK SK;//reservoir HL HL;//river PGZ PGZ;//irrigation DF DF;//embankment sz sz;//Sluice PWK PWK; Discharge Port GSZ GSZ;        Water station string L_name;        String l_id;        String L_type;        Public Picmusic () {InitializeComponent ();        } #region The general method, only need to change show, when instantiating the form, passing in different parameters can be private point _location;        private bool _isshowing;        Private Popup _popup;        Private Grid _grid;        Private Canvas _canvas;        Private FrameworkElement _content; Initialize and display the popup windowThe public method is called when the menu item is displayed (point location, string name, String Id, String type) {This.l_na            me = name;            this.l_id = Id;            This.l_type = type; /***************2013-05-22**************************/this.gcNM.Text = name;            Show Project name if (_isshowing) throw new InvalidOperationException ();            _isshowing = true;            _location = location;            Constructpopup (this); _popup.            IsOpen = true;            Handle the spacing problem of the title string tmp = name;            StringBuilder sb = new StringBuilder (); for (int i = 0; i < tmp. Length; i++) {sb.            Append (Tmp[i] + "");            } getdatasoapclient client = new Getdatasoapclient (); client.getgcmediabyidcompleted + = new Eventhandler<getgcmediabyidcompletedeventargs> (client_            getgcmediabyidcompleted);        Client.getgcmediabyidasync (Id, type); } void CLIent_getgcmediabyidcompleted (object sender, Getgcmediabyidcompletedeventargs e) {try {                observablecollection<tb_gcmedia> lists = E.result; if (lists.                        Count > 0) {foreach (Tb_gcmedia item in lists) { Project name This.gcNM.Text = Item. GCNM.                        Trim ();                        String[] s = {"ClientBin"}; Audio MP3 file String urlm = App.Current.Host.Source.OriginalString.ToString (). Split (S, stringsplitoptions.removeemptyentries) [0] + item. Mp3url. ToString ().                        Trim (new char[] {'. ', '/'});                        This.media.Source = new Uri (URLM, Urikind.relativeorabsolute); Picture file String Urla = App.Current.Host.Source.OriginalString.ToString (). Split (S, stringsplitoptions.removeemptyentries) [0] + item. Picurl. ToString ().   Trim (new char[] {'. ', '/'});                     Uri uri = new Uri (Urla, Urikind.relativeorabsolute);                        BitmapImage image = new BitmapImage (URI);                        This.gcImg.Source = image; Project Brief Description This.tbSKShortMes.Text = Item.                    MEMO; }} else {this.media.Source = new Uri ("Sound.mp3", Urikin d.relative);                    Audio data uri uri = new Uri ("Images/nopic.jpg", urikind.relative);                    BitmapImage image = new BitmapImage (URI); This.gcImg.Source = image; Project Picture This.tbSKShortMes.Text = "No information, please upload!" "; Engineering Brief Description}} catch (Exception) {this.media.Source = new Ur I ("Sound.mp3", urikind.relative);                Audio data uri uri = new Uri ("Images/nopic.jpg", urikind.relative);                BitmapImage image = new BitmapImage (URI); This.Gcimg.source = image; Project Picture This.tbSKShortMes.Text = "No information, please upload!" ";                Project Brief Description}} public void Show (point location) {if (_isshowing)            throw new InvalidOperationException ();            _isshowing = true;            _location = location;            Constructpopup (this); _popup.        IsOpen = true;            }//close popup form public void Close () {_isshowing = false; if (_popup! = null) {_popup.            IsOpen = false;        }}//pop-up box outside click to close the window protected virtual void Onclickoutside () {close (); }//Layout with grid, initialize popup form//Add a canvas inside the grid to monitor the mouse click event outside the menu item private void Constructpopup (Frameworkeleme            NT _element) {if (_popup! = null) return;            _popup = new popup ();            _grid = new Grid (); _popup.            Child = _grid; _canvas = new Canvas(); _canvas.            MouseLeftButtonDown + = (sender, args) = {onclickoutside ();}; _canvas. Mouserightbuttondown + = (sender, args) = {args. Handled = true; Onclickoutside ();            }; _canvas.            Background = new SolidColorBrush (colors.transparent); _grid.            Children.add (_canvas);            _content = _element; _content.            HorizontalAlignment = HorizontalAlignment.Left; _content.            VerticalAlignment = Verticalalignment.top; _content. Margin = new Thickness (_location. X, _location.            Y, 0, 0); _grid.            Children.add (_content);        Updatesize ();            }///<summary>//Update size///</summary> private void Updatesize () { _grid.            Width = Application.Current.Host.Content.ActualWidth; _grid.            Height = Application.Current.Host.Content.ActualHeight; if (_canvas! = null) {_canvas. Width = _grid.                Width; _canvas. Height = _grid.            Height;            }} #endregion #region WebService call method and close form method public void CloseWindow (SK MP) { Mp. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (HL MP) {MP. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (DF MP) {MP. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (PGZ MP) {MP. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (GSZ MP) {MP. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (PWK MP) {MP. LayoutRoot.Children.RemoveAt (MP.        LAYOUTROOT.CHILDREN.COUNT-1); } public void CloseWindow (SZ MP) {MP. LayoutRoot.Children.RemoveAt (MP. LayouTROOT.CHILDREN.COUNT-1);            private void Imgstart_mouseleftbuttondown (object sender, System.Windows.Input.MouseButtonEventArgs e) {            This is where you add an event handler implementation.            E.handled = true;            Uri uri = new Uri ("Images/button_blue_play.png", urikind.relative);            BitmapImage image = new BitmapImage (URI);            This.imgStart.Source = image;            The other becomes gray pattern uri = new Uri ("Images/button_grey_pause.png", urikind.relative);            BitmapImage image2 = new BitmapImage (URI);            This.imgPause.Source = Image2;            URI = new Uri ("Images/button_grey_stop.png", urikind.relative);            BitmapImage image3 = new BitmapImage (URI);        This.imgEnd.Source = Image3;            private void Imgstart_mouseleftbuttonup (object sender, System.Windows.Input.MouseButtonEventArgs e) {            This is where you add an event handler implementation.        This.media.Play (); } private void Imgpause_mouseleftbuttondown (object senDer, System.Windows.Input.MouseButtonEventArgs E) {//Add an event handler implementation here.            E.handled = true;            Uri uri = new Uri ("Images/button_blue_pause.png", urikind.relative);            BitmapImage image = new BitmapImage (URI);            This.imgPause.Source = image;            The other becomes gray pattern uri = new Uri ("Images/button_grey_play.png", urikind.relative);            BitmapImage image2 = new BitmapImage (URI);            This.imgStart.Source = Image2;            URI = new Uri ("Images/button_grey_stop.png", urikind.relative);            BitmapImage image3 = new BitmapImage (URI);        This.imgEnd.Source = Image3;            private void Imgpause_mouseleftbuttonup (object sender, System.Windows.Input.MouseButtonEventArgs e) {            This is where you add an event handler implementation.        This.media.Pause ();            private void Imgend_mouseleftbuttondown (object sender, System.Windows.Input.MouseButtonEventArgs e) {         This is where you add an event handler implementation.   E.handled = true;            Uri uri = new Uri ("Images/button_blue_stop.png", urikind.relative);            BitmapImage image = new BitmapImage (URI);            This.imgEnd.Source = image;            The other becomes gray pattern uri = new Uri ("Images/button_grey_pause.png", urikind.relative);            BitmapImage image2 = new BitmapImage (URI);            This.imgPause.Source = Image2;            URI = new Uri ("Images/button_grey_play.png", urikind.relative);            BitmapImage image3 = new BitmapImage (URI);        This.imgStart.Source = Image3;            private void Imgend_mouseleftbuttonup (object sender, System.Windows.Input.MouseButtonEventArgs e) {            This is where you add an event handler implementation.        This.media.Stop (); } #endregion}}///<summary>//Irrigation List Spotlight//</summary>//<param name= "Sen Der "></param>//<param name=" E "></param> private void dgpgzlist_selectionchanged (Obje CT sender, SelectionChangedEventArgs e) {ESRI. ArcGIS.Client.Projection.WebMercator mercator = new ESRI.            ArcGIS.Client.Projection.WebMercator ();            Highlight and select row-related map elements datagrid DataGrid = sender as DataGrid;            int selectedindex = Datagrid.selectedindex; if (SelectedIndex >-1) {Tb_pgz Findresult = (tb_pgz) Dgpgzlist.selecteditem;//Get the DataGrid selected Row, the DataGrid is the data of the DataGrid's Name property value Graphic g = new Graphic () {Geometry = Me Rcator. Fromgeographic (New MapPoint (double). Parse (FindResult.Latitute.ToString (). Trim ()), double. Parse (FindResult.Longitute.ToString ().                Trim ())), Symbol = layoutroot.resources["Defaultmarkersymbol"] as Symbol}; Save attribute g.attributes["Latitute"] = Findresult.latitute; Latitude g.attributes["Longitute"] = Findresult.longitute; Longitude g.attributes["NM"] = findresult.bznm; //Name g.attributes["ID"] = findresult.id;//serial number ESRI. ArcGIS.Client.Geometry.Envelope selectedfeatureextent = Mercator. Togeographic (G.geometry). Extent;                The position of the selected point double expandpercentage = 1; After adding a value, focus (note here to convert the geographic coordinates and Mercator coordinates) Double Widthexpand = (selectedfeatureextent.width + 5) * (Expandpercentag                E/100);                Double Heightexpand = (selectedfeatureextent.height + 5) * (EXPANDPERCENTAGE/100); ESRI. ArcGIS.Client.Geometry.Envelope displayextent = new Envelope (Wkidconvert.lonlat2mercator (New MapPoint ( Selectedfeatureextent.xmin-(WIDTHEXPAND/2), Selectedfeatureextent.ymin-(HEIGHTEXPAND/2))), Wkidconvert.lonlat2mercator (New MapPoint (Selectedfeatureextent.xmax + (WIDTHEXPAND/2), Selectedfeatureextent.ymax +                (HEIGHTEXPAND/2))))                {spatialreference = new spatialreference (102100)};  try {//focus                  Mymap.zoomto (displayextent);                Showfocus (g);                } catch (Exception) {}//focus, empty the selected record in the DataGrid                Datagrid.selectedindex =-1; Focus is loading into the SL middle display and automatically adding tip information generaltransform GT = this.                Transformtovisual (Application.Current.RootVisual as UIElement);                Double x = browser.clientwidth;                Double y = browser.clientheight; Point offset = GT.                Transform (new Point (X/2, Y/2)); Double controltop = offset.                Y-125; Double controlleft = offset.                X-300;                Point P = new Point (Controlleft, controltop);                Tip_base.g_picmusic = new Picmusic (); Tip_Base.g_PicMusic.Show (P, g.attributes["NM"]. ToString (), g.attributes["ID"].            ToString (), "4"); } else {//No Processing}}






ArcGIS API for Silverlight when the DataGrid selects an item, the map focuses on the pop-up window and can play the audio file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.