Beispiel #1
0
        public bool Read()
        {
            try
            {
                FileStream fs = _mapFile.StreamReader;
                fs.Position = 0;

                MagicByte = _mapFile.ReadFixedString(20);
                if (MagicByte != "mapsforge binary OSM")
                {
                    return(false);
                }
                HeaderSize   = _mapFile.ReadInt32();
                FileVersion  = _mapFile.ReadInt32();
                FileSize     = _mapFile.ReadInt64();
                CreationDate = new DateTime(1970, 1, 1).AddMilliseconds(_mapFile.ReadInt64());
                //minLat, minLon, maxLat, maxLon
                MinLat     = (double)_mapFile.ReadInt32() / 1000000.0;
                MinLon     = (double)_mapFile.ReadInt32() / 1000000.0;
                MaxLat     = (double)_mapFile.ReadInt32() / 1000000.0;
                MaxLon     = (double)_mapFile.ReadInt32() / 1000000.0;
                TileSize   = _mapFile.ReadInt16();
                Projection = _mapFile.ReadVariableString();
                byte b = (byte)fs.ReadByte();
                DebugInformationPresent   = (b & 0x80) == 0x80;
                MapStartPositionPresent   = (b & 0x40) == 0x40;
                MapStartZoomLevelPresent  = (b & 0x20) == 0x20;
                LanguagePreferencePresent = (b & 0x10) == 0x10;
                CommentPresent            = (b & 0x80) == 0x80;
                CreatedByPresent          = (b & 0x40) == 0x40;
                //todo
                if (MapStartPositionPresent)
                {
                    MapStartLat = (double)_mapFile.ReadInt32() / 1000000.0;
                    MapStartLon = (double)_mapFile.ReadInt32() / 1000000.0;
                }
                else
                {
                    MapStartLat = null;
                    MapStartLon = null;
                }
                if (MapStartZoomLevelPresent)
                {
                    MapStartZoomLevel = fs.ReadByte();
                }
                else
                {
                    MapStartZoomLevel = null;
                }
                if (LanguagePreferencePresent)
                {
                    LanguagePreference = _mapFile.ReadVariableString();
                }
                else
                {
                    LanguagePreference = null;
                }
                if (CommentPresent)
                {
                    Comment = _mapFile.ReadVariableString();
                }
                else
                {
                    Comment = null;
                }
                if (CreatedByPresent)
                {
                    CreatedBy = _mapFile.ReadVariableString();
                }
                else
                {
                    CreatedBy = null;
                }
                int cnt = _mapFile.ReadInt16();
                POITags = new Tag[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    string   s     = _mapFile.ReadVariableString();
                    string[] parts = s.Split(new char[] { '=' });
                    POITags[i] = new Tag(parts[0], parts[1]);
                }
                cnt     = _mapFile.ReadInt16();
                WayTags = new Tag[cnt];
                for (int i = 0; i < cnt; i++)
                {
                    string   s     = _mapFile.ReadVariableString();
                    string[] parts = s.Split(new char[] { '=' });
                    WayTags[i] = new Tag(parts[0], parts[1]);
                }
                ZoomIntervalCount          = fs.ReadByte();
                ZoomIntervalConfigurations = new ZoomIntervalConfiguration[ZoomIntervalCount];
                for (int i = 0; i < ZoomIntervalCount; i++)
                {
                    ZoomIntervalConfiguration zli = new ZoomIntervalConfiguration(
                        fs.ReadByte(),
                        fs.ReadByte(),
                        fs.ReadByte(),
                        _mapFile.ReadInt64(),
                        _mapFile.ReadInt64());
                    ZoomIntervalConfigurations[i] = zli;
                }
            }
            catch
            {
                return(false);
            }
            return(true);
        }