80 lines
3.1 KiB
Objective-C
80 lines
3.1 KiB
Objective-C
//
|
|
// MapMessageCustomCellData.m
|
|
// EscortProject
|
|
//
|
|
// Created by 仁康信息 on 2023/7/7.
|
|
//
|
|
|
|
#import "MapMessageCustomCellData.h"
|
|
#import "MapMessageCustomCell.h"
|
|
#import<CommonCrypto/CommonDigest.h>
|
|
|
|
@implementation MapMessageCustomCellData
|
|
|
|
+ (TUIMessageCellData *)getCellData:(V2TIMMessage *)message{
|
|
// NSDictionary *param = [NSJSONSerialization JSONObjectWithData:message.locationElem.desc options:NSJSONReadingAllowFragments error:nil];
|
|
MapMessageCustomCellData *cellData = [[MapMessageCustomCellData alloc] initWithDirection:message.isSelf ? MsgDirectionOutgoing : MsgDirectionIncoming];
|
|
cellData.innerMessage = message;
|
|
cellData.msgID = message.msgID;
|
|
cellData.text = message.locationElem.desc;
|
|
cellData.MapPictureImg = [self mapLocationImage:message.locationElem.longitude Withlation:message.locationElem.latitude];
|
|
cellData.reuseId = @"MapMessageCustomCell";
|
|
cellData.showAvatar = true;
|
|
// cellData.avatarUrl = [NSURL URLWithString:message.faceURL];
|
|
return cellData;
|
|
}
|
|
|
|
|
|
+ (NSString *)mapLocationImage:(CGFloat)longLation Withlation:(CGFloat)lation {
|
|
// 0: self.longLation,self.lation
|
|
NSString * staciUrl = @"https://restapi.amap.com/v3/staticmap?key=e9926badd26aaa766d13439c88a83f2d";
|
|
NSString * mapKey = @"e9926badd26aaa766d13439c88a83f2d";
|
|
NSString * loctaionUrl = @"https://a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png";
|
|
|
|
NSString * needMdString = [NSString stringWithFormat:@"key=%@&location=%f,%f&markers=-1,%@,0:%f,%f&size=700*500&zoom=15124d58f7223ac9738312a8d187a21f2b",mapKey,longLation,lation,loctaionUrl,longLation,lation];
|
|
|
|
|
|
NSString * mapUrl = [NSString stringWithFormat:@"%@&location=%f,%f&markers=-1,%@,0:%f,%f&size=700*500&zoom=15&sig=%@",staciUrl,longLation,lation,loctaionUrl,longLation,lation,[self md5:needMdString]];
|
|
|
|
return mapUrl;
|
|
|
|
|
|
|
|
}
|
|
//md加密
|
|
+ (NSString *)md5:(NSString *)str
|
|
{
|
|
const char *cStr = [str UTF8String];
|
|
unsigned char result[16];
|
|
CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
|
|
return [NSString stringWithFormat:
|
|
@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
|
|
result[0], result[1], result[2], result[3],
|
|
result[4], result[5], result[6], result[7],
|
|
result[8], result[9], result[10], result[11],
|
|
result[12], result[13], result[14], result[15]
|
|
];
|
|
}
|
|
|
|
|
|
|
|
- (CGSize)contentSize
|
|
{
|
|
CGFloat textMaxWidth = 245.f;
|
|
CGFloat textLabelWidth = textMaxWidth - 20; // 左右各 10 边距
|
|
|
|
CGRect rect = [self.text boundingRectWithSize:CGSizeMake(textLabelWidth, MAXFLOAT)
|
|
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
|
attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:14] }
|
|
context:nil];
|
|
CGFloat textHeight = ceil(rect.size.height) + 12; // 上下各 6pt
|
|
CGFloat totalHeight = textHeight + 140; // 文字 + 地图图片
|
|
|
|
return CGSizeMake(textMaxWidth, totalHeight);
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|