Skip to content
This repository was archived by the owner on Aug 25, 2023. It is now read-only.

Fix for issue #9 (simplestyle) - #50

Merged
incanus merged 4 commits into
masterfrom
unknown repository
Feb 27, 2014
Merged

incanus merged 4 commits into
masterfrom
unknown repository

Conversation

@ghost

@ghost ghost commented Feb 26, 2014

Copy link
Copy Markdown

This adds simplestyle support for issue #9 by fetching simplestyle geoJSON, and for maps which have markers, adding the markers to the map using MKPinAnnotationView (i.e. generic pins).

Noteworthy things:

  1. This incorporates the lessons learned from Fix for #22: Only write to cache for an HTTP 200, sweep empty png files. #23 about network error handling (see updateOverlay and updateMarkers)
  2. The example map is from weekend picks (see Add marker geoJSON to the sample map (for #38) #44) which includes markers but no lines or polygons. This pull request wasn't attempting to implement any support for lines and polygons though, so that's fine.
  3. There is some related background info at Fix for issue #5 (markers) & #9 (simplestyle) #21 (prior attempt at a simplestyle implementation)

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

Looks good so far -- couple comments here. #44 should get resolved soon; we have a map up under examples but I'm waiting for some markers to go onto it.

  • Why do all the manual stuff around MBXSimpleStylePointAnnotation.coordinate? Doesn't this come for free with MKAnnotation?
  • We should probably namespace reuseID better and use a const as is common in UITableView setups.
  • 👍 on the concurrency of overlay/markers fetching and the new network error handling. And we should probably keep away from auto-retry of failed markers for now, as you are doing, until Infinite failing TileJSON requests when app launches in airplane mode #24 is better. However, isn't this always going to fail for maps that don't have simplestyle attached to them? It will always fetch, always 404, and that's an extra network call that might not need to happen?
  • If we cache markers, we'll need a way to clear that cache independent of the tile cache clearing that exists now. Otherwise people will have to ship code updates and/or do this manually if they change the markers on their hosted map.

@ghost

ghost commented Feb 26, 2014

Copy link
Copy Markdown
Author

Why do all the manual stuff around MBXSimpleStylePointAnnotation.coordinate? Doesn't this come for free with MKAnnotation?

Well... MKAnnoation is a protocol rather than a class, and it requires a KVO compliant setter for coordinate. For this pull request, I could have used an MKPinAnnotation, but I would have to strip that right back out and replace it with what I've got in order to do the Maki markers for #5. For that, the annotation needs to store a marker image, or the equivalent color and marker strings. The present stuff works for both cases. I could strip it out and add it back in for #5, but I'd rather not.

We should probably namespace reuseID better and use a const as is common in UITableView setups.

Sounds reasonable. Patch? Or maybe a link to an example that you like?

However, isn't this always going to fail for maps that don't have simplestyle attached to them? It will always fetch, always 404, and that's an extra network call that might not need to happen?

Nope. It doesn't work like that. The Core api will give you an empty geoJSON file if the map doesn't have any markers. For example: https://a.tiles.mapbox.com/v3/justin.map-pgygbwdm/markers.geojson

If we cache markers, we'll need a way to clear that cache independent of the tile cache clearing that exists now. Otherwise people will have to ship code updates and/or do this manually if they change the markers on their hosted map.

Here's the existing logic in sweepCache. I'm under the impression that it will treat cached markers in just the same way as it does tiles, subject to kMBXMapViewCacheInterval. On a side note, it looks like sweepCache should really be using _cacheInterval, but that's a separate issue. Looking at this, what do you think should be different?

            while ((filename = [cacheEnumerator nextObject]))
            {
                NSString *filePath = [NSString stringWithFormat:@"%@/%@", [self.mapView cachePath], filename];
                NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];

                if (attributes[NSFileType] == NSFileTypeRegular && [attributes[NSFileModificationDate] timeIntervalSinceDate:[NSDate date]] < -kMBXMapViewCacheInterval)
                    [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
                else
                {
                    // Clean up any empty cache files that might be lying around from previous bugs
                    //
                    if ((attributes[NSFileType] == NSFileTypeRegular) && ([attributes[NSFileSize] integerValue] == 0))
                        [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
                }
            }

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor
  • Got it re: MKAnnotation. You are right.
  • I'll push a patch for the reuse stuff.
  • We're still doing an extra HTTP request though. I like this better than an always-404, though, so I think we can live with it until some future point when it's a real issue.
  • I meant more implementing a distinction or a separate call from -emptyCacheForMapID:, but you are right about the sweeping. Say someone updates markers and wants the freshest ones in the app. They have a sort of shorter lifecycle than map tiles, I would think, so should be able to be cleared separately without affecting longer-lived tiles in cache. I don't think we need to worry about caching delegate stuff, though (not that you brought that up). That could always be added later.

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

BTW feel free to make branches in this repo, then I can push to them. I've just pushed a copy of your issue9 here and added my reuse fix.

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

@ghost

ghost commented Feb 26, 2014

Copy link
Copy Markdown
Author

I'm still a bit scared to mess with this repo too directly. My git/github skills are rapidly improving, but there's a lot I don't know. I did cherry-pick and push your commit though. Better?

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

Sure. Branches don't hurt much, though, and you can always git push origin :mybranch to delete them later.

@ghost

ghost commented Feb 26, 2014

Copy link
Copy Markdown
Author

So is this ready to go, or do we still need to add/change something?

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

I think we still need a marker-specifc cache clear that doesn't affect tiles.

@ghost

ghost commented Feb 26, 2014

Copy link
Copy Markdown
Author

and that would be exposed in the header file?

@ghost

ghost commented Feb 26, 2014

Copy link
Copy Markdown
Author

I'm working on this:

/** Remove any locally-cached Mapbox markers for the given map ID.
 *
 *   This method has no effect on any caching system managed by a cachingDelegate, but will still remove markers that were previously cached by the default caching system.
 *
 *   @param mapID The Mapbox map ID. */
- (void)emptyMarkerCacheForMapID:(NSString *)mapID;

@incanus

incanus commented Feb 26, 2014

Copy link
Copy Markdown
Contributor

👍

@incanus
incanus merged commit deb0076 into mapbox:master Feb 27, 2014
@incanus incanus mentioned this pull request Feb 27, 2014
@ghost
ghost deleted the issue9 branch February 27, 2014 03:23
@incanus

incanus commented Jan 21, 2015

Copy link
Copy Markdown
Contributor

The Core api will give you an empty geoJSON file if the map doesn't have any markers.

We're still doing an extra HTTP request though. I like this better than an always-404, though, so I think we can live with it until some future point when it's a real issue.

Some future point == today.

Styles (from Mapbox Studio) can't have markers, as reflected by their TileJSON, so we need to pay attention to this before attempting to download any marker URLs, since we get a 404 instead of an empty GeoJSON for them and this throws off offline download count logic.

#143

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants