How to use custom images for SM3DARIconMarkerView?

103 views
Skip to first unread message

Kim S

unread,
Feb 9, 2012, 4:50:45 AM2/9/12
to 3d...@googlegroups.com
Hi

I have 3DAR up and running but have difficulties trying to display custom icons for the POIs.

Basically, I want to show a custom image for each SM3DARIconMarkerView on a POI. I have spent hours trying to figure out the right approach but the 3DAR library (v.2.1.3) just crashes no matter what.

What is the correct approach for adding a POI with a SM3DARIconMarkerView using a custom image?

Some of the approaches I have tried (which all fail):

1. Create a POI and try to manipulate the view:
CLLocation *location = [[CLLocation alloc] initWithLatitude:somePoint.y longitude:somePoint.x];
SM3DARPointOfInterest *annotation = [[SM3DARPointOfInterest alloc] initWithLocation:location properties:nil];
annotation.title = poi.title;
annotation.subtitle = poi.subtitle;
a. Get the existing view from the POI:
SM3DARIconMarkerView *iconMarkerView = (SM3DARIconMarkerView *)annotation.view;
iconMarkerView.imageName = poi.iconName;
b. Create a new view and set it on the POI:
SM3DARIconMarkerView *iconMarkerView = [[SM3DARIconMarkerView alloc] initWithPointOfInterest:annotation imageName:poi.iconName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:poi.iconName];
markerView.icon = imageView;
a. Add the point:
[self.sm3dar addPoint:annotation];
b. Add the POI: (What is the difference?)
[self.sm3dar addPointOfInterest:annotation];

2. Add a POI directly:
[self.sm3dar addPointOfInterestWithLatitude:somePoint.y
longitude:somePoint.x 
altitude:0 
  title:poi.title
subtitle:poi.subtitle 
markerViewClass:[SM3DARIconMarkerView class] 
 properties:nil];
The same approcaches for manipulating the view as above all fail.

3. Subclass SM3DARIconMarkerView and try to set the image and/or icon in the initWithPointOfInterest:imageName: method.

In all cases the custom image appears for the POIs but the 3DAR library crashes right after with the following exception:
2012-02-08 17:25:53.445 AppName[2632:707] -[ShowMeViewController updateMap] [Line 190] Adding annotations
2012-02-08 17:25:53.915 AppName[2632:707] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'

The "Adding annotations" message is printed out after adding all the points but before the method exits, so the crash is not in the addPoint/addPointOfInterest methods but something after, probably inside the SM3DARIconMarkerView class.

FYI: I use ARC (automatic reference counting) and I debug on an iPhone 3GS.

Thanks for any help on this. I am out of ideas at this point. It is very unclear how using custom icons is supposed to be implemented.

Kim S

unread,
Feb 9, 2012, 5:20:30 AM2/9/12
to 3d...@googlegroups.com
I added a symbolic breakpoint on objc_exception_throw to try to learn more about the crash.

The crash happens when (auto) focusing on a POI and the SM3DARIconMarkerView tries to retrieve the focusedImageName.

The SM3DARIconMarkerView object (when debugging) has an array "parts" which contains just one object; the string with the icon name I have set. I assume there is supposed to be a second string here with the icon name for the image to display when focused. But there is no method/property/ivar on SM3DARIconMarkerView for specifying this focused image.

This is the stack trace:

#0 0x31eff1c8 in objc_exception_throw ()
#1 0x320e7274 in -[__NSArrayI objectAtIndex:] ()
#2 0x003b5082 in -[SM3DARIconMarkerView focusedImageName] at /Users/pmark/projects/SpotMetrix/3DAR/Library/iOS/Source/Views/SM3DARIconMarkerView.mm:121
#3 0x003b4ebc in -[SM3DARIconMarkerView didReceiveFocus] at /Users/pmark/projects/SpotMetrix/3DAR/Library/iOS/Source/Views/SM3DARIconMarkerView.mm:131
#4 0x003924e2 in -[SM3DARController updateCamera] at /Users/pmark/projects/SpotMetrix/3DAR/Library/iOS/Source/Core/SM3DARController.mm:1805
#5 0x00398456 in -[SM3DARController drawView:] at /Users/pmark/projects/SpotMetrix/3DAR/Library/iOS/Source/Core/SM3DARController.mm:386
#6 0x31b0a422 in CA::Display::DisplayLink::dispatch(unsigned long long, unsigned long long) ()
#7 0x31b0a378 in CA::Display::IOMFBDisplayLink::callback(__IOMobileFramebuffer*, unsigned long long, unsigned long long, unsigned long long, void*) ()
#8 0x3372ff92 in IOMobileFramebufferVsyncNotifyFunc ()
#9 0x379e0890 in IODispatchCalloutFromCFMessage ()
#10 0x32158f42 in __CFMachPortPerform ()
#11 0x32163552 in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ ()
#12 0x321634f4 in __CFRunLoopDoSource1 ()
#13 0x32162342 in __CFRunLoopRun ()
#14 0x320e54dc in CFRunLoopRunSpecific ()
#15 0x320e53a4 in CFRunLoopRunInMode ()
#16 0x321f1fec in GSEventRunModal ()
#17 0x32c75742 in UIApplicationMain ()

Kim S

unread,
Feb 9, 2012, 6:47:43 AM2/9/12
to 3d...@googlegroups.com
Disabling auto focusing on POIs (in 3dar.plist) avoids the crash and allows me to display custom images using this code:
CLLocation *location = [[CLLocation alloc] initWithLatitude:somePoint.y longitude:somePoint.x];
SM3DARPointOfInterest *annotation = [[SM3DARPointOfInterest alloc] initWithLocation:location properties:nil];
annotation.title = poi.title;
annotation.subtitle = poi.subtitle;
ShowMeIconMarkerView *iconMarkerView = [[ShowMeIconMarkerView alloc] initWithPointOfInterest:annotation imageName:poi.iconName];
annotation.view = iconMarkerView;
[self.sm3dar addPoint:annotation];

I have used a subclass of SM3DARIconMarkerView to customize presentation, but this is not necessary for the code to work.

I assume focusedImageName tries to find an image with "_focused" appended to the imageName since there is no way to specify the focus image name.

I would still like to use the focus feature but without having to provide separate focus images for each POI (potentially hundreds). Ideally it should be possible to specify that the icon image should not be changed when focused.

Kim S

unread,
Feb 9, 2012, 7:25:05 AM2/9/12
to 3d...@googlegroups.com
Implementing focusedImageName in my subclass allows me to use auto focus (with the same image name) without crashing:

- (NSString *)focusedImageName {
return self.imageName;
}

At least this seems to be working as long as I can get away with not calling [super focusedImageName].

Matt Holmboe

unread,
Feb 14, 2013, 7:53:08 PM2/14/13
to 3d...@googlegroups.com
Hi Kim,

I'm looking to do the exact same thing with an app I'm working on. I've successfully been able to display the custom image using the 

SM3DARIconMarkerView method, however I'm not sure I'm following how you got the auto focus feature to work. Could you (or somebody else) describe how to implement the auto focus view with custom images?

Thanks,

Matt

Denis Santxez

unread,
Jul 1, 2013, 3:38:15 PM7/1/13
to 3d...@googlegroups.com
I have tried all the above code, but I get no effect. The default icon keeps appearing. I'm using 3DAR in development mode. Do I have to change a setting in the library or something?? 

Thanks,

Denis

P. Mark Anderson

unread,
Jul 2, 2013, 2:55:24 AM7/2/13
to 3d...@googlegroups.com
Hi,

If the app builds, links, installs and runs on your device then you're working with the right version. To release your app, build it with the distribution library.

It looks like Kim S used a subclass of SM3DARIconMarkerView to customize presentation to override the default focused image name which looks for an image named with _focused. That way he has full control of the marker's image. 

- (NSString *)focusedImageName {
    return self.imageName;
}

Great work Kim S. Many of 3DAR's less basic features can be a bit opaque.

Mark
--
You received this message because you are subscribed to the Google Groups "3DAR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to 3dar+uns...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages