titanium-mapbox icon indicating copy to clipboard operation
titanium-mapbox copied to clipboard

images for annotations

Open adampax opened this issue 10 years ago • 21 comments

adampax avatar Apr 05 '14 23:04 adampax

+1

yozef avatar Apr 27 '14 13:04 yozef

@yozef I spent some time last week looking into this, but ran into an issue with image size not getting handled properly when added to the callout. The Mapbox SDK is using a library called SMCallout to create the callouts. Maybe it is having an issue with the Ti Proxy view being passed to it.

adampax avatar Apr 27 '14 15:04 adampax

I may have to start implementing this module in the coming weeks for a released app, I'll try to take a look as well...

yozef avatar Apr 28 '14 00:04 yozef

Hi,

Any luck with images as annotations?

Xaynder avatar Oct 25 '14 13:10 Xaynder

Is there a new status? Maybe beta? :-)

maikkley avatar Mar 09 '15 16:03 maikkley

I made a HUGE workaround by actually removing the whole module and using Mapbox's JS API that I've implemented inside a webview. It allows me to use the whole API (including images for annotations) and still interact with titanium using Ti.App.fireEvent("app:eventName");

It works surprisingly well.

Xaynder avatar Mar 09 '15 23:03 Xaynder

Ok, thanks. This will not work for me, because i have an offline map :-/ So i must implement a solution to set images on an offline map.

maikkley avatar Mar 10 '15 09:03 maikkley

For an annotation image, replace the function above in /Classes/ComPolancomediaMapboxView.m

- (RMMapLayer *)markerLayer:(RMMapView *)mapView userInfo:(NSDictionary *)userInfo
{
    //RMMarker *marker = [[RMMarker alloc] initWithMapBoxMarkerImage:nil tintColor:([TiUtils isIOS7OrGreater] ? mapView.tintColor : nil)];

    NSDictionary *args = [userInfo objectForKey:@"args"];
    RMMarker *marker = [[RMMarker alloc] initWithUIImage:[UIImage imageNamed:[TiUtils stringValue:[args objectForKey:@"imageUrl"]]] anchorPoint:CGPointMake(0.5, 1.0)];

    marker.canShowCallout = YES;

    return marker;
}

Note that you can now make something like this

        mapView.setAnnotation({
            latitude:xx.97080,
            longitude:xx.86068,
            title:'Title',
            subtitle: 'Subtitle',
            imageUrl:'images/test.png'
        });

Attention: You must paste the imageUrl without leading "/" :-) have fun!

maikkley avatar Mar 10 '15 16:03 maikkley

Hey @maikkley, how did you compile for 3.5.0+ (64-bit)?

nitrag avatar Mar 12 '15 23:03 nitrag

@Xaynder Is there any chance you are able to share your work?

type88 avatar Mar 12 '15 23:03 type88

@nitrag

  1. I take the source code from github.
  2. Open the xcode project in xcode
  3. Update each of the target architectures to standard ( $(ARCHS_STANDARD) )
  4. Set the iOS Deployment Target to iOS 6.0 or newer
  5. Save the project
  6. Edit the manifest file in Titanium and add a line "architectures: armv7 arm64 i386 x86_64"
  7. set a new version number, e.g. 0.4.1
  8. compile and have fun :-)

maikkley avatar Mar 13 '15 16:03 maikkley

Updating to 64 bit would make a great PR :)

adampax avatar Mar 13 '15 16:03 adampax

@maikkley

Tried your steps exactly. Didn't work.

Did you let xcode update project to preferred settings? Do you build for active architectures only? Did you have to update mapbox-ios-sdk? Did you change build.py? Can you submit a PR for your working code? ;)


** BUILD FAILED **

The following build commands failed:

CompileC build/MapView.build/Release-iphoneos/MapView.build/Objects-normal/armv7/RMAbstractWebMapSource.o Map/RMAbstractWebMapSource.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler

(1 failure)

xcodebuild failed

nitrag avatar Mar 13 '15 17:03 nitrag

I would see, that i make a pull request on this weekend. :-)

Edit: Maybe tonight :-)

maikkley avatar Mar 13 '15 17:03 maikkley

@maikkley

:'(

eagerly awaiting a PR for 64-bit support!

nitrag avatar Mar 16 '15 13:03 nitrag

Sorry, i have not configurated git in Titanium Studio. I am on the way, but it is the first time, that i use github to fork and make a pull request :-)

maikkley avatar Mar 16 '15 15:03 maikkley

@adampax

See pull https://github.com/adampax/titanium-mapbox/pull/16

I made a PR, please test on your end but I think I've got everything updated and working!

Note that due to parity with the file.resolve(), you now need to add the mbtiles extension.

map: 'control-room.mbtiles',

nitrag avatar Mar 17 '15 18:03 nitrag

@nitrag awesome, will check out the PR, thanks

adampax avatar Mar 17 '15 20:03 adampax

So, i hope that is the right way i create a PR :-) Let me know, if something is not working!

maikkley avatar Mar 18 '15 19:03 maikkley

This is apparently in the most recent build although the images aren't showing for me.

gregpardo avatar Jan 15 '16 15:01 gregpardo

I have modified my module to much, that i can't upload it or make a PR. But, my source code for images in that line: https://github.com/adampax/titanium-mapbox/blob/master/Classes/ComPolancomediaMapboxView.m#L377

looks like:

    NSDictionary *args = [userInfo objectForKey:@"args"];
    NSString *url = [TiUtils stringValue:[args objectForKey:@"imageUrl"]];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent: url];
    CGFloat mySize = (CGFloat)[[TiUtils stringValue:[args objectForKey:@"imageSize"]] floatValue];
    CGSize rect = CGSizeMake(mySize,mySize);

    UIImage *img;

    if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
        img = [self imageWithImage:[UIImage imageWithContentsOfFile:path] scaledToSize:rect];
    } else {
        img = [UIImage imageNamed:url];
    }
    RMMarker *marker = [[RMMarker alloc] initWithUIImage:img anchorPoint:CGPointMake(0.5f, 1.0f)];

and it works for me.

maikkley avatar Jan 15 '16 16:01 maikkley