// // MapMessageCustomCellData.m // EscortProject // // Created by 仁康信息 on 2023/7/7. // #import "MapMessageCustomCellData.h" #import "MapMessageCustomCell.h" #import @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=9e4aac9a04b8296e9039adce3b472f28"; NSString * mapKey = @"9e4aac9a04b8296e9039adce3b472f28"; 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=154985aa1abb49ce2daa20d032a374eb58",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 { // CGRect rect = [self.text boundingRectWithSize:CGSizeMake(300, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{ NSFontAttributeName : [UIFont systemFontOfSize:15] } context:nil]; // CGSize size = CGSizeMake(ceilf(rect.size.width)+1, ceilf(rect.size.height)); // // 加上气泡边距 // size.height += 60; // size.width += 20; // return size; CGFloat textMaxWidth = 245.f; CGSize size = CGSizeMake(textMaxWidth, 170); return size; } @end