Пример #1
0
        /*private void set_equipment(object sender, RoutedEventArgs e)
         * {
         *  if ((Boolean)((CheckBox)sender).IsChecked)
         *  {
         *      DataSourceSelectorEquipment.IsEnabled = true;
         *      //EquipmentUIDComboBox.IsEnabled = true;
         *      //EquipmentHFComboBox.IsEnabled = true;
         *      //EquipmentLabelComboBox.IsEnabled = true;
         *  }
         *  else
         *  {
         *      if (DataSources.Count > 1)
         *      {
         *          DataSources.Remove(DataSources[1]);
         *      }
         *      DataSourceSelectorEquipment.IsEnabled = false;
         *      //EquipmentUIDComboBox.IsEnabled = false;
         *      //EquipmentHFComboBox.IsEnabled = false;
         *      //EquipmentLabelComboBox.IsEnabled = false;
         *  }
         * }*/

        private async void AddDatasourceToCache(OOBDataSource ods)
        {
            try
            {
                String Uid       = ods.UIDField;
                String HF        = ods.HFField;
                String DF        = ods.DescField;
                String Labels    = "";
                String DescFlds  = "";
                String CacheName = ods.Key;
                Dictionary <String, String> fields = new Dictionary <String, String>();
                fields["UID"] = Uid;
                fields["HF"]  = HF;

                Int32 numBaseFlds = 2;
                if (DF != null)
                {
                    fields["DESCFIELD"] = DF;
                    numBaseFlds         = 3;
                }

                Int32    arraySize = ods.LabelFields.Count + ods.DescriptionFields.Count + numBaseFlds;
                string[] qfields   = new string[arraySize];
                qfields[0] = Uid;
                qfields[1] = HF;
                if (DF != null)
                {
                    qfields[2] = DF;
                }
                Int32   c     = numBaseFlds;
                Boolean first = true;
                foreach (String f in ods.LabelFields)
                {
                    if (!first)
                    {
                        Labels += ",";
                    }
                    else
                    {
                        first = false;
                    }
                    Labels    += f;
                    qfields[c] = f;
                    ++c;
                }
                first = true;
                foreach (String f in ods.DescriptionFields)
                {
                    if (!first)
                    {
                        DescFlds += ",";
                    }
                    else
                    {
                        first = false;
                    }
                    DescFlds  += f;
                    qfields[c] = f;
                    ++c;
                }
                fields["LABELS"]   = Labels;
                fields["DESCFLDS"] = DescFlds;
                Query q = new Query();



                q.Fields = qfields;
                cache.AddFeatuereContainer(CacheName);

                DataSource ds = ods.DataSource;
                q.ReturnGeometry = true;
                QueryResult res = await ds.ExecuteQueryAsync(q);

                var resultOids = from feature in res.Features select System.Convert.ToInt32(feature.Attributes[ds.ObjectIdFieldName]);

                MapWidget           mw = MapWidget.FindMapWidget(ds);
                client.FeatureLayer fl = mw.FindFeatureLayer(ds);
                //fl.Update();
                client.UniqueValueRenderer r = fl.Renderer as client.UniqueValueRenderer;
                foreach (client.Graphic g in fl.Graphics)
                {
                    cache.AddFeature(CacheName, g, ods.BaseDescription, ods.BaseLabel, fields, r);
                }
                ods.IsCacheCreated = true;

                //cache.AddFeature
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message + "/n" + e.Source
                                               + "/n" + e.StackTrace);
            }
        }
Пример #2
0
        public void AddFeature(String key, client.Graphic feature, String baseDesc, String baseLabel, Dictionary <String, String> fields, client.UniqueValueRenderer ur)
        {
            try
            {
                Dictionary <String, Dictionary <String, object> > fList = _items[key];
                Dictionary <String, object> attributes = new Dictionary <String, object>();

                object uid = null, hf = null, label = null, description = null;
                client.Geometry.MapPoint pt = feature.Geometry as client.Geometry.MapPoint;

                uid   = feature.Attributes[fields["UID"]];
                hf    = feature.Attributes[fields["HF"]];
                label = parseLabel(feature, fields["LABELS"], baseLabel);
                String descFlds             = fields["DESCFLDS"];
                String df = fields["DESCFIELD"];
                description = createDescriptionString(feature, baseDesc, df, descFlds);
                //client.FeatureService.Symbols.PictureMarkerSymbol sym = feature.Symbol as client.FeatureService.Symbols.PictureMarkerSymbol;
                client.FeatureService.Symbols.PictureMarkerSymbol sym = ur.GetSymbol(feature) as client.FeatureService.Symbols.PictureMarkerSymbol;
                ImageSource isrc = null;

                if (uid != null)
                {
                    if (!fList.ContainsKey(uid.ToString()))
                    {
                        if (pt != null)
                        {
                            String coords = pt.X.ToString() + "," + pt.Y.ToString();
                            attributes["COORDS"] = coords;
                            attributes["POINT"]  = pt;
                            geoCollection.Add(pt);
                        }
                        if (hf != null)
                        {
                            attributes["HF"] = hf.ToString();
                        }
                        else
                        {
                            attributes["HF"] = null;
                        }
                        if (label != null)
                        {
                            attributes["LABEL"] = label;
                        }
                        else
                        {
                            attributes["LABEL"] = null;
                        }
                        if (description != null)
                        {
                            attributes["DESCRIPTION"] = description;
                        }
                        else
                        {
                            attributes["DESCRIPTION"] = null;
                        }
                        if (sym != null)
                        {
                            attributes["ICON"] = sym.Source;
                        }
                        else
                        {
                            attributes["ICON"] = isrc;
                        }
                        fList.Add(uid.ToString(), attributes);
                        _refreshSymbols = true;
                        _isDirty        = true;
                    }
                    else
                    {
                        r++;
                    }
                }
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message + "/n" + e.Source
                                               + "/n" + e.StackTrace);
            }
        }