Skip to content

Commit

Permalink
fix(v11,ios): implement filter and sourceId for v11 layers (#3390)
Browse files Browse the repository at this point in the history
  • Loading branch information
mfazekas authored Feb 23, 2024
1 parent c5d94e6 commit da06a81
Show file tree
Hide file tree
Showing 10 changed files with 414 additions and 9 deletions.
49 changes: 48 additions & 1 deletion ios/RNMBX/RNMBXCircleLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,61 @@ public class RNMBXCircleLayer: RNMBXVectorLayer {
override func layerType() -> Layer.Type {
return LayerType.self
}



// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Circle"})}
func setCommonOptions(_ layer: inout CircleLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be Circle but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout CircleLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style,
Expand Down
48 changes: 47 additions & 1 deletion ios/RNMBX/RNMBXFillExtrusionLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,60 @@ public class RNMBXFillExtrusionLayer: RNMBXVectorLayer {
override func layerType() -> Layer.Type {
return LayerType.self
}


// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"FillExtrusion"})}
func setCommonOptions(_ layer: inout FillExtrusionLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be FillExtrusion but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout FillExtrusionLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style,
Expand Down
48 changes: 47 additions & 1 deletion ios/RNMBX/RNMBXFillLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,60 @@ public class RNMBXFillLayer: RNMBXVectorLayer {
override func layerType() -> Layer.Type {
return LayerType.self
}


// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Fill"})}
func setCommonOptions(_ layer: inout FillLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be Fill but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout FillLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style,
Expand Down
45 changes: 44 additions & 1 deletion ios/RNMBX/RNMBXLineLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,59 @@ public class RNMBXLineLayer: RNMBXVectorLayer {
return LayerType.self
}

// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Line"})}
func setCommonOptions(_ layer: inout LineLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be Line but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout LineLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? LineLayer {
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style {
Expand Down
45 changes: 44 additions & 1 deletion ios/RNMBX/RNMBXModelLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,59 @@ public class RNMBXModelLayer: RNMBXVectorLayer {
return LayerType.self
}

// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Model"})}
func setCommonOptions(_ layer: inout ModelLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be Model but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout ModelLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? ModelLayer {
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style {
Expand Down
50 changes: 48 additions & 2 deletions ios/RNMBX/RNMBXRasterLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,59 @@ public class RNMBXRasterLayer: RNMBXLayer {
return layer
}

// @{codepart-replace-start(LayerPropsCommon.codepart-swift.ejs,{layerType:"Raster"})}
func setCommonOptions(_ layer: inout RasterLayer) -> Bool {
var changed = false

#if RNMBX_11
if let sourceLayerID = sourceLayerID {
layer.sourceLayer = sourceLayerID
changed = true
}

if let sourceID = sourceID {
if !(existingLayer && sourceID == DEFAULT_SOURCE_ID) && hasSource() {
layer.source = sourceID
changed = true
}
}

if let filter = filter, filter.count > 0 {
do {
let data = try JSONSerialization.data(withJSONObject: filter, options: .prettyPrinted)
let decodedExpression = try JSONDecoder().decode(Expression.self, from: data)
layer.filter = decodedExpression
changed = true
} catch {
Logger.log(level: .error, message: "parsing filters failed for layer \(optional: id): \(error.localizedDescription)")
}
}
#endif

return changed
}

override func setOptions(_ layer: inout Layer) {
if var actualLayer = layer as? LayerType {
if self.setCommonOptions(&actualLayer) {
layer = actualLayer
}
} else {
Logger.log(level: .error, message: "Expected layer type to be Raster but was \(type(of: layer))")
}
}

override func apply(style : Style) throws {
try style.updateLayer(withId: id, type: RasterLayer.self) { (layer : inout RasterLayer) in
if let styleLayer = self.styleLayer as? RasterLayer {
try style.updateLayer(withId: id, type: LayerType.self) { (layer : inout RasterLayer) in
if self.styleLayer != nil {
self.setOptions(&self.styleLayer!)
}
if let styleLayer = self.styleLayer as? LayerType {
layer = styleLayer
}
}
}
// @{codepart-replace-end}

override func addStyles() {
if let style : Style = self.style,
Expand Down
Loading

0 comments on commit da06a81

Please sign in to comment.