void vik_viewport_screen_to_coord ( VikViewport *vvp, int x, int y, VikCoord *coord ) { g_return_if_fail ( vvp != NULL ); if ( vvp->coord_mode == VIK_COORD_UTM ) { int zone_delta; struct UTM *utm = (struct UTM *) coord; coord->mode = VIK_COORD_UTM; utm->zone = vvp->center.utm_zone; utm->letter = vvp->center.utm_letter; utm->easting = ( ( x - ( vvp->width_2) ) * vvp->xmpp ) + vvp->center.east_west; zone_delta = floor( (utm->easting - EASTING_OFFSET ) / vvp->utm_zone_width + 0.5 ); utm->zone += zone_delta; utm->easting -= zone_delta * vvp->utm_zone_width; utm->northing = ( ( ( vvp->height_2) - y ) * vvp->ympp ) + vvp->center.north_south; } else if ( vvp->coord_mode == VIK_COORD_LATLON ) { coord->mode = VIK_COORD_LATLON; if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_LATLON ) { coord->east_west = vvp->center.east_west + (180.0 * vvp->xmpp / 65536 / 256 * (x - vvp->width_2)); coord->north_south = vvp->center.north_south + (180.0 * vvp->ympp / 65536 / 256 * (vvp->height_2 - y)); } else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_EXPEDIA ) calcxy_rev(&(coord->east_west), &(coord->north_south), x, y, vvp->center.east_west, vvp->center.north_south, vvp->xmpp * ALTI_TO_MPP, vvp->ympp * ALTI_TO_MPP, vvp->width_2, vvp->height_2); else if ( vvp->drawmode == VIK_VIEWPORT_DRAWMODE_MERCATOR ) { /* This isn't called with a high frequently so less need to optimize */ coord->east_west = vvp->center.east_west + (180.0 * vvp->xmpp / 65536 / 256 * (x - vvp->width_2)); coord->north_south = DEMERCLAT ( MERCLAT(vvp->center.north_south) + (180.0 * vvp->ympp / 65536 / 256 * (vvp->height_2 - y)) ); } } }
static void _mapcoord_to_center_coord ( VikMapSource *self, MapCoord *src, VikCoord *dest ) { gdouble socalled_mpp; if (src->scale >= 0) socalled_mpp = VIK_GZ(src->scale); else socalled_mpp = 1.0/VIK_GZ(-src->scale); dest->mode = VIK_COORD_LATLON; dest->east_west = ((src->x+0.5) / VIK_GZ(17) * socalled_mpp * 360) - 180; dest->north_south = DEMERCLAT(180 - ((src->y+0.5) / VIK_GZ(17) * socalled_mpp * 360)); }