나는 날씨 앱에 NOAA 레이더 이미지를 추가했습니다. 일부 테스트 후에 이미지가지도에서 올바르게 그리지 못하는 것으로 나타났습니다. 이미지의 모퉁이가 정확한 것 같지만 모퉁이에서 벗어나면 비뚤어집니다. 아래는 관련 코드입니다.MapKit MKOverlay를 통한 래스터 맵 추가 이상한 렌더링 문제
오버레이 :
@implementation FMRadarOverlay
- (id)initWithImage:(UIImage*)radarImage withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate{
self.radarImage = radarImage;
MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
return self;
}
- (CLLocationCoordinate2D)coordinate{
return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect)));
}
- (MKMapRect)boundingMapRect{
return mapRect;
}
@end
렌더러 :
@implementation FMRadarOverlayRenderer
- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
FMRadarOverlay *radarOverlay = (FMRadarOverlay*)self.overlay;
CGImageRef imageReference = radarOverlay.radarImage.CGImage;
MKMapRect theMapRect = [radarOverlay boundingMapRect];
CGRect theRect = [self rectForMapRect:theMapRect];
CGContextScaleCTM(context, 1.0, -1.0);
CGContextTranslateCTM(context, 0.0, -theRect.size.height);
CGContextSetAlpha(context, 0.6);
CGContextDrawImage(context, theRect, imageReference);
}
@end
그리고 레이어를 생성하는 예 :
//using url with map and drawing transparent to check accuracy of rendering
//url for radar data only is http://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif
NSURL *radarUrl = [NSURL URLWithString:@"http://radar.weather.gov/Conus/RadarImg/latest.gif"];
NSData *radarData = [NSData dataWithContentsOfURL:radarUrl];
UIImage *rawImage = [UIImage imageWithData:radarData];
FMRadarOverlay *radarOverlay = [[FMRadarOverlay alloc] initWithImage:rawImage withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)];
동일한 이미지와 좌표를 가지고 그들을 오버레이 경우 Google 어스는 올바르게 렌더링되는 kml 파일을 사용합니다. 마치 지구의 곡률 등을 보완하지 않는 것과 같습니다. 비슷한 효과가있는 다른 지리 참조 연산 된 래스터 레이어를 사용해 보았습니다. 어떤 아이디어?
예 KML : 나쁜 렌더링
<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><name>NWS Radar Images</name><open>1</open><Folder> <name>National Weather Service</name> <ScreenOverlay> <name>National Weather Service</name> <description>National Weather Service Doppler Radar RIDGE Imagery http://radar.weather.gov</description> <visibility>1</visibility> <Icon> <href>http://radar.weather.gov/ridge/graphics/nws_google.gif</href> </Icon> <overlayXY x="0" y="1" xunits="fraction" yunits="fraction" /> <screenXY x="0" y="1" xunits="fraction" yunits="fraction" /> <rotationXY x="0" y="0" xunits="fraction" yunits="fraction" /> <size x="0" y="0" xunits="fraction" yunits="fraction" /> </ScreenOverlay><ScreenOverlay> <name>NOAA</name> <description>National Oceanic and Atomospheric Administration http://www.noaa.gov</description> <visibility>1</visibility> <Icon> <href>http://radar.weather.gov/ridge/graphics/noaa_google.gif</href> </Icon> <overlayXY x=".2" y="1" xunits="fraction" yunits="fraction" /> <screenXY x=".2" y="1" xunits="fraction" yunits="fraction" /> <rotationXY x="0" y="0" xunits="fraction" yunits="fraction" /> <size x="0" y="0" xunits="fraction" yunits="fraction" /> </ScreenOverlay></Folder><Folder><name>LATEST_RADARONLY</name><Folder><name>Mosaic</name><ScreenOverlay><name>Legend</name><visibility>1</visibility><Icon><href></href><refreshMode>onInterval</refreshMode><refreshInterval>120</refreshInterval></Icon><overlayXY x="1.0" y="0.5" xunits="fraction" yunits="fraction"/><screenXY x="1.0" y="0.5" xunits="fraction" yunits="fraction"/><rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/></ScreenOverlay><GroundOverlay><name>Mosaic</name><Icon><href>http://radar.weather.gov/ridge/Conus/RadarImg/latest.gif</href><refreshMode>onInterval</refreshMode><refreshInterval>120</refreshInterval></Icon><visibility>1</visibility><LatLonBox><north>50.406626367301044</north><south>21.652538062803</south><east>-66.517937876818</east><west>-127.620375523875420</west></LatLonBox></GroundOverlay></Folder></Folder></Document></kml>