Пример #1
0
    private void DeleteMarkup()
    {
        int groupId = Request.Form["id"] != null?Convert.ToInt32(Request.Form["id"]) : -1;

        AppState appState = AppState.FromJson(Request.Form["state"]);

        double[] geo   = Request.Form["geo"].Split(',').Select(o => Convert.ToDouble(o)).ToArray();
        double   scale = Convert.ToDouble(Request.Form["scale"]);

        IGeometry searchShape;
        double    distance = 0;

        if (geo.Length == 4)
        {
            searchShape = EnvelopeExtensions.FromArray(geo).ToPolygon();
        }
        else
        {
            searchShape = new Point(geo[0], geo[1]);
            distance    = geo[2];
        }

        bool       deleted       = false;
        List <int> markupIndexes = new List <int>();

        for (int i = 0; i < appState.Markup.Count; ++i)
        {
            HitType hitType = MarkupHitTest(appState.Markup[i], searchShape, distance, scale);

            if (hitType != HitType.None)
            {
                markupIndexes.Add(i);
                deleted = true;
            }
        }

        if (groupId > -1)
        {
            try
            {
                using (OleDbConnection connection = AppContext.GetDatabaseConnection())
                {
                    bool   deletedInGroup = false;
                    string sql            = String.Format("select MarkupID, Shape, Text, Measured from {0}Markup where GroupID = ?", WebConfigSettings.ConfigurationTablePrefix);

                    using (OleDbCommand command = new OleDbCommand(sql, connection))
                    {
                        command.Parameters.Add("@1", OleDbType.Integer).Value = groupId;
                        DataTable table = new DataTable();

                        using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
                        {
                            adapter.Fill(table);
                        }

                        command.Parameters.Clear();

                        for (int i = table.Rows.Count - 1; i >= 0; --i)
                        {
                            DataRow row     = table.Rows[i];
                            HitType hitType = MarkupHitTest(row, searchShape, distance, scale);

                            if (hitType != HitType.None)
                            {
                                command.CommandText = String.Format("update {0}Markup set Deleted = 1 where MarkupID = {1}", WebConfigSettings.ConfigurationTablePrefix, row["MarkupID"]);
                                command.ExecuteNonQuery();
                                deletedInGroup = true;
                            }
                        }
                    }

                    if (deletedInGroup)
                    {
                        UpdateMarkupGroupLastAccessed(groupId, connection);
                        deleted = true;
                    }
                }
            }
            catch { }
        }

        Dictionary <string, object> result = new Dictionary <string, object>();

        result["deleted"] = deleted;

        if (markupIndexes.Count >= 0)
        {
            result["markup"] = markupIndexes;
        }

        ReturnJson(result);
    }
Пример #2
0
    private void SelectFeatures()
    {
        AppState appState  = AppState.FromJson(Request.Form["state"]);
        bool     updated   = false;
        bool     truncated = false;

        if (Request.Form["geo"] == null)
        {
            appState.SelectionManager.SelectTargets();
            updated = true;
        }
        else
        {
            double[] geo = Request.Form["geo"].Split(',').Select(o => Convert.ToDouble(o)).ToArray();

            CommonDataFrame        dataFrame   = AppContext.GetDataFrame(appState.MapTab);
            Configuration.LayerRow layer       = Configuration.Layer.First(o => o.LayerID == (appState.Action == Action.Select ? appState.TargetLayer : appState.SelectionLayer));
            CommonLayer            commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);
            CommonField            keyField    = commonLayer.FindField(layer.KeyField);

            string levelQuery = layer.GetLevelQuery(commonLayer, appState.Level);

            DataTable table = null;

            if (geo.Length == 4)
            {
                Envelope box = EnvelopeExtensions.FromArray(geo);

                if (!layer.IsMaxSelectionAreaNull() && layer.MaxSelectionArea > 0 && box.Width * box.Height > layer.MaxSelectionArea)
                {
                    throw new AppException("The selection shape was too large; try again with a smaller shape");
                }

                table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, box.ToPolygon());
            }
            else
            {
                table = commonLayer.GetFeatureTable(keyField.Name, levelQuery, geo[0], geo[1], geo[2]);
            }

            UpdateMode mode = (UpdateMode)Enum.Parse(typeof(UpdateMode), Request.Form["mode"], true);

            if (table != null && table.Rows.Count > 0)
            {
                if (appState.Action == Action.Select)
                {
                    updated = UpdateIds(appState.TargetIds, table, mode);

                    if (!layer.IsMaxNumberSelectedNull())
                    {
                        truncated = appState.TargetIds.Truncate(layer.MaxNumberSelected);
                    }

                    if (mode != UpdateMode.Remove && table.Rows.Count == 1)
                    {
                        updated = UpdateActive(appState, table.Rows[0][0].ToString()) || updated;
                    }
                }
                else
                {
                    updated = UpdateIds(appState.SelectionIds, table, mode);

                    if (!layer.IsMaxNumberSelectedNull())
                    {
                        appState.SelectionIds.Truncate(layer.MaxNumberSelected);
                    }

                    if (updated)
                    {
                        truncated = appState.SelectionManager.SelectTargets();
                    }
                }
            }
            else if (mode == UpdateMode.New)
            {
                updated = appState.Action == Action.Select ? appState.TargetIds.Count > 0 : appState.SelectionIds.Count > 0;
                appState.TargetIds.Clear();
                appState.SelectionIds.Clear();
                appState.ActiveMapId  = "";
                appState.ActiveDataId = "";
            }
        }

        if (!updated)
        {
            ReturnJson(null);
        }

        if (!appState.TargetIds.Contains(appState.ActiveMapId))
        {
            appState.ActiveMapId  = "";
            appState.ActiveDataId = "";
        }

        Dictionary <String, Object> state = new Dictionary <String, Object>();

        state.Add("ActiveMapId", appState.ActiveMapId);
        state.Add("ActiveDataId", appState.ActiveDataId);
        state.Add("TargetIds", appState.TargetIds);
        state.Add("SelectionIds", appState.SelectionIds);

        Dictionary <String, Object> result = new Dictionary <String, Object>();

        result.Add("state", state);
        result.Add("truncated", truncated);
        ReturnJson(result);
    }