naisunev

Need help with: Strange side-effects from re-projecting 4326 -> 102100

Discussion created by naisunev on Feb 21, 2012
Latest reply on Mar 2, 2012 by JNery-esristaff
Hi Everyone,

I'm running into something very basic using the WPF esri sample application.

Inside ElementLayer I'm inserting the following code: (works!)

private void RedlandsButton_Click(object sender, RoutedEventArgs e)
  {
   MessageBox.Show("You found Redlands");
            var wi = new ESRI.ArcGIS.Client.ElementLayer() { ID = "NO2" };
            var i = new Image
            {
                Source = new BitmapImage(new Uri("http://cool2.mooo.com/urbanfloodwebsite/images/NO2.png")),
                IsHitTestVisible = false,
                Stretch = Stretch.Fill
            };
            // Taken from the original KML file <LatLonBox id="khLatLonBox218"><north>90</north><south>-90</south><east>180</east><west>-180</west></LatLonBox>

            var mpa = new MapPoint(-180, -89.99) ;
            var mpb = new MapPoint(180, 89.99);
            var envelope = new Envelope(mpa, mpb);
            ESRI.ArcGIS.Client.ElementLayer.SetEnvelope(i, envelope);
            wi.Children.Add(i);
            wi.Initialize();
            MyMap.Layers.Add(wi);
  }


Inside the BingMaps Example I'm inserting the following code: (doesn't work!)

  private void LoadMapButton_Click(object sender,RoutedEventArgs e)
  {
   WebClient webClient = new WebClient();
   string uri = string.Format("http://dev.virtualearth.net/REST/v1/Imagery/Metadata/Aerial?supressStatus=true&key={0}",BingKeyTextBox.Text);

            webClient.OpenReadCompleted += (s, a) =>
            {
                if (a.Error == null)
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(BingAuthentication));
                    BingAuthentication bingAuthentication = serializer.ReadObject(a.Result) as BingAuthentication;
                    a.Result.Close();
                    string authenticationResult = bingAuthentication.AuthenticationResultCode.ToString();

                    if (authenticationResult == "ValidCredentials")
                    {
                        ESRI.ArcGIS.Client.Bing.TileLayer tileLayer = new TileLayer()
                        {
                            ID = "BingLayer",
                            LayerStyle = TileLayer.LayerType.Road,
                            ServerType = ServerType.Production,
                            Token = BingKeyTextBox.Text
                        };

                        MyMap.Layers.Add(tileLayer);

                        BingKeyGrid.Visibility = System.Windows.Visibility.Collapsed;
                        LayerStyleGrid.Visibility = System.Windows.Visibility.Visible;

                        InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Collapsed;

                        var wi = new ESRI.ArcGIS.Client.ElementLayer() { ID = "NO2" };
                        var i = new Image
                        {
                            Source = new BitmapImage(new Uri("http://cool2.mooo.com/urbanfloodwebsite/images/NO2.png")),
                            IsHitTestVisible = false,
                            Stretch = Stretch.Fill
                        };
                        //<LatLonBox id="khLatLonBox218"><north>90</north><south>-90</south><east>180</east><west>-180</west></LatLonBox>

                        //102100
                        var w = new WebMercator();
                        var mpa = w.FromGeographic(new MapPoint(-180, -89.999)) as MapPoint;
                        var mpb = w.FromGeographic(new MapPoint(180, 89.999)) as MapPoint;
                        var envelope = new Envelope(mpa, mpb);
                        ESRI.ArcGIS.Client.ElementLayer.SetEnvelope(i, envelope);
                        wi.Children.Add(i);
                        wi.Initialize();
                        MyMap.Layers.Add(wi);
                    }
                    else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
                }
                else InvalidBingKeyTextBlock.Visibility = System.Windows.Visibility.Visible;
            };
   webClient.OpenReadAsync(new System.Uri(uri));
  }



Somehow though.. the image overlay works perfectly in the ElementLayer sample, but has a strange dimension in the BingMaps layer, even though I'm correctly converting the envelope.

Help would be appreciated!

Outcomes