コード例 #1
0
ファイル: MapPkgMapperHdd.cs プロジェクト: mitice/foo
        public void loadImages(MapPackage pkg)
        {
            Hashtable parts = new Hashtable();

            try
            {
                string        pathToParts   = this.mapsDir + "\\zoom_" + pkg.getZoom() + "\\" + pkg.getName() + "\\parts";
                DirectoryInfo partsDirInfo  = new DirectoryInfo(pathToParts);
                string        searchPattern = "*";
                if (pkg.getPartsFormat() != "")
                {
                    searchPattern += "." + pkg.getPartsFormat();
                }
                foreach (FileInfo partFileInfo in partsDirInfo.GetFiles(searchPattern))
                {
                    String partFileName = partFileInfo.Name;
                    // remove extension
                    char[] s    = ".".ToCharArray();
                    String name = partFileName.Split(s)[0];
                    // get part coordinates (not geografical)
                    s = "_".ToCharArray();
                    String[] pointStr = name.Split(s);
                    // NOTE: part images are named inversely, row number is first then col number
                    Point  p   = new Point(Convert.ToInt32(pointStr[1]), Convert.ToInt32(pointStr[0]));
                    Bitmap img = new Bitmap(pathToParts + "\\" + partFileInfo.ToString());
                    parts[p] = img;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("MapPkgRepository: loadImages: error during images load!");
                throw new MapPkgRepositoryException("error during images load", e);
            }
            try
            {
                // after successfully loading parts set them in map pkg
                foreach (DictionaryEntry part in parts)
                {
                    pkg.setPart((Point)part.Key, (Bitmap)part.Value);
                }
            }
            catch (Exception e)
            {
                pkg.freeParts();
                Debug.WriteLine("MapPkgRepository: loadImages: error during images put to map pkg!");
                throw new MapPkgRepositoryException("error during images put to map pkg", e);
            }
        }
コード例 #2
0
ファイル: MapSourceMem.cs プロジェクト: mitice/foo
 /// <summary>
 /// Find map package by coordinates in the source.
 /// </summary>
 /// <returns>MapPackage instance.</returns>
 public MapPackage findMapPkg(double latitude, double longitude, int zoom)
 {
     //foreach (MapPackage mapPkg in this.recentlyUsedMapPkgs)
     // iterate in reverse to start from the newest
     for (int i = this.recentlyUsedMapPkgs.Count - 1; i >= 0; i--)
     {
         MapPackage mapPkg = this.recentlyUsedMapPkgs[i];
         if (mapPkg.getZoom() == zoom && mapPkg.coordinatesMatches(latitude, longitude))
         {
             //Debug.WriteLine("MapSourceMem: findMapPkg: found map pkg: " + mapPkg);
             return(mapPkg);
         }
     }
     Debug.WriteLine("MapSourceMem: findMapPkg: not found pkg for: ("
                     + latitude + "; " + longitude + "), zoom: " + zoom);
     return(null);
 }