You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Changing image property of MGLAnnotationImage doesn't update sprite #4556
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?
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 mbgl::Map::updateAnnotation().
Digging in further, it does appear that -[MGLMapView annotationImageNeedsRedisplay:] and -installAnnotationImage: are working as they always have, by calling mbgl::Map::removeAnnotationImage() followed by addAnnotationImage() with the same image ID. If I remove this line, all the annotations associated with the annotation image update as expected – but only when deselecting the annotation or moving the viewport, which is weird.
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 removeAnnotationImage() is an appropriate fix, but we’ll need to figure out why the update only happens on deselection or camera changes and also test some edge cases like setting image to nil.
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.
we’ll need to figure out why the update only happens on deselection or camera changes
Pretty sure this was because I had merely moved the call to removeAnnotationImage() instead of deleting it outright. #10372 deletes the call to that method, which I think is the better fix.
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
Activity
RomainQuidet commentedon Apr 4, 2016
I tested it on objC, it's working for me.
friedbunny commentedon Apr 4, 2016
Replacing an annotation image is bit cumbersome — it’s currently not necessarily as simple as just changing the
imageproperty.Here’s an a WIP example of how to replace an annotation image in Swift.
The key points:
MGLAnnotationImage.annotationobject that comes with themapView:didSelectAnnotation:delegate method.1ec5 commentedon May 25, 2016
This should work following #3835. Please let us know if setting the
imageproperty isn’t working in the v3.3.0 alphas.millenbop commentedon Nov 23, 2016
This is still an issue with ios-v3.3.7 static, so please reopen.
My code is below:
Channel76 commentedon Jan 14, 2017
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...
1ec5 commentedon Jan 14, 2017
#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?
millenbop commentedon Jan 16, 2017
They have the same dimensions:
nrubin999 commentedon Aug 28, 2017
@1ec5 What's the status of this? Trying to update
imageofMGLAnnotationImagewith no success. Image has same dimensions.1ec5 commentedon Aug 30, 2017
I can reproduce this issue in iosapp in eedd909 (post-v3.6.2, pre-v3.6.3) with the following diff:
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
mbgl::Map::updateAnnotation().Digging in further, it does appear that
-[MGLMapView annotationImageNeedsRedisplay:]and-installAnnotationImage:are working as they always have, by callingmbgl::Map::removeAnnotationImage()followed byaddAnnotationImage()with the same image ID. If I remove this line, all the annotations associated with the annotation image update as expected – but only when deselecting the annotation or moving the viewport, which is weird.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
removeAnnotationImage()is an appropriate fix, but we’ll need to figure out why the update only happens on deselection or camera changes and also test some edge cases like settingimagetonil.ohwhen commentedon Oct 22, 2017
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.
mapView.removeAnnotation(annotation)mapView.addAnnotation(annotation)1ec5 commentedon Nov 14, 2017
Pretty sure this was because I had merely moved the call to
removeAnnotationImage()instead of deleting it outright. #10372 deletes the call to that method, which I think is the better fix.sassiwalid commentedon Nov 28, 2018
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??
stale commentedon Aug 27, 2019
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.
stale commentedon May 22, 2020
This issue has been automatically detected as stale because it has not had recent activity and will be archived. Thank you for your contributions.