-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Changing image
property of MGLAnnotationImage
doesn't update sprite
#4556
Comments
I tested it on objC, it's working for me. |
Replacing an annotation image is bit cumbersome — it’s currently not necessarily as simple as just changing the Here’s an a WIP example of how to replace an annotation image in Swift. The key points:
|
This should work following #3835. Please let us know if setting the |
This is still an issue with ios-v3.3.7 static, so please reopen. My code is below:
|
This is also true if you try to change the pin size for an annotation image that is already "drawn" on the map with the same ReuseId. Even if you remove and re-add the annotation, the size of the pin doesn't change. In order to see the pin with the new size, you have to restart the app... |
#7618 tracks this issue more generally for style images in the runtime styling API. @millenbop, before I re-close this issue as a reverse duplicate of #7618, can you confirm whether the marker-red.png and marker-green.png images you were using had differing dimensions? |
@1ec5 What's the status of this? Trying to update |
I can reproduce this issue in iosapp in eedd909 (post-v3.6.2, pre-v3.6.3) with the following diff: diff --git a/platform/ios/app/MBXViewController.m b/platform/ios/app/MBXViewController.m
index 992b7d587..adc6b7c44 100644
--- a/platform/ios/app/MBXViewController.m
+++ b/platform/ios/app/MBXViewController.m
@@ -1777,8 +1777,14 @@ typedef NS_ENUM(NSInteger, MBXSettingsMiscellaneousRows) {
return;
}
- MGLPointAnnotation *point = (MGLPointAnnotation *)annotation;
- point.coordinate = [self.mapView convertPoint:self.mapView.center toCoordinateFromView:self.mapView];
+// MGLPointAnnotation *point = (MGLPointAnnotation *)annotation;
+// point.coordinate = [self.mapView convertPoint:self.mapView.center toCoordinateFromView:self.mapView];
+
+ NSString *title = [(MGLPointAnnotation *)annotation title];
+ if (!title.length) return;
+ NSString *lastTwoCharacters = [title substringFromIndex:title.length - 2];
+ MGLAnnotationImage *image = [mapView dequeueReusableAnnotationImageWithIdentifier:lastTwoCharacters];
+ image.image = [self imageWithText:lastTwoCharacters backgroundColor:[UIColor orangeColor]];
}
- (void)mapView:(MGLMapView *)mapView didFinishLoadingStyle:(MGLStyle *)style Interestingly, if I uncomment the line that changes the annotation’s coordinate, the image does update – just for that particular annotation – by virtue of the call to Digging in further, it does appear that diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm
index af7122fc1..236e50f39 100644
--- a/platform/ios/src/MGLMapView.mm
+++ b/platform/ios/src/MGLMapView.mm
@@ -4106,11 +4106,6 @@ public:
NSString *fallbackReuseIdentifier = MGLDefaultStyleMarkerSymbolName;
NSString *fallbackIconIdentifier = [MGLAnnotationSpritePrefix stringByAppendingString:fallbackReuseIdentifier];
- // Remove the old icon from the style.
- if ( ! [iconIdentifier isEqualToString:fallbackIconIdentifier]) {
- _mbglMap->removeAnnotationImage(iconIdentifier.UTF8String);
- }
-
if (annotationImage.image)
{
// Add the new icon to the style.
@@ -4126,6 +4121,11 @@ public:
}
else
{
+ // Remove the old icon from the style.
+ if ( ! [iconIdentifier isEqualToString:fallbackIconIdentifier]) {
+ _mbglMap->removeAnnotationImage(iconIdentifier.UTF8String);
+ }
+
// Add the default icon to the style if necessary.
annotationImage.styleIconIdentifier = fallbackIconIdentifier;
if ( ! [self dequeueReusableAnnotationImageWithIdentifier:MGLDefaultStyleMarkerSymbolName]) Since the image replacement feature was originally implemented, a formal style image API was added with the expectation that a sprite image would never be removed while in use. I think removing the call to |
Also running into this issue, using build 3.6.4. The image doesn't refresh automatically..the only workaround I found that works is removing and adding the annotation again.
|
Pretty sure this was because I had merely moved the call to |
my problem is when I select an annotation in the mapbox mapview the state changed to selected and the image of the annotation for this I wrote this delegate method func mapView(_ mapView: MGLMapView, didSelect annotation: MGLAnnotation) {
the addAnnotation method fire this imageForAnnotation method: func mapView(_ mapView: func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? {
It's fire correctly the second case but the pin image doesn't change!!!! I didn't know why?? |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions. |
When I update the
image
property on aMGLAnnotationImage
, for example in thedidSelectAnnotation
function:...I see the below block of code in mapbox-gl framework run, but the annotation image does not update:
I believe it should update the annotation's image on the fly without any type of manual refresh.
The issue is referenced:
#2210
#3146
The text was updated successfully, but these errors were encountered: