gicoprasico
Posts: 2
Joined: Tue Apr 12, 2011 12:12 pm

MapData.SetScale for netcf

Tue Apr 12, 2011 2:18 pm

Hi.

I am trying do develop an application with multi-map support. I have successfully create a mapLib file, scaled all raster maps properly with GpsTools Studio. I even successfully run the application and put an symbol icon to locate my position and it seams everything is OK. But i have one more requirement to fulfill. I have to display map with appropriate scale (meters/px).

On application start-up I go through all maps and try to rescale them. The result is that now my position (icon symbol) is completely wrongly positioned.


here is my sample code:

Code: Select all

ZoomScale scale = ZoomScale.maximum;
double screenRatio = (double)this.m_map.Height / (double)this.Width;
double angle = 270 - Math.Atan((double)this.m_map.Height / (double)this.m_map.Width) * (180 / Math.PI);

for (int i = 0; i < this.m_map.MapLib.MapDataCount; i++) {
   if (i == 0) {
       scale = ZoomScale.maximum;
   } else if (i == 1) {
        scale = ZoomScale.medium;
   } else if (i == 2) {
        scale = ZoomScale.minimum;
   } else {
      scale = ZoomScale.maximum;
   }

   GpsViewNET.MapData mapData = this.m_map.ActiveMapData(this.m_map.MapLib.GetMapDataByIndex(i + 1).Name);

   GpsViewNET.Point upperLeftPoint = new GpsViewNET.Point(0, 0);
   Position upperLeftPosition = this.m_map.Point2Position(upperLeftPoint);

   double widthDistance = (2.0 / screenRatio) * (double)scale;
   double heightDistance = 2 * (double)scale;
   double totalDistance = Math.Sqrt(Math.Pow(heightDistance, 2) + Math.Pow(widthDistance, 2));

   double lowerRightLongitude;
   double lowerRightLatitude;

   //calculate the position that should be displayed in lower right corner
   GisConversion.CalculateGeoPoint(this.m_map.Position.Longitude, this.m_map.Position.Latitude, totalDistance,
       angle, out lowerRightLongitude, out lowerRightLatitude);

   Position lowerRightPosition = new Position();
   lowerRightPosition.Longitude = lowerRightLongitude;
   lowerRightPosition.Latitude = lowerRightLatitude;

   GpsViewNET.Point lowerRightPoint = new GpsViewNET.Point();
   lowerRightPoint.X = this.m_map.Height;
   lowerRightPoint.Y = this.m_map.Width;

   mapData.SetScale(upperLeftPosition, upperLeftPoint,lowerRightPosition, lowerRightPoint, null, null);
}
and here is the code ZoomScale, just for better understanding:

Code: Select all

 
    public enum ZoomScale : int { 
        minimum = 150,
        medium = 1500,
        maximum = 15000
    }
GisConversion.CalculateGeoPoint is our own function to calculate geo point from known point, distance and bearing. I checked the calculated point on Google Earth and there is no problem with this calculation. All coordinates were also as expected.

gicoprasico
Posts: 2
Joined: Tue Apr 12, 2011 12:12 pm

RE: MapData.SetScale for netcf

Tue Apr 12, 2011 2:25 pm

I found one little bug in my code, but the main problem stays.

Code: Select all

                    lowerRightPoint.X = this.m_map.Width;
                    lowerRightPoint.Y = this.m_map.Height;

Return to “GpsTools”