imagemapsoverlaytilesroute-me

route-me image overlay in iPhone


I'm using route-me in my project. Library is quite good. Adding markers, drawing polygone work fine. How about placing single image as overlay in given location (latitude, longitude)? This funcionality is missing I think. Has anyone done placing the image overlay without overloading the tiles source?


Solution

  • I've found the solution...

     CLLocationCoordinate2D lcA =   CLLocationCoordinate2DMake(oSector.f_overlay_lat_min,oSector.f_overlay_long_min);
            CLLocationCoordinate2D lcB = CLLocationCoordinate2DMake(oSector.f_overlay_lat_max,oSector.f_overlay_long_max);
    
            CGPoint cgA = [mvMap latLongToPixel:lcA];
            CGPoint cgB = [mvMap latLongToPixel:lcB];
    
            float fLatMin  = MIN(cgA.x,cgB.x);
            float fLongMin = MIN(cgA.y,cgB.y);
    
            float fWidth  = sqrt((cgA.x - cgB.x)*(cgA.x - cgB.x));
            float fHeight = sqrt((cgA.y - cgB.y)*(cgA.y - cgB.y));
    
            RMMapLayer *mlLayer = [[RMMapLayer alloc] init];
            mlLayer.contents = (id) oSector.im_overlay.CGImage;
            mlLayer.frame    = CGRectMake(fLatMin,fLongMin,fWidth,fHeight); 
    
            [[mvMap.contents overlay] addSublayer:mlLayer];
    

    the mvMap is IBOutlet RMMapView *mvMap somewhere in your h file

    the oSector.im_overlay.CGImage can be

    UIImage *i = [UIImage imageNamed:<something>];
    lmLayer.contents = i.CGImage