2013-03-11 72 views
0

我是新來的Windows Phone 7開發人員。 我最近下載並試用了Arcgis示例地圖,它在更改TiledMapserverlayer的URL後給我這個錯誤。空間參考

Invalid spatial reference. Spatial reference must match map's spatial reference. Clear the map layers collection prior to changing the spatial reference. 

的.xaml

  <esri:GraphicsLayer ID="MyGraphicsLayer"> 
       <esri:GraphicsLayer.Graphics> 
        <esri:Graphic Symbol="{StaticResource RedMarkerSymbol}"> 
         <esriGeometry:MapPoint X="11560518.5450925" Y="153495.271364825"> 


         </esriGeometry:MapPoint> 
        </esri:Graphic> 
       </esri:GraphicsLayer.Graphics> 
      </esri:GraphicsLayer> 

      <esri:ArcGISTiledMapServiceLayer ID="MyLayer" 
       Url="http://www.onemap.sg/ArcGIS/rest/services/basemap/MapServer" /> 
     </esri:Map> 

的.cs

public partial class Map : PhoneApplicationPage 
{ 
    GeoCoordinateWatcher _watcher; 
    Graphic _graphicLocation; 
    private static ESRI.ArcGIS.Client.Projection.WebMercator mercator = 
     new ESRI.ArcGIS.Client.Projection.WebMercator(); 
    bool initialLoad = true; 

    public Map() 
    { 
     InitializeComponent(); 

     _graphicLocation = (MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer).Graphics[0]; 

     _watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High); 
     _watcher.MovementThreshold = 20; 

     _watcher.StatusChanged += watcher_StatusChanged; 
     _watcher.PositionChanged += watcher_PositionChanged; 

     // Start data acquisition 
     _watcher.Start(); 
    } 

    void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) 
    { 
     switch (e.Status) 
     { 
      case GeoPositionStatus.Disabled: 
       // The location service is disabled or unsupported. 
       // Alert the user 
       StatusTextBlock.Text = "Location is unsupported on this device"; 
       break; 
      case GeoPositionStatus.Initializing: 
       // The location service is initializing. 
       // Disable the Start Location button 
       StatusTextBlock.Text = "Initializing location service"; 
       break; 
      case GeoPositionStatus.NoData: 
       // The location service is working, but it cannot get location data 
       // Alert the user and enable the Stop Location button 
       StatusTextBlock.Text = "Data unavailable"; 
       break; 
      case GeoPositionStatus.Ready: 
       // The location service is working and is receiving location data 
       // Show the current position and enable the Stop Location button 
       StatusTextBlock.Text = "Ready - retrieving data"; 
       break; 
     } 
    } 

    void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) 
    { 
     _graphicLocation.Geometry = mercator.FromGeographic(new MapPoint(e.Position.Location.Longitude, e.Position.Location.Latitude)); 

     // Use horizontal accuracy (returned in meters) to zoom to the location 
     if (initialLoad) 
     { 
      Envelope rect = new Envelope(
       (_graphicLocation.Geometry as MapPoint).X - (e.Position.Location.HorizontalAccuracy/2), 
       (_graphicLocation.Geometry as MapPoint).Y - (e.Position.Location.HorizontalAccuracy/2), 
       (_graphicLocation.Geometry as MapPoint).X + (e.Position.Location.HorizontalAccuracy/2), 
       (_graphicLocation.Geometry as MapPoint).Y + (e.Position.Location.HorizontalAccuracy/2)); 

      MyMap.ZoomTo(rect.Expand(20)); 

      initialLoad = false; 
     } 
     else 
     { 
      MyMap.PanTo(_graphicLocation.Geometry); 
     } 
    } 

    private void PhoneApplicationPage_Unloaded(object sender, RoutedEventArgs e) 
    { 
     _watcher.Stop(); 
    }} 

我已經嘗試了許多解決方案,例如在WKID增加,但它不工作。 我一直有這個錯誤很長。有人可以幫助! 謝謝

+0

您添加到地圖的圖形必須與地圖具有相同的空間參考。如果您更改了網址,您是否更改爲具有不同空間參考的地圖?這可能導致了錯誤。一種可能的解決方案是將圖形的座標重新映射到地圖的空間參考。 – progrmr 2013-03-11 17:31:50

回答

1

一般來說,你不應該混合SpatialReferences。調用Map.Pan,使用與Map的SRef不同的SRef將變化的Extent放大到未投影的幾何體將導致引發異常。當GPS位置發生變化時,您正試圖移動導致異常的差異SRef的Map。如果您首先投射GPS點,則不會出現該問題。爲此使用GeometryService。順便說一下,在他們的工具包中查看API的GpsLayer,因爲它可以在上面手動保存大量的代碼。另外設置一個ProjectionService,事情應該適合你。

歡呼:)

+0

謝謝,謝謝,謝謝! – Zen 2013-04-01 09:35:42