Exemple #1
0
        /// <summary>
        /// Gets called on double click on the map
        /// </summary>
        /// <param name="e">Mouse event arguments</param>
        protected override void OnDoubleClick(EventArgs e)
        {
            if (_readOnly)
            {
                return;
            }

            base.OnDoubleClick(e);

            if (CurrentPolygon == null || !CurrentPolygon.IsMouseOver)
            {
                return;
            }

            var zone         = (PolyZone)CurrentPolygon.Tag;
            var editZoneForm = new EditZoneForm(zone);

            if (editZoneForm.ShowDialog() == DialogResult.OK)
            {
                Client.Instance.Send(new UpdateZoneReq()
                {
                    Zone = JsonConvert.SerializeObject(editZoneForm.GetZone())
                });
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets called when a new polygon has been drawn or discarded
        /// Aka. Draw mode end
        /// <param name="save">Indicates whether to save or discard the current drawing polygon</param>
        /// </summary>
        private void EndDrawPolygonAsync(bool save)
        {
            IsDrawingPolygon = false;

            if (save && _currentDrawingPolygon.LocalPoints.Count - 1 > 1 && _currentDrawingPolygon.GetArea(true) > 0d)
            {
                // Remove "ghost" point marker
                _currentDrawingPolygon.Points.Remove(_currentNewRectMaker.Position);
                UpdatePolygonLocalPosition(_currentDrawingPolygon);

                var newZone = new PolyZone
                {
                    Geometry    = new List <Geometry>(),
                    Id          = "",
                    Zoneid      = "",
                    ServiceNa   = "Service provider",
                    Description = "New zone",
                    Timetable   = "",
                    Color       = ColorTranslator.ToHtml((_currentDrawingPolygon.Fill as SolidBrush)?.Color ?? Color.Black)
                };

                var editZoneForm = new EditZoneForm(newZone);
                if (editZoneForm.ShowDialog() == DialogResult.OK)
                {
                    newZone = editZoneForm.GetZone();
                    newZone.Geometry.AddRange(
                        _currentDrawingPolygon.Points.Select(x => x.ToGeometry(0))
                        );

                    var zoneSeriliazed = JsonConvert.SerializeObject(newZone, Converter.Settings);
                    Client.Instance.Send(new InsertZoneReq()
                    {
                        Zone = zoneSeriliazed
                    });
                    StartWaiting();

                    Client.Instance.OnZoneInsertAck += (ack) => {
                        newZone.Id = ack.ZoneId.ToString();

                        // Set newly inserted zone's point ids
                        for (var i = 0; i < newZone.Geometry.Count; i++)
                        {
                            newZone.Geometry[i].Id = ack.PointIds[i];
                        }

                        StopWaiting();
                    };

                    _currentDrawingPolygon.Tag = newZone;
                    _dtoObject.Zones.Add(newZone);
                }
                else
                {
                    _polygons.Polygons.Remove(_currentDrawingPolygon);
                }

                Map_OnPolygonClick(_polygons.Polygons.FirstOrDefault(polygon => polygon == _currentDrawingPolygon), null);
            }
            else
            {
                _polygons.Polygons.Remove(_currentDrawingPolygon);
            }

            OnDrawPolygonEnd?.Invoke(_currentDrawingPolygon);

            _currentDrawingPolygon = null;

            _topLayer.Markers.Remove(_currentNewRectMaker);
            _currentNewRectMaker = null;

            UpdateVerticlesCount();
        }