Skip to content

Commit

Permalink
Update Mapbox to rc.8
Browse files Browse the repository at this point in the history
  • Loading branch information
lucka-me committed Sep 16, 2021
1 parent d30d3d1 commit 238ccfb
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,35 @@
"repositoryURL": "https://github.com/mapbox/mapbox-common-ios.git",
"state": {
"branch": null,
"revision": "82eaeed75ac3cb7a8f386009a4fca7f1fb3f8697",
"version": "17.1.0"
"revision": "a69e8ec4684ea2db20c94e85bcb54497554500d0",
"version": "18.0.0"
}
},
{
"package": "MapboxCoreMaps",
"repositoryURL": "https://github.com/mapbox/mapbox-core-maps-ios.git",
"state": {
"branch": null,
"revision": "f619bd71a80be83c8bae6ed28f9c1b218bdde555",
"version": "10.0.0-rc.7.2"
"revision": "d5360ef24a2038150ab68c67ada0893f6d5b5b15",
"version": "10.0.0-rc.8"
}
},
{
"package": "MapboxMobileEvents",
"repositoryURL": "https://github.com/mapbox/mapbox-events-ios.git",
"state": {
"branch": null,
"revision": "8e0c725271dee0a0c957b9b9738aef81b601f12b",
"version": "1.0.2"
"revision": "e4ded10f5b9594374416f9396d5b540f8c491bbe",
"version": "1.0.3"
}
},
{
"package": "MapboxMaps",
"repositoryURL": "https://github.com/mapbox/mapbox-maps-ios",
"state": {
"branch": null,
"revision": "5b8b0246f283e87fb98193e67f7bf8eb0a490e1f",
"version": "10.0.0-rc.7"
"revision": "bedc49744970602ebc10c6de3f8a2b4cc6f084a6",
"version": "10.0.0-rc.8"
}
},
{
Expand Down
52 changes: 30 additions & 22 deletions iOS/Views/FusionMap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ struct FusionMap: UIViewRepresentable {
fileprivate static let padding = UIEdgeInsets(top: 12, left: 12, bottom: 12, right: 12)

private static let token = "pk.eyJ1IjoibHVja2EtbWUiLCJhIjoiY2twZTQ2MDVuMDEzNzJwcDMwM3Vqbjc1ZCJ9.BgUUlHt3Wdk8aVSJr4fsvw"
private static let color = ColorRepresentable(color: .init(hue: 0.56, saturation: 1.00, brightness: 1.00, alpha: 100))
private static let colorLight = ColorRepresentable(color: .init(hue: 0.56, saturation: 0.80, brightness: 1.00, alpha: 100))
private static let color = StyleColor(.init(hue: 0.56, saturation: 1.00, brightness: 1.00, alpha: 100))
private static let colorLight = StyleColor(.init(hue: 0.56, saturation: 0.80, brightness: 1.00, alpha: 100))

@Environment(\.colorScheme) private var colorScheme
@State private var annotationManager: PointAnnotationManager? = nil
Expand Down Expand Up @@ -113,7 +113,6 @@ struct FusionMap: UIViewRepresentable {
}

private func addAnnotations(to view: MapView) {
var source = GeoJSONSource()
let features: [ Turf.Feature ] = nominations.compactMap { nomination in
guard let coordinate = nomination.coordinate else {
return nil
Expand All @@ -122,11 +121,22 @@ struct FusionMap: UIViewRepresentable {
feature.properties = [ "title" : nomination.title ]
return feature
}
source.data = .featureCollection(.init(features: features))
let featureCollection = FeatureCollection(features: features)

let style = view.mapboxMap.style
if style.sourceExists(withId: Self.sourceID) {
try? style.updateGeoJSONSource(withId: Self.sourceID, geoJSON: featureCollection)
return
}

var source = GeoJSONSource()
source.data = .featureCollection(featureCollection)
source.cluster = true
source.generateId = true
source.clusterRadius = 50
source.clusterMaxZoom = 14

try? style.addSource(source, id: Self.sourceID)

var clusteredLayer = CircleLayer(id: Self.clusteredLayerID)
clusteredLayer.source = Self.sourceID
clusteredLayer.filter = Exp(.has) { "point_count" }
Expand Down Expand Up @@ -157,17 +167,7 @@ struct FusionMap: UIViewRepresentable {
unclusteredLayer.circleOpacity = .constant(0.6)
unclusteredLayer.circleStrokeWidth = .constant(2)
unclusteredLayer.circleStrokeColor = .constant(Self.color)

let style = view.mapboxMap.style
if style.layerExists(withId: Self.clusteredLayerID) {
try? style.removeLayer(withId: Self.clusteredLayerID)
try? style.removeLayer(withId: Self.countLayerID)
try? style.removeLayer(withId: Self.unclusteredLayerID)
}
if style.sourceExists(withId: Self.sourceID) {
try? style.removeSource(withId: Self.sourceID)
}
try? style.addSource(source, id: Self.sourceID)

try? style.addLayer(clusteredLayer)
try? style.addLayer(countLayer)
try? style.addLayer(unclusteredLayer, layerPosition: .below(clusteredLayer.id))
Expand All @@ -186,6 +186,7 @@ fileprivate class FusionMapModel {
var view: MapView? = nil

func addGestureRecognizers(to view: MapView) {
print("addGestureRecognizers")
self.view = view
view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapHandler(sender:))))
}
Expand All @@ -201,17 +202,24 @@ fileprivate class FusionMapModel {
private func tryTapClustered(
at point: CGPoint, notFoundHandler: @escaping () -> Void = { }
) {
guard let solidView = view else {
return
}
print(solidView.mapboxMap.style.allSourceIdentifiers)
guard let solidView = view else { return }
solidView.mapboxMap.queryRenderedFeatures(
at: point, options: .init(layerIds: [ FusionMap.clusteredLayerID ], filter: nil)
) { tappedQueryResult in
guard let _ = try? tappedQueryResult.get().first else {
guard let feature = try? tappedQueryResult.get().first?.feature else {
notFoundHandler()
return
}
// Not work (yet)
solidView.mapboxMap.queryFeatureExtension(
for: FusionMap.sourceID,
feature: feature,
extension: "supercluster",
extensionField: "expansion-zoom"
) { extensionResult in
guard let extensions = try? extensionResult.get() else { return }
print(extensions)
}
let zoom = solidView.cameraState.zoom
let ratio = (CGFloat.pi / 2.0 - atan(zoom / 3.0)) * 0.4 + 1.0
let camera = CameraOptions(
Expand Down Expand Up @@ -244,7 +252,7 @@ fileprivate class FusionMapModel {
guard
let features = try? result.get(),
let feature = features.first,
let title = feature.feature.properties["title"] as? String,
let title = feature.feature?.properties?["title"] as? String,
let viewController = UIApplication.shared.keyRootViewController
else {
notFoundHandler()
Expand Down

0 comments on commit 238ccfb

Please sign in to comment.