Files
MapLibreParticleLab/platform/darwin/src/MLNVectorStyleLayer.h

113 lines
5.5 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#import <Foundation/Foundation.h>
#import "MLNForegroundStyleLayer.h"
#import "MLNFoundation.h"
NS_ASSUME_NONNULL_BEGIN
/** 原始 Filter 接口的错误域。 */
FOUNDATION_EXTERN MLN_EXPORT NSErrorDomain const MLNStyleFilterErrorDomain;
/** 原始 Filter 接口的稳定错误代码;不影响既有 predicate 接口。 */
typedef NS_ENUM(NSInteger, MLNStyleFilterErrorCode) {
/** E_FILTER_UNSUPPORTED:输入超限、不支持或无法证明无损重放;未写入。 */
MLNStyleFilterErrorUnsupported = 1,
/** E_FILTER_INVALID_LAYER:rawLayer 已失效或不是支持的 Vector Layer。 */
MLNStyleFilterErrorInvalidLayer = 2,
/** E_FILTER_WRONG_THREAD:必须在主线程调用。 */
MLNStyleFilterErrorWrongThread = 3,
/** E_FILTER_MUTATION_FAILED:写入/后验检查失败,已验证原 Filter 恢复。 */
MLNStyleFilterErrorMutationFailed = 4,
/** E_FILTER_ROLLBACK_FAILED:无法确认恢复;Host 必须废弃当前操作 Context。 */
MLNStyleFilterErrorRollbackFailed = 5,
};
/**
``MLNVectorStyleLayer`` is an abstract superclass for style layers whose content
is defined by an ``MLNShapeSource`` or ``MLNShapeSource`` object.
Create instances of ``MLNCircleStyleLayer``, ``MLNCircleStyleLayer``,
``MLNFillExtrusionStyleLayer``, ``MLNFillExtrusionStyleLayer``, ``MLNFillExtrusionStyleLayer``, and
``MLNSymbolStyleLayer`` in order to use ``MLNSymbolStyleLayer``'s properties and
methods. Do not create instances of ``MLNVectorStyleLayer`` directly, and do not
create your own subclasses of this class.
*/
MLN_EXPORT
@interface MLNVectorStyleLayer : MLNForegroundStyleLayer
// MARK: Refining a Style Layer’s Content
/**
Identifier of the layer within the source identified by the `sourceIdentifier`
property from which the receiver obtains the data to style.
*/
@property (nonatomic, nullable) NSString *sourceLayerIdentifier;
/**
The style layer’s predicate.
Use the style layer’s predicate to include only the features in the source
layer that satisfy a condition that you define. If the style layer initially
comes from the style, its predicate corresponds to the
<a href="https://maplibre.org/maplibre-style-spec/#layer-filter">`filter`</a>
property in the style JSON.
See the “<a href="../predicates-and-expressions.html">Predicates and Expressions</a>”
guide for details about the predicate syntax supported by this class.
### Example
To filter the layer to include only the features whose `index` attribute is 5
or 10 and whose `ele` attribute is at least 1,500, you could create an
`NSCompoundPredicate` along these lines:
```swift
let layer = MLNLineStyleLayer(identifier: "contour", source: terrain)
layer.sourceLayerIdentifier = "contours"
layer.predicate = NSPredicate(format: "(index == 5 || index == 10) && CAST(ele, 'NSNumber') >=
1500.0") mapView.style?.addLayer(layer)
```
*/
@property (nonatomic, nullable) NSPredicate *predicate;
/**
读取当前有效 rawLayer 的 Filter JSON 快照;不经过 NSPredicate 或初始化 Style JSON。
空 Filter 返回 NSNull;失败返回 nil,并通过 error 报告原因。
仅返回经现有 Foundation/Core 转换器往返验证的子集:JSON 最大深度 64(根为 1),
最多 4096 个节点(含对象键),字符串和键的 UTF-8 总量最多 256 KiB。
字符串/键含 U+0000 或非法 UTF-8、非有限数值、负零、绝对值大于 2^53-1 的数值、
非 JSON Core 值以及不可重放的 Filter 均报 MLNStyleFilterErrorUnsupported。
结构比较保留数组顺序、对象键和值、布尔/数值区别;仅精确可表示的数值存储类型可归一。
常用 all/any/!/比较/get/has/in/literal、类型断言和 collator 可以进入验证;
其他操作符、混合 legacy/表达式 Filter 或发生折叠/默认值补全而无法结构往返者可能拒绝。
返回对象与 Layer 状态分离,调用方不得在调用期间并发修改输入或 Style。
必须在主线程调用。本接口不证明 Layer 属于当前 Style:未加入或正常移除后仍存活的
Layer 可以使用。Host 必须另行核验当前 Style 按 ID 查得的对象身份、Token/代次等;
rawLayer 已销毁则失败。该接口不管理 Host Context 或 revision。
*/
- (nullable id)rawStyleFilterJSONObjectWithError:(NSError * _Nullable * _Nullable)error;
/**
只设置当前 rawLayer 的 Filter。输入为 Filter 数组或 NSNull(精确恢复空 Filter);
nil 不作为清空指令。NSDecimalNumber 及不支持的 Foundation 类型也会被拒绝。
在写入前对输入建立独立快照、验证 Core 解析/序列化不丢失结构,并证明新旧 Filter
可以经上述 getter 的同一路径重放。任何准入失败都返回 NO,原 Layer 不变。
输入必须已是 Core 可往返的形式;显式 literal 标量、常量折叠或省略 collator 默认项
等即使语义可能等价,也可被保守拒绝。具体限制与 rawStyleFilterJSONObjectWithError: 一致。
写入后重新检查实际 Filter;若不符或写入抛出异常则尝试恢复原 Filter。
MLNStyleFilterErrorMutationFailed 表示恢复已核实,但宿主仍应重新获取状态;
MLNStyleFilterErrorRollbackFailed 表示状态无法确认,宿主必须废弃当前操作 Context。
成功仅代表本次 Filter 操作,不能替代 Host 的 Style 成员关系/外部修改检测。
不修改 Paint/Layout/Source/层序,也不移除 Layer 或重载 Style。
*/
- (BOOL)setRawStyleFilterJSONObject:(id)json error:(NSError * _Nullable * _Nullable)error;
@end
NS_ASSUME_NONNULL_END