/// <summary> /// Map provider topic /// </summary> //public string Topic //{ // get { return __topic as string; } // set // { // __topic = value; // SubscribeToMap(__topic); // } //} /// <summary> /// 采用调用服务方式获取地图数据 /// </summary> /// <param name="serviceName"></param> public void GetStaticMap(string serviceName) { lock (this) { if (imagehandle == null) { imagehandle = new NodeHandle(); } //if(mapServiceClient!=null) //{ // mapServiceClient.shutdown(); // mapServiceClient = null; //} //if (mapServiceClient != null) // return; //mapServiceClient = imagehandle.serviceClient<nm.GetMap>(serviceName); //nm.GetMap srv = new nm.GetMap(); nm.GetMap.Request req = new Messages.nav_msgs.GetMap.Request(); nm.GetMap.Response resp = new Messages.nav_msgs.GetMap.Response(); if (imagehandle.serviceClient <nm.GetMap.Request, nm.GetMap.Response>(serviceName).call(req, ref resp)) { nm.OccupancyGrid i = resp.map; mapResolution = i.info.resolution; owner.MapResolution = mapResolution; mapHeight = i.info.height; mapWidth = i.info.width; origin = new PointF((float)i.info.origin.position.x, (float)i.info.origin.position.y); Point left_bottomPoint = owner.Map2World(origin); left_bottomPoint.Offset(-(int)MapHeight, -(int)mapWidth); SetRectangle(left_bottomPoint.X, left_bottomPoint.Y, (int)mapHeight, (int)MapWidth); Size size = new Size((int)i.info.width, (int)i.info.height); byte[] data = createRGBA(i.data); UpdateImage(data, size, false); _originalImage = _image; _image.RotateFlip(RotateFlipType.Rotate270FlipNone); data = null; owner.PanX = owner.Width / 2 - (rectangle.Width / 2 + rectangle.Left); owner.PanY = owner.Height / 2 - (rectangle.Height / 2 + rectangle.Top); //owner.Invalidate(); owner.LastDataUpdateTime = DateTime.Now; } } }
private bool mapCallback(nm.GetMap.Request req, ref nm.GetMap.Response resp) { resp = map_resp_; return(true); }