Ejemplo n.º 1
0
        private void QueryPOIBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            _pois = new List <POI>();
            var query = e.Argument as string;

            var left = (from q in _blocks
                        orderby q.Center.Lng
                        select q.Center.Lng).FirstOrDefault();
            var top = (from q in _blocks
                       orderby q.Center.Lat descending
                       select q.Center.Lat).FirstOrDefault();
            var bottom = (from q in _blocks
                          orderby q.Center.Lat
                          select q.Center.Lat).FirstOrDefault();
            var right = (from q in _blocks
                         orderby q.Center.Lng descending
                         select q.Center.Lng).FirstOrDefault();

            MapPainter mp = new MapPainter(left, top, bottom, right);

            mp.Map         = picMap.Image.Clone() as Bitmap;
            mp.PaintEvent += Mp_PaintEvent;
            foreach (var block in _blocks)
            {
                _pois.AddRange(block.ReadBlockPOI(query, 20));
                mp.Draw(block.Center.Lat, block.Center.Lng, Color.DarkGreen);
                var bwk = sender as BackgroundWorker;
                bwk.ReportProgress(1);
            }
            e.Result = _pois;
        }
Ejemplo n.º 2
0
        public List <Block> SplitBlock()
        {
            CityCenter = GetCityCenter();

            var blocks = new List <Block>();

            int round = 1;

            while (Spread(round++, blocks))
            {
                blocks = blocks.Where(i => i.InCity).ToList();

                var left = (from q in blocks
                            orderby q.Center.Lng
                            select q.Center.Lng).FirstOrDefault();
                var top = (from q in blocks
                           orderby q.Center.Lat descending
                           select q.Center.Lat).FirstOrDefault();
                var bottom = (from q in blocks
                              orderby q.Center.Lat
                              select q.Center.Lat).FirstOrDefault();
                var right = (from q in blocks
                             orderby q.Center.Lng descending
                             select q.Center.Lng).FirstOrDefault();

                MapPainter mp = new MapPainter(left, top, bottom, right);

                foreach (var block in blocks)
                {
                    mp.Draw(block.Center.Lat, block.Center.Lng, block.DistrictColor);
                }
                if (NewRound != null)
                {
                    NewRound.Invoke(this, new NewRoundEventArgs()
                    {
                        Count = blocks.Count, Map = mp.Map
                    });
                }
            }

            return(blocks);
        }
Ejemplo n.º 3
0
        private void DeserializeBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var path = e.Argument as string;

            if (!string.IsNullOrEmpty(path) && File.Exists(path))
            {
                JavaScriptSerializer jss = new JavaScriptSerializer();
                jss.MaxJsonLength = Int32.MaxValue;
                var str = File.ReadAllText(path);
                _blocks = jss.Deserialize <List <Block> >(str);
                if (_blocks != null && _blocks.Count > 0)
                {
                    var left = (from q in _blocks
                                orderby q.Center.Lng
                                select q.Center.Lng).FirstOrDefault();
                    var top = (from q in _blocks
                               orderby q.Center.Lat descending
                               select q.Center.Lat).FirstOrDefault();
                    var bottom = (from q in _blocks
                                  orderby q.Center.Lat
                                  select q.Center.Lat).FirstOrDefault();
                    var right = (from q in _blocks
                                 orderby q.Center.Lng descending
                                 select q.Center.Lng).FirstOrDefault();

                    MapPainter mp = new MapPainter(left, top, bottom, right);

                    foreach (var block in _blocks)
                    {
                        mp.Draw(block.Center.Lat, block.Center.Lng, block.DistrictColor);
                    }

                    e.Result = mp.Map;
                }
                else
                {
                    e.Result = null;
                }
            }
        }