area.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. #include <memory>
  2. #include <write-copy.h>
  3. #include "db_api/CDBSingletonDefine.h"
  4. #include "log.h"
  5. #include <area.h>
  6. #include "point.h"
  7. #include "monkey_car/monkeycar_area.h"
  8. #include "landmark.h"
  9. #include "area_business.h"
  10. #include <boost/algorithm/string/split.hpp>
  11. #include <boost/algorithm/string/classification.hpp>
  12. #include"module_service/module_area.h"
  13. template<> std::shared_ptr<area_list>
  14. single_base<area_list, int, std::shared_ptr<area>>::m_instance=std::make_shared<area_list>();
  15. struct underground_area:area
  16. {
  17. underground_area(int limit_count_person, int limit_time_person,double scale,int32_t mapid)
  18. :area(-1,limit_count_person,limit_time_person,scale,mapid,(1<<1)|(1<<2)|(1<<3)|(1<<4))
  19. {
  20. m_area_business_list=area_business::get_instance_list(m_area_type);
  21. }
  22. void db_load_card_count()
  23. {
  24. }
  25. virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
  26. {
  27. //根据s的地面、地下属性判断
  28. return false;
  29. }
  30. };
  31. struct ground_area:area
  32. {
  33. virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
  34. {
  35. //根据s的地面、地下属性判断
  36. return false;
  37. }
  38. };
  39. struct special_area:area
  40. {
  41. virtual bool in_area(const std::shared_ptr<site>&s, const point & p)
  42. {
  43. return false;
  44. }
  45. };
  46. void area::on_hover(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
  47. {
  48. for(auto i:m_area_business_list)
  49. {
  50. i->on_hover(a,c,a->get_business_data(i->business_type()));
  51. }
  52. }
  53. void area::on_enter(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
  54. {
  55. log_info("on_enter..%d areaId:%d",c->m_id,m_id);
  56. for(auto i:m_area_business_list)
  57. {
  58. i->on_enter(a,c,a->get_business_data(i->business_type()));
  59. }
  60. }
  61. void area::on_leave(std::shared_ptr<area_hover>&a,std::shared_ptr<card_location_base>&c)
  62. {
  63. log_info("on_leave..%d areaId:%d",c->m_id,m_id);
  64. for(auto i:m_area_business_list)
  65. {
  66. i->on_leave(a,c,a->get_business_data(i->business_type()));
  67. }
  68. }
  69. bool area::in_area(const std::shared_ptr<site>&s, const point & p)
  70. {
  71. if(m_bound.empty())
  72. return false;
  73. int counter = 0;
  74. double xinters;
  75. point p1,p2;
  76. p1 = m_bound[0];
  77. int size = m_bound.size();
  78. for (int i=1;i<= size;i++) {
  79. p2 = m_bound[i%size];
  80. if (p.y > std::min(p1.y,p2.y)) {
  81. if (p.y <= std::max(p1.y,p2.y)) {
  82. if (p.x <= std::max(p1.x,p2.x)) {
  83. if (p1.y != p2.y) {
  84. xinters = (p.y-p1.y)*(p2.x-p1.x)/(p2.y-p1.y)+p1.x;
  85. if (p1.x == p2.x || p.x <= xinters)
  86. counter++;
  87. }
  88. }
  89. }
  90. }
  91. p1 = p2;
  92. }
  93. return (counter % 2 == 0) ? false : true;
  94. }
  95. area_list::area_list()
  96. {
  97. }
  98. #if 0
  99. void area_list::init_monkeycar_area()
  100. {
  101. std::unordered_map<int,std::shared_ptr<area>> map;
  102. const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path, c.scale,\
  103. over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance ,b.monkeycar_coordinate,b.monkeycar_speed \
  104. FROM dat_area a ,dat_monkeycar_base_info b ,dat_map c\
  105. where a.area_id = b.monkeycar_base_info_id and a.map_id = c.map_id;";
  106. std::string Error;
  107. YADB::CDBResultSet DBRes;
  108. sDBConnPool.Query(sql,DBRes,Error);
  109. if(!Error.empty())
  110. log_error("monkeycar area init Error,%s",Error.c_str());
  111. int nCount = DBRes.GetRecordCount( Error );
  112. if (nCount > 0)
  113. {
  114. log_info( "init_monkey area. The record count=%d", nCount );
  115. while ( DBRes.GetNextRecod(Error) )
  116. {
  117. int area_id = 0;
  118. DBRes.GetField( "area_id",area_id, Error );
  119. int map_id = 0;
  120. DBRes.GetField( "map_id",map_id, Error );
  121. unsigned int area_type_id = 0;
  122. DBRes.GetField( "area_type_id",area_type_id, Error );
  123. int over_count_person = 0;
  124. DBRes.GetField( "over_count_person",over_count_person, Error );
  125. int over_count_vehicle = 0;
  126. DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
  127. int over_time_person = 0;
  128. DBRes.GetField( "over_time_person",over_time_person, Error );
  129. int over_time_vehicle = 0;
  130. DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
  131. std::string path;
  132. DBRes.GetField( "path",path, Error );
  133. float monkeycar_speed = 0;
  134. DBRes.GetField( "monkeycar_speed",monkeycar_speed, Error );
  135. std::string monkeycar_coor;
  136. DBRes.GetField( "monkeycar_coordinate",monkeycar_coor, Error );
  137. float scale=0;
  138. DBRes.GetField( "scale",scale, Error );
  139. log_info("init_area : id:%d,path:%s",area_id, path.c_str());
  140. std::shared_ptr<db_area> da = std::make_shared<db_area>();
  141. da->m_default_speed = monkeycar_speed;
  142. da->m_point = init_path(monkeycar_coor);
  143. std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
  144. ap->m_bound=init_path(path);
  145. for(const auto &p : ap->m_bound)
  146. log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  147. for(const auto &p : da->m_point)
  148. log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  149. map.insert({area_id,ap});
  150. }
  151. }
  152. area_list::instance()->add(map);
  153. }
  154. #endif
  155. void area_list::init_monkeycar_area(int id)
  156. {
  157. std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path, c.scale,\
  158. over_count_person, over_count_vehicle, over_time_person, over_time_vehicle,\
  159. over_speed_vehicle, is_attendance ,b.monkeycar_coordinate,b.monkeycar_speed \
  160. FROM dat_area a ,dat_monkeycar_base_info b ,dat_map c\
  161. where a.area_id = b.monkeycar_base_info_id and a.map_id = c.map_id";
  162. if(-1 == id)
  163. {
  164. sql.append(";");
  165. }
  166. else
  167. {
  168. sql.append(" AND a.area_id=");
  169. sql.append(std::to_string(id));
  170. sql.append(";");
  171. std_debug("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
  172. log_info("基础数据 monkeycar area 增加或修改区域 sql=%s", sql.c_str());
  173. }
  174. std::string Error;
  175. YADB::CDBResultSet DBRes;
  176. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  177. int nCount = DBRes.GetRecordCount( Error );
  178. if (nCount < 1)
  179. {
  180. log_error("基础数据 monkeycar area 增加或修改失败,数据库中找不到: area_id=%d", id);
  181. return ;
  182. }
  183. std::unordered_map<int,std::shared_ptr<area>> map;
  184. while ( DBRes.GetNextRecod(Error) )
  185. {
  186. int area_id = 0;
  187. DBRes.GetField( "area_id",area_id, Error );
  188. int map_id = 0;
  189. DBRes.GetField( "map_id",map_id, Error );
  190. unsigned int area_type_id = 0;
  191. DBRes.GetField( "area_type_id",area_type_id, Error );
  192. int over_count_person = 0;
  193. DBRes.GetField( "over_count_person",over_count_person, Error );
  194. int over_count_vehicle = 0;
  195. DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
  196. int over_time_person = 0;
  197. DBRes.GetField( "over_time_person",over_time_person, Error );
  198. int over_time_vehicle = 0;
  199. DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
  200. std::string path;
  201. DBRes.GetField( "path",path, Error );
  202. double monkeycar_speed = 0;
  203. DBRes.GetField( "monkeycar_speed",monkeycar_speed, Error );
  204. std::string monkeycar_coor;
  205. DBRes.GetField( "monkeycar_coordinate",monkeycar_coor, Error );
  206. double scale=0;
  207. DBRes.GetField( "scale",scale, Error );
  208. log_info("monkeycar area init_area : id:%d,path:%s",area_id, path.c_str());
  209. if(-1 == id)
  210. {
  211. std::shared_ptr<db_area> da = std::make_shared<db_area>();
  212. da->m_default_speed = monkeycar_speed;
  213. da->m_point = init_path(monkeycar_coor);
  214. std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,
  215. over_time_person,scale,map_id,area_type_id);
  216. ap->m_bound=init_path(path);
  217. for(const auto &p : ap->m_bound)
  218. log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  219. for(const auto &p : da->m_point)
  220. log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  221. map.insert({area_id,ap});
  222. }
  223. else
  224. {
  225. std::shared_ptr<db_area> da = std::make_shared<db_area>();
  226. da->m_default_speed = monkeycar_speed;
  227. da->m_point = init_path(monkeycar_coor);
  228. std::shared_ptr<area> ap = std::make_shared<monkey_area>(da,area_id,over_count_person,
  229. over_time_person,scale,map_id,area_type_id);
  230. ap->m_bound=init_path(path);
  231. for(const auto &p : ap->m_bound)
  232. log_info("point:monkey:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  233. for(const auto &p : da->m_point)
  234. log_info("point:monkey_coor:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  235. auto tmp_ptr = area_list::instance()->get(id);
  236. if(tmp_ptr)
  237. {
  238. area_list::instance()->remove(id);
  239. }
  240. area_list::instance()->add(id, ap);
  241. log_info("基础数据 monkeycar area增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,\
  242. scale:%.2f,map_id:%d,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
  243. id,over_count_person, over_time_person,scale,map_id,area_type_id,
  244. over_count_vehicle,over_time_vehicle);
  245. std_debug("基础数据 monkeycar area增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,\
  246. scale:%.2f,map_id:%d,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
  247. id,over_count_person, over_time_person,scale,map_id,area_type_id,
  248. over_count_vehicle,over_time_vehicle);
  249. }
  250. }
  251. if(-1 == id)
  252. {
  253. log_info( "monkeycar area init_area. The record count=%d\n", nCount );
  254. area_list::instance()->add(map);
  255. }
  256. }
  257. void area_list::init_from_db(int id/*=-1*/)
  258. {
  259. std::string sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
  260. over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, \
  261. over_speed_vehicle, is_attendance \
  262. FROM dat_area a,dat_map b\
  263. where a.map_id = b.map_id and area_id not in \
  264. (select monkeycar_base_info_id from dat_monkeycar_base_info)";
  265. if(-1 == id)
  266. {
  267. sql.append(";");
  268. }
  269. else
  270. {
  271. sql.append(" AND s.area_id=");
  272. sql.append(std::to_string(id));
  273. sql.append(";");
  274. log_info("基础数据 增加或修改区域 sql=%s", sql.c_str());
  275. }
  276. std::string Error;
  277. YADB::CDBResultSet DBRes;
  278. sDBConnPool.Query(sql.c_str(),DBRes,Error);
  279. int nCount = DBRes.GetRecordCount( Error );
  280. if (nCount < 1)
  281. {
  282. log_error("基础数据 增加或修改失败,数据库中找不到: area_id=%d:%s", id,sql.c_str());
  283. return ;
  284. }
  285. std::unordered_map<int,std::shared_ptr<area>> map;
  286. while ( DBRes.GetNextRecod(Error) )
  287. {
  288. int area_id = 0;
  289. DBRes.GetField( "area_id",area_id, Error );
  290. int map_id = 0;
  291. DBRes.GetField( "map_id",map_id, Error );
  292. unsigned int area_type_id = 0;
  293. DBRes.GetField( "area_type_id",area_type_id, Error );
  294. int over_count_person = 0;
  295. DBRes.GetField( "over_count_person",over_count_person, Error );
  296. int over_count_vehicle = 0;
  297. DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
  298. int over_time_person = 0;
  299. DBRes.GetField( "over_time_person",over_time_person, Error );
  300. int over_time_vehicle = 0;
  301. DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
  302. std::string path;
  303. DBRes.GetField( "path",path, Error );
  304. double scale = 0;
  305. DBRes.GetField( "scale",scale, Error );
  306. log_info("init_area : id:%d,path:%s",area_id, path.c_str());
  307. if(-1 == id)
  308. {
  309. std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,
  310. scale,map_id,area_type_id);
  311. ap->m_limit_vehicle_second = over_time_vehicle;
  312. ap->m_limit_vehicle_count = over_count_vehicle;
  313. ap->m_bound=init_path(path);
  314. for(const auto &p : ap->m_bound)
  315. log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  316. map.insert({area_id,ap});
  317. // CheckAreaType(ap,area_type_id,0);
  318. }
  319. else
  320. {
  321. auto tmp_ptr = area_list::instance()->get(id);
  322. if(tmp_ptr)
  323. {
  324. // CheckAreaType(tmp_ptr,area_type_id,tmp_ptr->m_area_type);
  325. tmp_ptr->update(over_count_person, over_time_person,scale,map_id,area_type_id,
  326. over_count_vehicle,over_time_vehicle);
  327. tmp_ptr->m_bound=init_path(path);
  328. }
  329. else
  330. {
  331. std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,
  332. scale,map_id,area_type_id);
  333. ap->m_limit_vehicle_second = over_time_vehicle;
  334. ap->m_limit_vehicle_count = over_count_vehicle;
  335. ap->m_bound=init_path(path);
  336. for(const auto &p : ap->m_bound)
  337. log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  338. area_list::instance()->add(id, ap);
  339. // CheckAreaType(ap,area_type_id,0);
  340. }
  341. log_info("基础数据 增加或修改区域成功:区域id:%d,over_count_person:%d over_time_person:%d,scale:%.2f,map_id:%d\
  342. ,area_type_id:%d,over_count_vehicle:%d,over_time_vehicle:%d",
  343. id,over_count_person, over_time_person,scale,map_id,area_type_id,
  344. over_count_vehicle,over_time_vehicle);
  345. }
  346. }
  347. if(-1 == id)
  348. {
  349. log_info( "init_area. The record count=%d\n", nCount );
  350. area_list::instance()->add(map);
  351. init_monkeycar_area();
  352. }
  353. }
  354. #if 0
  355. //新画禁区功能-给禁区中的卡发送警告及呼叫
  356. void area_list::CheckAreaType(int area_id,int new_area_type,int old_area_type)
  357. {
  358. auto area_ptr = area_list::instance()->get(area_id);
  359. if (!area_ptr) {
  360. log_info("区域已经删除:areaid=%d", area_id);
  361. return;
  362. }
  363. CheckAreaType(area_ptr,new_area_type,old_area_type);
  364. }
  365. void area_list::CheckAreaType( std::shared_ptr<area> pArea,int new_area_type,int old_area_type)
  366. {
  367. if (nullptr == pArea)
  368. {
  369. return ;
  370. }
  371. if (new_area_type != AREA_TYPE::AREA_TYPE_FORBIDDEN && old_area_type != AREA_TYPE::AREA_TYPE_FORBIDDEN)
  372. {
  373. return;
  374. }
  375. struct local_visit:visitor<std::shared_ptr<card_location_base>>
  376. {
  377. std::shared_ptr<area> m_area;
  378. int m_old_area_type;
  379. bool visit(std::shared_ptr<card_location_base> c)
  380. {
  381. //处理
  382. point pt(c->x,c->y,c->z);
  383. std::shared_ptr<area> point_area = area_list::instance()->get_area(pt);
  384. if (point_area == nullptr)
  385. {
  386. return true;
  387. }
  388. //不在区域里
  389. if (m_area->m_id != point_area->m_id)
  390. {
  391. return true;
  392. }
  393. if (m_area->m_area_type == AREA_TYPE::AREA_TYPE_FORBIDDEN)
  394. {
  395. //发送进入禁区的警告
  396. //呼叫
  397. std::shared_ptr<area_hover> _area_hover = c->get_area_hover();
  398. if (nullptr != _area_hover)
  399. {
  400. _area_hover->m_area = m_area;
  401. _area_hover->m_area->on_enter(_area_hover,c);
  402. }
  403. }
  404. else
  405. {
  406. if (m_old_area_type == AREA_TYPE::AREA_TYPE_FORBIDDEN)
  407. {
  408. //之前是禁区,改成非禁区
  409. //发送一个离开禁区的警告
  410. //停止呼叫
  411. std::shared_ptr<area_hover> _area_hover = c->get_area_hover();
  412. if (nullptr != _area_hover)
  413. {
  414. _area_hover->m_area->on_leave(_area_hover,c);
  415. }
  416. }
  417. else
  418. {
  419. return false;
  420. }
  421. }
  422. return true;
  423. }
  424. };
  425. local_visit lv;
  426. lv.m_area = pArea;
  427. lv.m_old_area_type = old_area_type;
  428. card_list::instance()->accept(lv);
  429. }
  430. #endif
  431. #if 0
  432. void area_list::init_from_db()
  433. {
  434. std::unordered_map<int,std::shared_ptr<area>> map;
  435. const char *sql = "SELECT a.area_id, a.name, a.map_id, a.area_type_id, a.path,b.scale, \
  436. over_count_person, over_count_vehicle, over_time_person, over_time_vehicle, over_speed_vehicle, is_attendance \
  437. FROM dat_area a,dat_map b\
  438. where a.map_id = b.map_id and area_id not in (select monkeycar_base_info_id from dat_monkeycar_base_info);";
  439. std::string Error;
  440. YADB::CDBResultSet DBRes;
  441. sDBConnPool.Query(sql,DBRes,Error);
  442. if(!Error.empty())
  443. log_error("monkeycar area init Error,%s",Error.c_str());
  444. int nCount = DBRes.GetRecordCount( Error );
  445. if (nCount > 0)
  446. {
  447. log_info( "init_area. The record count=%d\n", nCount );
  448. while ( DBRes.GetNextRecod(Error) )
  449. {
  450. int area_id = 0;
  451. DBRes.GetField( "area_id",area_id, Error );
  452. int map_id = 0;
  453. DBRes.GetField( "map_id",map_id, Error );
  454. unsigned int area_type_id = 0;
  455. DBRes.GetField( "area_type_id",area_type_id, Error );
  456. int over_count_person = 0;
  457. DBRes.GetField( "over_count_person",over_count_person, Error );
  458. int over_count_vehicle = 0;
  459. DBRes.GetField( "over_count_vehicle",over_count_vehicle, Error );
  460. int over_time_person = 0;
  461. DBRes.GetField( "over_time_person",over_time_person, Error );
  462. int over_time_vehicle = 0;
  463. DBRes.GetField( "over_time_vehicle",over_time_vehicle, Error );
  464. std::string path;
  465. DBRes.GetField( "path",path, Error );
  466. double scale = 0;
  467. DBRes.GetField( "scale",scale, Error );
  468. log_info("init_area : id:%d,path:%s",area_id, path.c_str());
  469. std::shared_ptr<area> ap = std::make_shared<area>(area_id,over_count_person,over_time_person,scale,map_id,area_type_id);
  470. ap->m_limit_vehicle_second = over_time_vehicle;
  471. ap->m_limit_vehicle_count = over_count_vehicle;
  472. ap->m_bound=init_path(path);
  473. for(const auto &p : ap->m_bound)
  474. log_info("point:area_id:%d--x:%.2f,y:%.2f",area_id,p.x,p.y);
  475. map.insert({area_id,ap});
  476. }
  477. }
  478. area_list::instance()->add(map);
  479. init_monkeycar_area();
  480. }
  481. #endif
  482. std::vector<point> area_list::init_path(std::string &str)
  483. {
  484. if(str.empty())
  485. log_error("area path empty()...");
  486. std::vector<point> vp;
  487. std::vector<std::string> vs;
  488. std::vector<std::string> vs1;
  489. boost::split(vs,str,boost::is_any_of("ML ;"));
  490. for(auto & s:vs)
  491. {
  492. if(s.empty())
  493. continue;
  494. boost::split(vs1,s,boost::is_any_of(","));
  495. if(vs1.size()!=2)
  496. log_error("area path data Error.pls check data table.");
  497. vp.emplace_back(atof(vs1[0].c_str()),atof(vs1[1].c_str()));
  498. }
  499. return std::move(vp);
  500. }
  501. std::vector<std::shared_ptr<area>> area_list::get_area(const std::shared_ptr<site> s,const point&pt)
  502. {
  503. std::vector<std::shared_ptr<area>> ret;
  504. auto map = area_list::instance()->m_map;
  505. for(const auto &a:map)
  506. {
  507. if(a.second->in_area(s, pt))
  508. {
  509. ret.push_back(a.second);
  510. }
  511. }
  512. //区域覆盖不完全地图,很多车辆人行驶在地图外,如何确认.
  513. return std::move(ret);
  514. }
  515. void area_tool::on_point(const std::shared_ptr<site>&s,std::shared_ptr<card_location_base> c,const point&pt)
  516. {
  517. log_info("on_point...cardid:%d,type:%d",c->m_id,c->m_type);
  518. setLandmark(pt);
  519. std::vector<std::shared_ptr<area>> areas=area_list::instance()->get_area(s, pt);//找出所有的区域
  520. std::sort(areas.begin(),areas.end(),[](std::shared_ptr<area>&l,std::shared_ptr<area>&r){
  521. return l->id()<r->id();
  522. });
  523. auto c1=m_hover_list.begin(),ce=m_hover_list.end();
  524. auto a1=areas.begin() ,ae=areas.end();
  525. std::vector<std::shared_ptr<area_hover>> nlist;
  526. while (c1!=ce && a1!=ae)
  527. {
  528. if ((*c1)->id()<(*a1)->id())
  529. {
  530. (*c1)->m_area->on_leave(*c1, c);
  531. ++c1;
  532. }
  533. else if ((*a1)->id()<(*c1)->id())
  534. {
  535. nlist.push_back(std::make_shared<area_hover>(*a1,pt));
  536. (*a1)->on_enter(nlist.back(),c);
  537. ++a1;
  538. }
  539. else
  540. {
  541. nlist.push_back(*c1);
  542. (*c1)->m_area->on_hover(*c1,c);
  543. ++c1,++a1;
  544. }
  545. }
  546. while(c1!=ce)
  547. {
  548. (*c1)->m_area->on_leave(*c1, c);
  549. ++c1;
  550. }
  551. while(a1!=ae)
  552. {
  553. nlist.push_back(std::make_shared<area_hover>(*a1,pt));
  554. (*a1)->on_enter(nlist.back(),c);
  555. ++a1;
  556. }
  557. m_hover_list=std::move(nlist);
  558. }
  559. void area_hover::setLandmark(const point &pt)
  560. {
  561. set(pt);
  562. auto lm = Landmark_list::instance()->get(mapid(),id(),pt);
  563. landmark_id = std::get<0>(lm);
  564. landmark_dir = std::get<1>(lm);
  565. landmark_dis = std::get<2>(lm)*scale();
  566. log_info("landmark:%d %d %.2f,(%.2f,%.2f),%f",landmark_id,landmark_dir,landmark_dis,pt.x,pt.y,scale());
  567. }