Ejemplo n.º 1
0
 /// <summary>
 /// Put map package to the source.
 /// </summary>
 public void putMapPkg(MapPackage mapPkg)
 {
     if (this.recentlyUsedMapPkgs.Count >= CACHE_SIZE)
     {
         this.recentlyUsedMapPkgs[0].freeParts();
         this.recentlyUsedMapPkgs.RemoveAt(0);
     }
     this.recentlyUsedMapPkgs.Add(mapPkg);
 }
Ejemplo n.º 2
0
 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);
     }
 }
Ejemplo n.º 3
0
 public void update(GpsLocation currentGpsLocation, MapPackage currentMapPkg, int currentZoom)
 {
     this.currentGpsLocation = currentGpsLocation;
     this.currentMapPkg = currentMapPkg;
     this.currentZoom = currentZoom;
 }
Ejemplo n.º 4
0
 private void retrieveCurrentMapPkg()
 {
     double latitude = this.currentGpsLocation.getLatitude();
     double longitude = this.currentGpsLocation.getLongitude();
     // when current map pkg doesn't match, get pkg from repository
     if (!(this.currentMapPkg != null
         && this.currentMapPkg.coordinatesMatches(latitude, longitude)
         && this.currentMapPkg.getZoom() == this.currentZoom))
     {
         try
         {
             // get map package from repository
             this.currentMapPkg = this.mapPkgRepository.getMapPkg(latitude, longitude, this.currentZoom);
         }
         catch (MapNotFoundException e)
         {
             this.currentMapPkg = null;
             // map pkg for current location doesn't exist in repository
             this.mapDisplayer.displayMessage("No map for location.", 2000, Color.Red);
             return;
         }
     }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Put map package to the source.
 /// </summary>
 public void putMapPkg(MapPackage mapPkg)
 {
     // will be useful when map downloaded from web
     throw new Exception("The method or operation is not implemented.");
 }
Ejemplo n.º 6
0
 public void save(MapPackage pkg)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 7
0
 private MapPackage parseMapXml(string pkgName, string pathToMapXml)
 {
     // load xml document
     XmlDocument docMapXml = new XmlDocument();
     docMapXml.Load(pathToMapXml);
     // get description
     XmlNode descrNode = docMapXml.SelectSingleNode("/map/description");
     string descr = "";
     // description isn't required
     if (descrNode != null)
         descr = descrNode.InnerText;
     // get top left corner latitude
     XmlNode topLeftLatitudeNode = docMapXml.SelectSingleNode(
                                         "/map/coordinates/topLeft/latitude");
     double topLeftLatitude = parseCoordinate(topLeftLatitudeNode.InnerText);
     // get top left corner longitude
     XmlNode topLeftLongitudeNode = docMapXml.SelectSingleNode(
                                         "/map/coordinates/topLeft/longitude");
     double topLeftLongitude = parseCoordinate(topLeftLongitudeNode.InnerText);
     // get bottom right corner latitude
     XmlNode bottomRightLatitudeNode = docMapXml.SelectSingleNode(
                                         "/map/coordinates/bottomRight/latitude");
     double bottomRightLatitude = parseCoordinate(bottomRightLatitudeNode.InnerText);
     // get bottom right corner longitude
     XmlNode bottomRightLongitudeNode = docMapXml.SelectSingleNode(
                                         "/map/coordinates/bottomRight/longitude");
     double bottomRightLongitude = parseCoordinate(bottomRightLongitudeNode.InnerText);
     // get parts image format
     XmlNode partsFormatNode = docMapXml.SelectSingleNode("/map/parts/format");
     string partsFormat = "";
     // parts format aren't required
     if (partsFormatNode != null)
         partsFormat = partsFormatNode.InnerText;
     MapPackage mapPkg = new MapPackage(pkgName, topLeftLatitude, topLeftLongitude,
                             bottomRightLatitude, bottomRightLongitude);
     if (partsFormat != "")
         mapPkg.setPartsFormat(partsFormat);
     return mapPkg;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Put map package to the source.
 /// </summary>
 public void putMapPkg(MapPackage mapPkg)
 {
     throw new Exception("The method or operation is not implemented.");
 }
Ejemplo n.º 9
0
        // Get map package which is neighbour for given in specified direction.
        public MapPackage getNeighbourMapPkg(MapPackage pkg, Point direction, int zoom)
        {
            if (direction.X != -1 && direction.X != 0 && direction.X != 1 ||
                direction.Y != -1 && direction.Y != 0 && direction.Y != 1)
            {
                throw new MapNotFoundException("Bad direction!");
            }

            double topLeftLongitude = pkg.getTopLeftLongitude();
            double topLeftLatitude = pkg.getTopLeftLatitude();
            double bottomRightLongitude = pkg.getBottomRightLongitude();
            double bottomRightLatitude = pkg.getBottomRightLatitude();

            double longitude = (topLeftLongitude + bottomRightLongitude) / 2;
            double latitude = (topLeftLatitude + bottomRightLatitude) / 2;

            switch (direction.X)
            {
                case 1:
                    longitude = bottomRightLongitude + 0.000001;
                    break;
                case -1:
                    longitude = topLeftLongitude - 0.000001;
                    break;
            }
            // NOTE: y has inverted direction in map context
            switch (direction.Y)
            {
                case 1:
                    latitude = bottomRightLatitude - 0.000001;
                    break;
                case -1:
                    latitude = topLeftLatitude + 0.000001;
                    break;
            }

            return getMapPkg(latitude, longitude, zoom);
        }