ThinkGeo.com    |     Documentation    |     Premium Support

WpfMap CurrentExtent initial position



When I initialize the application I set the WpfMap CurrentExtent 

to my world map. But somehow its rejected. I say that because 

as soon as drag the mouse to reposition the screen the coordinates

change to some default values of


45000,-407 upperleft 

5359,-1032 lower right


 


private void MainViewMainWindow_MouseMove(object sender, RoutedEventArgs e)

{

 MouseEventArgs ee = (MouseEventArgs)e;

 System.Windows.Point ScreenPoint = ee.GetPosition(AccuViewWpfMap);

 PointShape worldPoint = ExtentHelper.ToWorldCoordinate(

 AccuViewWpfMap.CurrentExtent,

 new ScreenPointF((float)ScreenPoint.X, (float)ScreenPoint.Y),

    (float)AccuViewWpfMap.Width,

    (float)AccuViewWpfMap.Height);


 StatusDDText.Text = "X: " + worldPoint.X.ToString("0.##")

                     + "; Y:" + worldPoint.Y.ToString("0.##");

 StatusConvasCoordinateText.Text = "X: " + ScreenPoint.X 

                 + "; Y: " + ScreenPoint.Y;



This is all I do in the mouse move and the numbers returned in the

worldPoint reflect the position. I have to click drag and move to 

the position I set up when I started. 

Ideas? 

Bob



 


Bob,
 
Thanks for your post!
 
From the values of extent, I think your data has projection, so you need set MapUnit to meter not DecimalDegree, because DecimalDegree just use for latitude and longitude, so x is from -180 to 180, y is from -90 to 90.
 
I noticed that you wired the MouseMove event of MainViewMainWindow, I prefer that you can use MapMouseMove event of ExtentInteractiveOverlay. Because in that eventArgs, you can easy get correctly world coordinates. You can refer to following code:
 
            wpfMap1.ExtentOverlay.MapMouseMove += new EventHandler<MapMouseMoveInteractiveOverlayEventArgs>(ExtentOverlay_MapMouseMove);
        
void ExtentOverlay_MapMouseMove(object sender, MapMouseMoveInteractiveOverlayEventArgs e)
        {
            PointShape worldPoint = new PointShape(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY);
            Point ScreenPoint = new Point(e.InteractionArguments.ScreenX, e.InteractionArguments.ScreenY);
 
            StatusDDText.Text = "X: " + worldPoint.X.ToString("0.##")
                    + "; Y:" + worldPoint.Y.ToString("0.##");
            StatusConvasCoordinateText.Text = "X: " + ScreenPoint.X
                            + "; Y: " + ScreenPoint.Y;
        }
 
If you still can not fix your problem, can you do me a favor that test the winformaMap, if it has the same problem, please let me know.
 
Thanks
James

Meters -vs- degrees. I will have to look into. I need to map everything to degree’s because we have to overlay shapes and their positions over the actual longitude and latitude. Or I will have to translate everything tween and offset meters to degree’s and vise versa. Do you have a translation built in to do this?

 


Bob,
 
From you further description, I know you use many layers, they are using different projections.
 
You want to make them consistent, so I suggest that you can use Proj4Projection to convert all layers the same projection.
 
The easiest that I have found is to use the EPSG Code integers as the SRID parameters on the Proj4Projection. SRID = Spatial Reference ID. 



For example, the EPSG code for a NAD83 UTM projection is 26914. And our Countries02.shp is 4326, the world map kit layer is 4326 too.


The constructor on the ProjNet takes two SRID parameters (as one of the options). The internal projection, and the external projection. Internal means "what is the native projection of my data". External means "what do I want to convert to". Normal Lon/Lat data is expressed in WGS84 Geodetic datum, and the EPSG Code for it is 4326. So, your constructor is: 



Proj4Projection p = new Proj4Projection(26914, 4326) 



If you want to to "unproject" your projected data to the lon/lat of the WorldMapKit. 



When you get "world" extent coordinates, etc, they have be projected. If you want to convert those projected coordinates back to lon/lat, you just call: 



BaseShape projectedShape = projection.ConvertToExternal(rectangleShape). 




You also can refer to our HowDoI sample UseADifferentProjectionForAFeatureLayer.
 
So the solution is that you need know what projection of your data file, if you don’t know how you can ask your data provider. After that, you get the epsg number, you can convert your data to the same as others. Finally, they can match together, and you can use world map kit layer with your tab files.
 
Thanks
James