コード例 #1
0
        /// <summary>
        /// Inserts a new map polyline into the database.
        /// </summary>
        /// <param name="item">Object containing porperties to be inserted into the database.</param>
        public static async Task InsertMapPolylineItemAsync(MapPolylineItem item)
        {
            using (var cnn = await GetDbConnectionAsync())
            {
                cnn.Open();

                item.Id = (int)await cnn.ExecuteScalarAsync <long>(
                    @"INSERT INTO MapElement (Name, Type, StrokeColor, Width, Layer_Id)
                    VALUES (@Name, @Type, @StrokeColor, @Width, @Layer_Id);
                    SELECT last_insert_rowid();",
                    new
                {
                    item.Name,
                    Type        = "MapPolylineItem",
                    StrokeColor = StringColorConverter.ArgbColorToString(item.StrokeColor),
                    item.Width,
                    Layer_Id = item.ParentLayer.Id
                });

                var list = from g in item.Path
                           select new
                {
                    g.Altitude,
                    g.Latitude,
                    g.Longitude,
                    MapElement_Id = item.Id
                };

                await cnn.ExecuteAsync(
                    @"INSERT INTO Geoposition (Altitude, Latitude, Longitude, MapElement_Id)
                    VALUES (@Altitude, @Latitude, @Longitude, @MapElement_Id)",
                    list);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new instance of MapPolylineItem class.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="width"></param>
        /// <param name="length"></param>
        /// <param name="polygonRepresentationPath"></param>
        /// <param name="path"></param>
        /// <param name="layer"></param>
        /// <param name="strokeColor"></param>
        /// <returns></returns>
        public static MapPolylineItem GetMapPolylineItem(int id,
                                                         string name,
                                                         double width,
                                                         double length,
                                                         IReadOnlyList <BasicGeoposition> polygonRepresentationPath,
                                                         IReadOnlyList <BasicGeoposition> path,
                                                         MapLayerItem layer,
                                                         Color strokeColor)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("Name cannot be empty", nameof(name));
            }

            if (polygonRepresentationPath is null)
            {
                throw new ArgumentNullException(nameof(polygonRepresentationPath));
            }

            if (path is null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (layer is null)
            {
                throw new ArgumentNullException(nameof(layer));
            }

            MapPolylineItem result = new MapPolylineItem()
            {
                Id          = id,
                ParentLayer = layer,
                Name        = name,
                Length      = length,
                Width       = width,
                Path        = path
            };

            MapPolygon element = new MapPolygon()
            {
                FillColor   = strokeColor,
                StrokeColor = strokeColor,
                ZIndex      = layer.Id
            };

            element.Paths.Add(new Geopath(polygonRepresentationPath));
            result.Element = element;
            return(result);
        }