Exemple #1
0
 public void OnPhotoBagChanged()
 {
     App.Current.Dispatcher.Invoke((Action) delegate // <--- HERE
     {
         PhotoCollection.Clear();
         PhotoCollection.AddRange(PhotoBag);
     });
 }
Exemple #2
0
        /// <summary>
        /// This method takes a bounding box and returns
        /// Photocollection covering the bounding box from
        /// cache or from downloaded data
        /// </summary>
        /// <param name="west"></param>
        /// <param name="south"></param>
        /// <param name="east"></param>
        /// <param name="north"></param>
        /// <returns></returns>
        private PhotoCollection GetPhotoCollection(double west, double south
                                                   , double east, double north)
        {
            PhotoCollection collection = new PhotoCollection();
            double          tileSize   = 10.0;

            /*
             * //base the tile size on the max viewing distance
             * double maxDistance = m_maxdistance;// Math.Sqrt(m_maximumDistanceSq);
             *
             * double factor = maxDistance / m_world.EquatorialRadius;
             * // True view range
             * if (factor < 1)
             *  tileSize = Angle.FromRadians(Math.Abs(Math.Asin(maxDistance / m_world.EquatorialRadius)) * 2).Degrees;
             * else
             *  tileSize = Angle.FromRadians(Math.PI).Degrees;
             *
             * tileSize = (180 / (int)(180 / tileSize));
             *
             * if (tileSize == 0)
             *  tileSize = 0.1;
             */
            //Log.Write(Log.Levels.Debug, string.Format("TS: {0} -> {1}", name, tileSize));
            //not working for some reason...
            //int startRow = MathEngine.GetRowFromLatitude(south, tileSize);
            //int endRow = MathEngine.GetRowFromLatitude(north, tileSize);
            //int startCol = MathEngine.GetColFromLongitude(west, tileSize);
            //int endCol = MathEngine.GetColFromLongitude(east, tileSize);

            double currentSouth = -90;
            //for (int row = 0; row <= endRow; row++)
            XmlSerializer serializer = new XmlSerializer(typeof(PhotoCollection));

            while (currentSouth < 90)
            {
                double currentNorth = currentSouth + tileSize;
                if (currentSouth > north || currentNorth < south)
                {
                    currentSouth += tileSize;
                    continue;
                }

                double currentWest = -180;
                while (currentWest < 180)
                //    for (int col = startCol; col <= endCol; col++)
                {
                    double currentEast = currentWest + tileSize;
                    if (currentWest > east || currentEast < west)
                    {
                        currentWest += tileSize;
                        continue;
                    }



                    if (!Directory.Exists(m_cachedir))
                    {
                        Directory.CreateDirectory(m_cachedir);
                    }

                    string collectionFilename = m_cachedir
                                                + currentEast + "_"
                                                + currentWest + "_"
                                                + currentNorth + "_"
                                                + currentSouth + ".xml";
                    PhotoCollection currentPhotoCollection;
                    if (File.Exists(collectionFilename))
                    {
                        currentPhotoCollection = (PhotoCollection)serializer.Deserialize(
                            new FileStream(collectionFilename, FileMode.Open));
                    }
                    else
                    {
                        searchOptions.BoundaryBox = new BoundaryBox(currentWest, currentSouth,
                                                                    currentEast, currentNorth);
                        Photos photos = flickr.PhotosSearch(searchOptions);
                        currentPhotoCollection = photos.PhotoCollection;
                        serializer.Serialize(new FileStream(
                                                 collectionFilename, FileMode.Create), currentPhotoCollection);
                    }

                    collection.AddRange(currentPhotoCollection);

                    currentWest += tileSize;
                }
                currentSouth += tileSize;
            }
            return(collection);
        }