TencentGeofence.fromMap constructor
TencentGeofence.fromMap( - Map map
)
Implementation
factory TencentGeofence.fromMap(Map map) {
final type = GeofenceTypeCodec.fromWire(map['type'] as String?) ??
GeofenceType.circle;
final coord =
CoordinateTypeCodec.fromWire(map['coordinateType'] as String?) ??
CoordinateType.gcj02;
final transitions = <GeofenceTransition>{};
final rawTrans = map['monitorTransitions'];
if (rawTrans is List) {
for (final t in rawTrans) {
final parsed = GeofenceTransitionCodec.fromWire(t as String?);
if (parsed != null) transitions.add(parsed);
}
}
Duration? durationFromMs(Object? raw) {
if (raw is int) return Duration(milliseconds: raw);
if (raw is num) return Duration(milliseconds: raw.toInt());
return null;
}
Map<String, Object?>? userInfo;
final rawInfo = map['userInfo'];
if (rawInfo is Map) {
userInfo = <String, Object?>{};
rawInfo.forEach((k, v) {
if (k is String) userInfo![k] = v;
});
}
TencentLocationCoordinate? center;
final rawCenter = map['center'];
if (rawCenter is Map) center = TencentLocationCoordinate.fromMap(rawCenter);
List<TencentLocationCoordinate>? polygon;
final rawPoly = map['polygon'];
if (rawPoly is List) {
polygon = <TencentLocationCoordinate>[
for (final v in rawPoly)
if (v is Map) TencentLocationCoordinate.fromMap(v),
];
}
return TencentGeofence._(
id: (map['id'] as String?) ?? '',
type: type,
coordinateType: coord,
monitorTransitions: transitions.isEmpty
? const {GeofenceTransition.enter, GeofenceTransition.exit}
: transitions,
expiration: durationFromMs(map['expirationMs']),
dwellDuration: durationFromMs(map['dwellDurationMs']),
userInfo: userInfo,
center: center,
radius: (map['radius'] as num?)?.toDouble(),
polygon: polygon,
districtKeyword: map['districtKeyword'] as String?,
);
}