public Map(string source, MapSourceType sourceType, MapStorageType storageType) { this.source = source; this.sourceType = sourceType; this.storageType = storageType; this.image = GetImage(source, sourceType); }
public Map(Stream stream) { this.source = null; this.sourceType = MapSourceType.FileSystem; this.storageType = MapStorageType.Inline; stream.Position = 0; this.image = StripQuickRouteHeader(stream); }
public Map(Bitmap image) { this.source = null; this.sourceType = MapSourceType.FileSystem; this.storageType = MapStorageType.Inline; this.image = image; this.rawData = null; }
/// <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); }); }
/// <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); }
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."); }
/// <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); } }); }
/// <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); } }
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; } }
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); }
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); }
private static string GetStoreKey(MapStorageType storageType) { return(storageType == MapStorageType.InMemory ? InMemoryStoreKey : PersistentStoreKey); }
/// <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); }
/// <inheritdoc /> public void Edit(MapStorageType storageType, Element element, Range <int> levelOfDetails) { throw new NotImplementedException(); }
/// <inheritdoc /> public void Delete(MapStorageType storageType, long elementId, Range <int> levelOfDetails) { throw new NotImplementedException(); }
/// <inheritdoc /> public void Edit(MapStorageType storageType, Element element, Range<int> levelOfDetails) { throw new NotImplementedException(); }
/// <inheritdoc /> public void Delete(MapStorageType storageType, long elementId, Range<int> levelOfDetails) { throw new NotImplementedException(); }
/// <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); }
/// <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); }
private static string GetStoreKey(MapStorageType storageType) { return storageType == MapStorageType.InMemory ? InMemoryStoreKey : PersistentStoreKey; }
/// <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); }
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 }