From 76f5c80d8fe4fc3468a8655b42ce94ab292ab01a Mon Sep 17 00:00:00 2001 From: Zizasaurus Date: Wed, 4 Jan 2023 10:35:43 -0500 Subject: [PATCH] updating annotation initialization to include isDraggable/ isSelected --- .../templates/Annotation.swift.ejs | 28 ++++--- .../templates/AnnotationLocal.swift.ejs | 10 +-- .../templates/AnnotationManager.swift.ejs | 2 +- .../AnnotationManagerTests.swift.ejs | 83 ++++++++++++++----- mapbox-maps-ios | 2 +- mobile-metrics | 2 +- 6 files changed, 89 insertions(+), 38 deletions(-) diff --git a/codegen/annotation-generator/templates/Annotation.swift.ejs b/codegen/annotation-generator/templates/Annotation.swift.ejs index 5125251629d7..a5c1cd0a9cbe 100644 --- a/codegen/annotation-generator/templates/Annotation.swift.ejs +++ b/codegen/annotation-generator/templates/Annotation.swift.ejs @@ -69,54 +69,62 @@ public struct <%- camelize(type) %>Annotation: Annotation { <%_ if (type === symbol) { _%> /// Create a point annotation with a `Point` and an optional identifier. - public init(id: String = UUID().uuidString, point: Point) { + public init(id: String = UUID().uuidString, point: Point, isSelected: Bool = false, isDraggable: Bool = false) { self.id = id self.point = point + self.isSelected = isSelected + self.isDraggable = isDraggable } /// Create a point annotation with a coordinate and an optional identifier /// - Parameters: /// - id: Optional identifier for this annotation /// - coordinate: Coordinate where this annotation should be rendered - public init(id: String = UUID().uuidString, coordinate: CLLocationCoordinate2D) { + public init(id: String = UUID().uuidString, coordinate: CLLocationCoordinate2D, isSelected: Bool = false, isDraggable: Bool = false) { let point = Point(coordinate) - self.init(id: id, point: point) + self.init(id: id, point: point, isSelected: isSelected, isDraggable: isDraggable) } <%_ } else if(type === circle) { _%> /// Create a circle annotation with a `Point` and an optional identifier. - public init(id: String = UUID().uuidString, point: Point) { + public init(id: String = UUID().uuidString, point: Point, isSelected: Bool = false, isDraggable: Bool = false) { self.id = id self.point = point + self.isSelected = isSelected + self.isDraggable = isDraggable } /// Create a circle annotation with a center coordinate and an optional identifier /// - Parameters: /// - id: Optional identifier for this annotation /// - coordinate: Coordinate where this circle annotation should be centered - public init(id: String = UUID().uuidString, centerCoordinate: CLLocationCoordinate2D) { + public init(id: String = UUID().uuidString, centerCoordinate: CLLocationCoordinate2D, isSelected: Bool = false, isDraggable: Bool = false) { let point = Point(centerCoordinate) - self.init(id: id, point: point) + self.init(id: id, point: point, isSelected: isSelected, isDraggable: isDraggable) } <%_ } else if(type === fill) { _%> /// Create a polygon annotation with a `Polygon` and an optional identifier. - public init(id: String = UUID().uuidString, polygon: Polygon) { + public init(id: String = UUID().uuidString, polygon: Polygon, isSelected: Bool = false, isDraggable: Bool = false) { self.id = id self.polygon = polygon + self.isSelected = isSelected + self.isDraggable = isDraggable } <%_ } else if(type === line) { _%> /// Create a polyline annotation with a `LineString` and an optional identifier. - public init(id: String = UUID().uuidString, lineString: LineString) { + public init(id: String = UUID().uuidString, lineString: LineString, isSelected: Bool = false, isDraggable: Bool = false) { self.id = id self.lineString = lineString + self.isSelected = isSelected + self.isDraggable = isDraggable } /// Create a polyline annotation with an array of coordinates and an optional identifier. - public init(id: String = UUID().uuidString, lineCoordinates: [CLLocationCoordinate2D]) { + public init(id: String = UUID().uuidString, lineCoordinates: [CLLocationCoordinate2D], isSelected: Bool = false, isDraggable: Bool = false) { let lineString = LineString(lineCoordinates) - self.init(id: id, lineString: lineString) + self.init(id: id, lineString: lineString, isSelected: isSelected, isDraggable: isDraggable) } <%_ } _%> diff --git a/codegen/annotation-generator/templates/AnnotationLocal.swift.ejs b/codegen/annotation-generator/templates/AnnotationLocal.swift.ejs index d06610d7c1cf..b14a7a0555dd 100644 --- a/codegen/annotation-generator/templates/AnnotationLocal.swift.ejs +++ b/codegen/annotation-generator/templates/AnnotationLocal.swift.ejs @@ -2,12 +2,12 @@ switch (locals.annotationType) { case 'point': _%> -<%- locals.declarationKeyword %> annotation = PointAnnotation(point: .init(.init(latitude: 0, longitude: 0))) +<%- locals.declarationKeyword %> annotation = PointAnnotation(point: .init(.init(latitude: 0, longitude: 0)), isSelected: false, isDraggable: false) <%_ break; case 'circle': _%> -<%- locals.declarationKeyword %> annotation = CircleAnnotation(point: .init(.init(latitude: 0, longitude: 0))) +<%- locals.declarationKeyword %> annotation = CircleAnnotation(point: .init(.init(latitude: 0, longitude: 0)), isSelected: false, isDraggable: false) <%_ break; case 'polygon': @@ -19,13 +19,13 @@ let polygonCoords = [ CLLocationCoordinate2DMake(26.244156283890756, -89.857177734375), CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375) ] -<%- locals.declarationKeyword %> annotation = PolygonAnnotation(polygon: .init(outerRing: .init(coordinates: polygonCoords))) +<%- locals.declarationKeyword %> annotation = PolygonAnnotation(polygon: .init(outerRing: .init(coordinates: polygonCoords)), isSelected: false, isDraggable: false) <%_ break; case 'polyline': _%> let lineCoordinates = [ CLLocationCoordinate2DMake(0, 0), CLLocationCoordinate2DMake(10, 10) ] -<%- locals.declarationKeyword %> annotation = PolylineAnnotation(lineString: .init(lineCoordinates)) +<%- locals.declarationKeyword %> annotation = PolylineAnnotation(lineString: .init(lineCoordinates), isSelected: false, isDraggable: false) <%_ } -_%> \ No newline at end of file +_%> diff --git a/codegen/annotation-generator/templates/AnnotationManager.swift.ejs b/codegen/annotation-generator/templates/AnnotationManager.swift.ejs index 0037edd0cac5..7239736187c5 100644 --- a/codegen/annotation-generator/templates/AnnotationManager.swift.ejs +++ b/codegen/annotation-generator/templates/AnnotationManager.swift.ejs @@ -417,7 +417,7 @@ public class <%- camelize(type) %>AnnotationManager: AnnotationManagerInternal { } internal func handleDragBegin(with featureIdentifiers: [String]) { - guard let annotation = annotations.first(where: { featureIdentifiers.contains($0.id) }) else { return } + guard let annotation = annotations.first(where: { featureIdentifiers.contains($0.id) && $0.isDraggable }) else { return } createDragSourceAndLayer() annotationBeingDragged = annotation diff --git a/codegen/annotation-generator/templates/AnnotationManagerTests.swift.ejs b/codegen/annotation-generator/templates/AnnotationManagerTests.swift.ejs index 465ff421c254..1a701db3fdbb 100644 --- a/codegen/annotation-generator/templates/AnnotationManagerTests.swift.ejs +++ b/codegen/annotation-generator/templates/AnnotationManagerTests.swift.ejs @@ -410,7 +410,6 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI XCTAssertTrue(annotations.compactMap(\.image?.name).allSatisfy(manager.isUsingStyleImage(_:))) } - func testUnusedImagesRemovedFromStyle() { // given let allAnnotations = Array.random(withLength: 10) { @@ -503,7 +502,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI let clusterOptions = ClusterOptions() var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } @@ -553,7 +552,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI clusterProperties: testClusterProperties) var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } @@ -595,7 +594,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI circleColor: testCircleColor) var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } @@ -644,7 +643,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI textField: testTextField) var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } @@ -685,7 +684,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI let clusterOptions = ClusterOptions() var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } @@ -728,12 +727,12 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI let clusterOptions = ClusterOptions() var annotations = [PointAnnotation]() for _ in 0...500 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) annotations.append(annotation) } var newAnnotations = [PointAnnotation]() for _ in 0...100 { - let annotation = PointAnnotation(coordinate: .random()) + let annotation = PointAnnotation(coordinate: .random(), isSelected: false, isDraggable: false) newAnnotations.append(annotation) } @@ -808,6 +807,50 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI XCTAssertEqual(removeLayerInvocations[2].parameters, id) } <%_ } _%> + + func testHandleDragBeginIsDraggableFalse() throws { + <%_ if ( type === symbol) { _%> + manager.annotations = [ + PointAnnotation(id: "point1", coordinate: .random(), isSelected: false, isDraggable: false) + ] + <%_ } else if ( type === circle ) { _%> + manager.annotations = [ + CircleAnnotation(id: "circle1", centerCoordinate: .random(), isSelected: false, isDraggable: false) + ] + <%_ } else if ( type === line ) { _%> + manager.annotations = [ + PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)], isSelected: false, isDraggable: false) + ] + <%_ } else if ( type === fill ) { _%> + manager.annotations = [ + PolygonAnnotation(id: "polygon1", polygon: .init([[ + CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375), + CLLocationCoordinate2DMake(24.51713945052515, -87.967529296875), + CLLocationCoordinate2DMake(26.244156283890756, -87.967529296875), + CLLocationCoordinate2DMake(26.244156283890756, -89.857177734375), + CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375) + ]]), isSelected: false, isDraggable: false) + ] + <%_ } _%> + + style.addSourceStub.reset() + style.addPersistentLayerWithPropertiesStub.reset() + + <%_ if ( type === circle ) { _%> + manager.handleDragBegin(with: ["circle1"]) + <%_ } else if ( type === symbol ) { _%> + manager.handleDragBegin(with: ["point1"]) + <%_ } else if ( type === line ) { _%> + manager.handleDragBegin(with: ["line1"]) + <%_ } else if ( type === fill ) { _%> + manager.handleDragBegin(with: ["polygon1"]) + <%_ } _%> + + XCTAssertEqual(style.addSourceStub.invocations.count, 0) + XCTAssertEqual(style.addPersistentLayerWithPropertiesStub.invocations.count, 0) + XCTAssertEqual(style.updateGeoJSONSourceStub.invocations.count, 0) + } + func testHandleDragBeginNoFeatureId() { style.addSourceStub.reset() style.addPersistentLayerWithPropertiesStub.reset() @@ -833,15 +876,15 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI func testHandleDragBegin() throws { <%_ if ( type === symbol) { _%> manager.annotations = [ - PointAnnotation(id: "point1", coordinate: .random()) + PointAnnotation(id: "point1", coordinate: .random(), isSelected: false, isDraggable: true) ] <%_ } else if ( type === circle ) { _%> manager.annotations = [ - CircleAnnotation(id: "circle1", centerCoordinate: .random()) + CircleAnnotation(id: "circle1", centerCoordinate: .random(), isSelected: false, isDraggable: true) ] <%_ } else if ( type === line ) { _%> manager.annotations = [ - PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)]) + PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)], isSelected: false, isDraggable: true) ] <%_ } else if ( type === fill ) { _%> manager.annotations = [ @@ -851,7 +894,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI CLLocationCoordinate2DMake(26.244156283890756, -87.967529296875), CLLocationCoordinate2DMake(26.244156283890756, -89.857177734375), CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375) - ]])) + ]]), isSelected: false, isDraggable: true) ] <%_ } _%> @@ -894,15 +937,15 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI <%_ if ( type === symbol) { _%> manager.annotations = [ - PointAnnotation(id: "point1", coordinate: .init(latitude: 0, longitude: 0)) + PointAnnotation(id: "point1", coordinate: .init(latitude: 0, longitude: 0), isSelected: false, isDraggable: true) ] <%_ } else if ( type === circle ) { _%> manager.annotations = [ - CircleAnnotation(id: "circle1", centerCoordinate: .init(latitude: 0, longitude: 0)) + CircleAnnotation(id: "circle1", centerCoordinate: .init(latitude: 0, longitude: 0), isSelected: false, isDraggable: true) ] <%_ } else if ( type === line ) { _%> manager.annotations = [ - PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)]) + PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)], isSelected: false, isDraggable: true) ] <%_ } else if ( type === fill ) { _%> manager.annotations = [ @@ -912,7 +955,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI CLLocationCoordinate2DMake(26.244156283890756, -87.967529296875), CLLocationCoordinate2DMake(26.244156283890756, -89.857177734375), CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375) - ]])) + ]]), isSelected: false, isDraggable: true) ] <%_ } _%> @@ -942,15 +985,15 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI func testHandleDragEnded() throws { <%_ if ( type === symbol) { _%> manager.annotations = [ - PointAnnotation(id: "point1", coordinate: .init(latitude: 0, longitude: 0)) + PointAnnotation(id: "point1", coordinate: .init(latitude: 0, longitude: 0), isSelected: false, isDraggable: true) ] <%_ } else if ( type === circle ) { _%> manager.annotations = [ - CircleAnnotation(id: "circle1", centerCoordinate: .init(latitude: 0, longitude: 0)) + CircleAnnotation(id: "circle1", centerCoordinate: .init(latitude: 0, longitude: 0), isSelected: false, isDraggable: true) ] <%_ } else if ( type === line ) { _%> manager.annotations = [ - PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)]) + PolylineAnnotation(id: "line1", lineCoordinates: [ CLLocationCoordinate2D(latitude: 0, longitude: 0), CLLocationCoordinate2D(latitude: 10, longitude: 10)], isSelected: false, isDraggable: true) ] <%_ } else if ( type === fill ) { _%> manager.annotations = [ @@ -960,7 +1003,7 @@ final class <%- camelize(type) %>AnnotationManagerTests: XCTestCase, AnnotationI CLLocationCoordinate2DMake(26.244156283890756, -87.967529296875), CLLocationCoordinate2DMake(26.244156283890756, -89.857177734375), CLLocationCoordinate2DMake(24.51713945052515, -89.857177734375) - ]])) + ]]), isSelected: false, isDraggable: true) ] <%_ } _%> diff --git a/mapbox-maps-ios b/mapbox-maps-ios index 8fb8a671d59a..f430d22c07b2 160000 --- a/mapbox-maps-ios +++ b/mapbox-maps-ios @@ -1 +1 @@ -Subproject commit 8fb8a671d59a8807fe4e82be1fb2b75ec7e62139 +Subproject commit f430d22c07b2aae400f335fac393fcd8296454a7 diff --git a/mobile-metrics b/mobile-metrics index 0faf1105377e..a871e688ea65 160000 --- a/mobile-metrics +++ b/mobile-metrics @@ -1 +1 @@ -Subproject commit 0faf1105377eee335529d70865accf974d29c52c +Subproject commit a871e688ea65338f00e064531cc9f602c85ce463