Ejemplo n.º 1
0
 public Map(string source, MapSourceType sourceType, MapStorageType storageType)
 {
     this.source = source;
       this.sourceType = sourceType;
       this.storageType = storageType;
       this.image = GetImage(source, sourceType);
 }
Ejemplo n.º 2
0
 public Map(Stream stream)
 {
     this.source = null;
       this.sourceType = MapSourceType.FileSystem;
       this.storageType = MapStorageType.Inline;
       stream.Position = 0;
       this.image = StripQuickRouteHeader(stream);
 }
Ejemplo n.º 3
0
 public Map(Bitmap image)
 {
     this.source = null;
       this.sourceType = MapSourceType.FileSystem;
       this.storageType = MapStorageType.Inline;
       this.image = image;
       this.rawData = null;
 }
Ejemplo n.º 4
0
 /// <inheritdoc />
 public void Add(MapStorageType storageType, Element element, Range<int> levelOfDetails)
 {
     CoreLibrary.AddElementToStore(storageType,
         _resolver.Resolve(_stylesheet.Path),
         element, levelOfDetails, message =>
         {
             if (!String.IsNullOrEmpty(message))
                 throw new MapDataException(message);
         });
 }
Ejemplo n.º 5
0
        /// <summary> Identifies the map format from the specified file name. </summary>
        /// <param name="fileName"> The name of the file. </param>
        /// <param name="tryFallbackConverters"> Whether or not to attempt to try other converters if this fails. </param>
        /// <returns> Map format of the specified file. </returns>
        /// <exception cref="ArgumentNullException"> If fileName is null. </exception>
        /// <exception cref="FileNotFoundException"> If file/directory with the given name is missing. </exception>
        public static MapFormat Identify([NotNull] string fileName, bool tryFallbackConverters)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            MapStorageType targetType = MapStorageType.SingleFile;

            if (!File.Exists(fileName))
            {
                if (Directory.Exists(fileName))
                {
                    targetType = MapStorageType.Directory;
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }

            List <IMapImporter> fallbackConverters = new List <IMapImporter>();

            foreach (IMapImporter converter in Importers.Values)
            {
                try {
                    if (converter.StorageType == targetType && converter.ClaimsName(fileName))
                    {
                        if (converter.Claims(fileName))
                        {
                            return(converter.Format);
                        }
                    }
                    else
                    {
                        fallbackConverters.Add(converter);
                    }
                } catch { }
            }

            if (tryFallbackConverters)
            {
                foreach (IMapImporter converter in fallbackConverters)
                {
                    try {
                        if (converter.Claims(fileName))
                        {
                            return(converter.Format);
                        }
                    } catch { }
                }
            }

            return(MapFormat.Unknown);
        }
Ejemplo n.º 6
0
        public static Map Load([NotNull] string fileName)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            MapStorageType targetType = MapStorageType.SingleFile;

            if (!File.Exists(fileName))
            {
                if (Directory.Exists(fileName))
                {
                    targetType = MapStorageType.Directory;
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }

            List <IMapImporter> fallbackConverters = new List <IMapImporter>();

            // first try all converters for the file extension
            foreach (IMapImporter converter in Importers.Values)
            {
                bool claims = false;
                try {
                    claims = (converter.StorageType == targetType) &&
                             converter.ClaimsName(fileName) &&
                             converter.Claims(fileName);
                } catch { }
                if (claims)
                {
                    Map map = converter.Load(fileName);
                    map.HasChangedSinceSave = false;
                    return(map);
                }
                else
                {
                    fallbackConverters.Add(converter);
                }
            }

            foreach (IMapImporter converter in fallbackConverters)
            {
                try {
                    Map map = converter.Load(fileName);
                    map.HasChangedSinceSave = false;
                    return(map);
                } catch { }
            }

            throw new NoMapConverterFoundException("Could not find any converter to load the given file.");
        }
Ejemplo n.º 7
0
 /// <inheritdoc />
 public void Add(MapStorageType storageType, Element element, Range <int> levelOfDetails)
 {
     CoreLibrary.AddElementToStore(storageType,
                                   _resolver.Resolve(_stylesheet.Path),
                                   element, levelOfDetails, message =>
     {
         if (!String.IsNullOrEmpty(message))
         {
             throw new MapDataException(message);
         }
     });
 }
Ejemplo n.º 8
0
        /// <inheritdoc />
        public void AddToStore(MapStorageType storageType, string dataPath, Stylesheet stylesheet, Range <int> levelOfDetails)
        {
            var dataPathResolved       = _pathResolver.Resolve(dataPath);
            var stylesheetPathResolved = _pathResolver.Resolve(stylesheet.Path);

            Trace.Info(TraceCategory, String.Format("add to {0} storage: data:{1} using style: {2}",
                                                    storageType, dataPathResolved, stylesheetPathResolved));

            string errorMsg = null;

            CoreLibrary.AddToStore(storageType, stylesheetPathResolved, dataPathResolved, levelOfDetails,
                                   error => errorMsg = error);

            if (errorMsg != null)
            {
                throw new MapDataException(errorMsg);
            }
        }
Ejemplo n.º 9
0
        protected Map(SerializationInfo info, StreamingContext context)
        {
            source      = info.GetString("source");
            sourceType  = (MapSourceType)(info.GetValue("sourceType", typeof(MapSourceType)));
            storageType = (MapStorageType)(info.GetValue("storageType", typeof(MapStorageType)));
            switch (storageType)
            {
            case MapStorageType.Inline:
                //rawData = (byte[])(info.GetValueNo("rawData", typeof(byte[])));
                var getValueNoThrowMethod = info.GetType().GetMethod("GetValueNoThrow", BindingFlags.Instance | BindingFlags.NonPublic);
                rawData = (byte[])getValueNoThrowMethod.Invoke(info, new object[] { "rawData", typeof(byte[]) });


                if (rawData != null)
                {
                    // version 2.3 file format contains rawData field, create image from it
                    using (var ms = new MemoryStream(rawData))
                    {
                        image = (Bitmap)System.Drawing.Image.FromStream(ms);
                    }
                }
                else
                {
                    // version 2.2 file format
                    image = (Bitmap)(info.GetValue("image", typeof(Bitmap)));
                }
                break;

            case MapStorageType.Reference:
                switch (sourceType)
                {
                case MapSourceType.FileSystem:
                    image = (Bitmap)System.Drawing.Image.FromFile(source);
                    break;

                case MapSourceType.Url:
                    image = GetImageFromUrl(source);
                    break;
                }
                break;
            }
        }
Ejemplo n.º 10
0
        public static void AddElementToStore(MapStorageType storageType, string stylePath, Element element, Range<int> levelOfDetails, OnError onError)
        {
            double[] coordinates = new double[element.Geometry.Length*2];
            for (int i = 0; i < element.Geometry.Length; ++i)
            {
                coordinates[i*2] = element.Geometry[i].Latitude;
                coordinates[i*2 + 1] = element.Geometry[i].Longitude;
            }

            string[] tags = new string[element.Tags.Count * 2];
            var tagKeys = element.Tags.Keys.ToArray();
            for (int i = 0; i < tagKeys.Length; ++i)
            {
                tags[i*2] = tagKeys[i];
                tags[i*2 + 1] = element.Tags[tagKeys[i]];
            }

            addToStoreElement(GetStoreKey(storageType), stylePath, element.Id,
                coordinates, coordinates.Length,
                tags, tags.Length,
                levelOfDetails.Minimum, levelOfDetails.Maximum, onError);
        }
Ejemplo n.º 11
0
        public static void AddElementToStore(MapStorageType storageType, string stylePath, Element element, Range <int> levelOfDetails, OnError onError)
        {
            double[] coordinates = new double[element.Geometry.Length * 2];
            for (int i = 0; i < element.Geometry.Length; ++i)
            {
                coordinates[i * 2]     = element.Geometry[i].Latitude;
                coordinates[i * 2 + 1] = element.Geometry[i].Longitude;
            }

            string[] tags    = new string[element.Tags.Count * 2];
            var      tagKeys = element.Tags.Keys.ToArray();

            for (int i = 0; i < tagKeys.Length; ++i)
            {
                tags[i * 2]     = tagKeys[i];
                tags[i * 2 + 1] = element.Tags[tagKeys[i]];
            }

            addToStoreElement(GetStoreKey(storageType), stylePath, element.Id,
                              coordinates, coordinates.Length,
                              tags, tags.Length,
                              levelOfDetails.Minimum, levelOfDetails.Maximum, onError);
        }
Ejemplo n.º 12
0
 private static string GetStoreKey(MapStorageType storageType)
 {
     return(storageType == MapStorageType.InMemory ? InMemoryStoreKey : PersistentStoreKey);
 }
Ejemplo n.º 13
0
 /// <summary>
 ///     Adds map data to in-memory storage to specific level of detail range.
 ///     Supported formats: shapefile, osm xml, osm pbf.
 /// </summary>
 /// <param name="storageType"> Map data storage. </param>
 /// <param name="stylePath"> Stylesheet path. </param>
 /// <param name="path"> Path to file. </param>
 /// <param name="levelOfDetails"> Specifies level of details for which data should be imported. </param>
 /// <param name="onError"> OnError callback. </param>
 public static void AddToStore(MapStorageType storageType, string stylePath, string path, Range <int> levelOfDetails, OnError onError)
 {
     addToStoreInRange(GetStoreKey(storageType), stylePath, path, levelOfDetails.Minimum, levelOfDetails.Maximum, onError);
 }
Ejemplo n.º 14
0
 /// <inheritdoc />
 public void Edit(MapStorageType storageType, Element element, Range <int> levelOfDetails)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 /// <inheritdoc />
 public void Delete(MapStorageType storageType, long elementId, Range <int> levelOfDetails)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 /// <inheritdoc />
 public void Edit(MapStorageType storageType, Element element, Range<int> levelOfDetails)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 17
0
        protected Map(SerializationInfo info, StreamingContext context)
        {
            source = info.GetString("source");
              sourceType = (MapSourceType)(info.GetValue("sourceType", typeof(MapSourceType)));
              storageType = (MapStorageType)(info.GetValue("storageType", typeof(MapStorageType)));
              switch (storageType)
              {
            case MapStorageType.Inline:
              //rawData = (byte[])(info.GetValueNo("rawData", typeof(byte[])));
              var getValueNoThrowMethod = info.GetType().GetMethod("GetValueNoThrow", BindingFlags.Instance | BindingFlags.NonPublic);
              rawData = (byte[])getValueNoThrowMethod.Invoke(info, new object[] { "rawData", typeof(byte[]) });

              if (rawData != null)
              {
            // version 2.3 file format contains rawData field, create image from it
            using (var ms = new MemoryStream(rawData))
            {
              image = (Bitmap)System.Drawing.Image.FromStream(ms);
            }
              }
              else
              {
            // version 2.2 file format
            image = (Bitmap)(info.GetValue("image", typeof(Bitmap)));
              }
              break;

            case MapStorageType.Reference:
              switch (sourceType)
              {
            case MapSourceType.FileSystem:
              image = (Bitmap)System.Drawing.Image.FromFile(source);
              break;
            case MapSourceType.Url:
              image = GetImageFromUrl(source);
              break;
              }
              break;
              }
        }
Ejemplo n.º 18
0
 /// <inheritdoc />
 public void Delete(MapStorageType storageType, long elementId, Range<int> levelOfDetails)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 19
0
        /// <inheritdoc />
        public void AddToStore(MapStorageType storageType, string dataPath, Stylesheet stylesheet, Range<int> levelOfDetails)
        {
            var dataPathResolved = _pathResolver.Resolve(dataPath);
            var stylesheetPathResolved = _pathResolver.Resolve(stylesheet.Path);

            Trace.Info(TraceCategory, String.Format("add to {0} storage: data:{1} style: {2}",
                storageType, dataPathResolved, stylesheetPathResolved));

            string errorMsg = null;
            CoreLibrary.AddToStore(storageType, stylesheetPathResolved, dataPathResolved, levelOfDetails,
                error => errorMsg = error);

            if (errorMsg != null)
                throw new MapDataException(errorMsg);
        }
Ejemplo n.º 20
0
 /// <summary>
 ///     Adds map data to in-memory storage to specific quadkey.
 ///     Supported formats: shapefile, osm xml, osm pbf.
 /// </summary>
 /// <param name="storageType"> Map data storage. </param>
 /// <param name="stylePath"> Stylesheet path. </param>
 /// <param name="path"> Path to file. </param>
 /// <param name="quadKey"> QuadKey. </param>
 /// <param name="onError"> OnError callback. </param>
 public static void AddToStore(MapStorageType storageType, string stylePath, string path, QuadKey quadKey, OnError onError)
 {
     addToStoreInQuadKey(GetStoreKey(storageType), stylePath, path, quadKey.TileX, quadKey.TileY, quadKey.LevelOfDetail, onError);
 }
Ejemplo n.º 21
0
 private static string GetStoreKey(MapStorageType storageType)
 {
     return storageType == MapStorageType.InMemory ? InMemoryStoreKey : PersistentStoreKey;
 }
Ejemplo n.º 22
0
 /// <summary>
 ///     Adds map data to in-memory storage to specific quadkey.
 ///     Supported formats: shapefile, osm xml, osm pbf.
 /// </summary>
 /// <param name="storageType"> Map data storage. </param>
 /// <param name="stylePath"> Stylesheet path. </param>
 /// <param name="path"> Path to file. </param>
 /// <param name="quadKey"> QuadKey. </param>
 /// <param name="onError"> OnError callback. </param>
 public static void AddToStore(MapStorageType storageType, string stylePath, string path, QuadKey quadKey, OnError onError)
 {
     addToStoreInQuadKey(GetStoreKey(storageType), stylePath, path, quadKey.TileX, quadKey.TileY, quadKey.LevelOfDetail, onError);
 }
Ejemplo n.º 23
0
 /// <summary>
 ///     Adds map data to in-memory storage to specific level of detail range.
 ///     Supported formats: shapefile, osm xml, osm pbf.
 /// </summary>
 /// <param name="storageType"> Map data storage. </param>
 /// <param name="stylePath"> Stylesheet path. </param>
 /// <param name="path"> Path to file. </param>
 /// <param name="levelOfDetails"> Specifies level of details for which data should be imported. </param>
 /// <param name="onError"> OnError callback. </param>
 public static void AddToStore(MapStorageType storageType, string stylePath, string path, Range<int> levelOfDetails, OnError onError)
 {
     addToStoreInRange(GetStoreKey(storageType), stylePath, path, levelOfDetails.Minimum, levelOfDetails.Maximum, onError);
 }
Ejemplo n.º 24
0
        public static Map LoadHeader([NotNull] string fileName)
        {
            // ReSharper disable EmptyGeneralCatchClause
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            MapStorageType targetType = MapStorageType.SingleFile;

            if (!File.Exists(fileName))
            {
                if (Directory.Exists(fileName))
                {
                    targetType = MapStorageType.Directory;
                }
                else
                {
                    throw new FileNotFoundException();
                }
            }

            List <IMapConverter> fallbackConverters = new List <IMapConverter>();

            // first try all converters for the file extension
            foreach (IMapConverter converter in AvailableConverters.Values)
            {
                bool claims = false;
                try
                {
                    claims = (converter.StorageType == targetType) &&
                             converter.ClaimsName(fileName) &&
                             converter.Claims(fileName);
                }
                catch
                {
                }
                if (claims)
                {
                    try
                    {
                        Map map = converter.LoadHeader(fileName);
                        map.HasChangedSinceSave = false;
                        return(map);
                    }
                    catch (NotImplementedException)
                    {
                    }
                }
                else
                {
                    fallbackConverters.Add(converter);
                }
            }

            foreach (IMapConverter converter in fallbackConverters)
            {
                try
                {
                    Map map = converter.LoadHeader(fileName);
                    map.HasChangedSinceSave = false;
                    return(map);
                }
                catch
                {
                }
            }

            throw new MapFormatException("Unknown map format.");
            // ReSharper restore EmptyGeneralCatchClause
        }