public void TestCacheModifySymbol() { using (ShimsContext.Create()) { client.Geometry.MapPoint p = new client.Geometry.MapPoint(0.0, 0.0); clientfake.ShimGraphic g = new clientfake.ShimGraphic(); client.FeatureService.Symbols.PictureMarkerSymbol pms = new client.FeatureService.Symbols.PictureMarkerSymbol(); Uri myUri = new Uri("../../resources/zoom_in_tool_1.bmp", UriKind.RelativeOrAbsolute); BitmapDecoder decoder = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; pms.Source = bitmapSource; clientfake.ShimUniqueValueRenderer r = new clientfake.ShimUniqueValueRenderer(); Dictionary<String, Object> attributes = new Dictionary<String, Object>(); attributes["uniquedesignation"] = "Wolfpack 1 C"; attributes["owningunit"] = "2nd Stryker Brigade"; attributes["type"] = "M1128"; g.AttributesGet = () => { return attributes; }; g.GeometryGet = () => { return p; }; Dictionary<String, String> fields = new Dictionary<String, String>(); fields["UID"] = "uniquedesignation"; fields["HF"] = "owningunit"; fields["LABELS"] = "uniquedesignation"; fields["DESCFLDS"] = "type"; fields["DESCFIELD"] = "type"; int count = cache.RetrieveFeatureCache("EQUIPMENT").Count; cache.AddFeature("EQUIPMENT", g, "Type: {type}", "{uniquedesignation}", fields, r); fields["LABELS"] = "uniquedesignation,owningunit"; g.SymbolGet = () => { return pms; }; cache.UpdateFeature("EQUIPMENT", "Wolfpack 1 C", "Type: {type}", "{uniquedesignation} owned by {owningunit}", g, fields); Dictionary<String, Dictionary<String, Object>> fcache = cache.RetrieveFeatureCache("EQUIPMENT"); Dictionary<String, Object> f = fcache["Wolfpack 1 C"]; ImageSource imsrc = f["ICON"] as ImageSource; Assert.AreEqual(pms.Source, imsrc); } }
public static ESRI.ArcGIS.Mapping.Core.Symbols.ImageFillSymbol ToImageFillSymbol( ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol pms) { if (pms != null) { Symbols.ImageFillSymbol symbol = SymbolFromJson(pms.ToJson()) as Symbols.ImageFillSymbol; if (string.IsNullOrEmpty(symbol.ImageData) && string.IsNullOrEmpty(symbol.Source)) { string imageData = SymbolExtensions.GetImageData(pms); string source; if (string.IsNullOrEmpty(symbol.ImageData) && !string.IsNullOrEmpty(imageData)) { symbol.ImageData = imageData; } else if (string.IsNullOrEmpty(symbol.Source) && !string.IsNullOrEmpty(source = SymbolExtensions.GetImageUrl(pms))) { symbol.Source = source; } } return(symbol); } return(null); }
public void TestCacheModifySymbol() { using (ShimsContext.Create()) { client.Geometry.MapPoint p = new client.Geometry.MapPoint(0.0, 0.0); clientfake.ShimGraphic g = new clientfake.ShimGraphic(); client.FeatureService.Symbols.PictureMarkerSymbol pms = new client.FeatureService.Symbols.PictureMarkerSymbol(); Uri myUri = new Uri("../../resources/zoom_in_tool_1.bmp", UriKind.RelativeOrAbsolute); BitmapDecoder decoder = new BmpBitmapDecoder(myUri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default); BitmapSource bitmapSource = decoder.Frames[0]; pms.Source = bitmapSource; clientfake.ShimUniqueValueRenderer r = new clientfake.ShimUniqueValueRenderer(); Dictionary <String, Object> attributes = new Dictionary <String, Object>(); attributes["uniquedesignation"] = "Wolfpack 1 C"; attributes["owningunit"] = "2nd Stryker Brigade"; attributes["type"] = "M1128"; g.AttributesGet = () => { return(attributes); }; g.GeometryGet = () => { return(p); }; Dictionary <String, String> fields = new Dictionary <String, String>(); fields["UID"] = "uniquedesignation"; fields["HF"] = "owningunit"; fields["LABELS"] = "uniquedesignation"; fields["DESCFLDS"] = "type"; fields["DESCFIELD"] = "type"; int count = cache.RetrieveFeatureCache("EQUIPMENT").Count; cache.AddFeature("EQUIPMENT", g, "Type: {type}", "{uniquedesignation}", fields, r); fields["LABELS"] = "uniquedesignation,owningunit"; g.SymbolGet = () => { return(pms); }; cache.UpdateFeature("EQUIPMENT", "Wolfpack 1 C", "Type: {type}", "{uniquedesignation} owned by {owningunit}", g, fields); Dictionary <String, Dictionary <String, Object> > fcache = cache.RetrieveFeatureCache("EQUIPMENT"); Dictionary <String, Object> f = fcache["Wolfpack 1 C"]; ImageSource imsrc = f["ICON"] as ImageSource; Assert.AreEqual(pms.Source, imsrc); } }
private void PerformPostLayerInitializationActions(Layer layer, bool initializationSuccess) { GraphicsLayer gLayer = layer as GraphicsLayer; if (gLayer != null) { GeometryType geometryType = Core.LayerExtensions.GetGeometryType(gLayer); Collection <FieldInfo> layerFields = Core.LayerExtensions.GetFields(gLayer); FeatureLayer featureLayer = layer as FeatureLayer; if (layerFields.Count == 0 && featureLayer != null && featureLayer.LayerInfo != null && featureLayer.LayerInfo.Fields != null) { foreach (ESRI.ArcGIS.Client.Field field in featureLayer.LayerInfo.Fields) { if (FieldHelper.IsFieldFilteredOut(field.Type)) { continue; } ESRI.ArcGIS.Mapping.Core.FieldInfo fieldInfo = ESRI.ArcGIS.Mapping.Core.FieldInfo.FieldInfoFromField(featureLayer, field); layerFields.Add(fieldInfo); } } if (gLayer.Graphics != null) { #region Get geometry type, start getting symbology if (geometryType == GeometryType.Unknown && gLayer.Graphics.Count > 0) { geometryType = LayerUtils.GetGeometryTypeFromGraphic(gLayer.Graphics.ElementAtOrDefault(0)); Core.LayerExtensions.SetGeometryType(gLayer, geometryType); if ((gLayer.Renderer == null || gLayer.Renderer is HiddenRenderer) && !Symbology.DefaultSymbols.ContainsKey(geometryType)) { if (geometryType == GeometryType.Unknown) { gLayer.SetValue(ESRI.ArcGIS.Client.Extensibility.LayerExtensions.ErrorMessageProperty, "Layer has unspecified geometry type."); } else { Core.LayerExtensions.SetRunLayerPostInitializationActions(gLayer, true); SymbolConfigProvider.GetDefaultLinearGradientBrush(gLayer, ColorRampType.ClassBreaks); } return; } } #endregion #region Project graphics if necessary if (graphicsRequireReprojection(gLayer.Graphics)) { GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper( new ConfigurationStoreHelper().GetGeometryServiceUrl(ConfigurationStore) ); helper.ProjectGraphicsCompleted += (sender, args) => { GraphicsLayer targetLayer = args.UserState as GraphicsLayer; if (targetLayer != null) { targetLayer.Graphics.Clear(); foreach (Graphic graphic in args.Graphics) { targetLayer.Graphics.Add(graphic); } } }; helper.ProjectGraphics(gLayer.Graphics, Map.SpatialReference, gLayer); } #endregion #region Get field information if (layerFields.Count == 0) // fields not determined yet { determineFieldsFromGraphic(layerFields, gLayer.Graphics.ElementAtOrDefault(0)); } #endregion } #region Get renderer from feature layer's layer info, if necessary if (gLayer.Renderer == null || gLayer.Renderer is HiddenRenderer) { FeatureLayer lay = gLayer as FeatureLayer; if (lay != null && lay.LayerInfo != null && lay.LayerInfo.Renderer != null) { lay.Renderer = lay.LayerInfo.Renderer; } } #endregion #region Change PictureMarkerSymbol to ImageFillSymbol if (gLayer.Renderer != null && (geometryType == GeometryType.Point || geometryType == GeometryType.MultiPoint)) { SimpleRenderer sr = gLayer.Renderer as SimpleRenderer; ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol pms = null; if (sr != null) { pms = sr.Symbol as ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol; if (pms != null) { sr.Symbol = SymbolJsonHelper.ToImageFillSymbol(pms); } } else { ClassBreaksRenderer cbr = gLayer.Renderer as ClassBreaksRenderer; if (cbr != null) { foreach (ClassBreakInfo info in cbr.Classes) { pms = info.Symbol as ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol; if (pms != null) { info.Symbol = SymbolJsonHelper.ToImageFillSymbol(pms); } } } else { UniqueValueRenderer uvr = gLayer.Renderer as UniqueValueRenderer; if (uvr != null) { foreach (UniqueValueInfo info in uvr.Infos) { pms = info.Symbol as ESRI.ArcGIS.Client.FeatureService.Symbols.PictureMarkerSymbol; if (pms != null) { info.Symbol = SymbolJsonHelper.ToImageFillSymbol(pms); } } } } } } #endregion if (gLayer.Renderer == null || gLayer.Renderer is HiddenRenderer) { ApplyDefaultRenderer(gLayer, geometryType); } ApplyDefaultGradientBrush(gLayer); } else if ((layer is ArcGISDynamicMapServiceLayer || layer is ArcGISTiledMapServiceLayer) && !((bool)layer.GetValue(ESRI.ArcGIS.Client.WebMap.Document.IsBaseMapProperty))) { //get layer infos - used later for figuring out domain/subtypes, etc if ((layer.GetValue(ESRI.ArcGIS.Mapping.Core.LayerExtensions.LayerInfosProperty) as Collection <LayerInformation>) == null) { getLayerInfos(layer); } } bool doSelect = false; layer.SetValue(ESRI.ArcGIS.Client.Extensibility.LayerExtensions.InitialUpdateCompletedProperty, true); if (!initializationSuccess) { layer.SetValue(ESRI.ArcGIS.Client.Extensibility.LayerExtensions.InitialUpdateFailedProperty, true); } else { bool hasId = !string.IsNullOrEmpty(layer.ID) || !string.IsNullOrEmpty(layer.GetValue(ESRI.ArcGIS.Client.Extensibility.MapApplication.LayerNameProperty) as string); // Certain layers get added when the map draw mode is changed (An empty graphics layer is added) // We don't want to auto-select this layer if (hasId || !(layer is GraphicsLayer)) { doSelect = true; } } if (doSelect) { SetSelectedLayer(new LayerEventArgs() { Layer = layer }); } SubscribeToLayerInitializationEvents(layer, false); }
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); } }
public Boolean UpdateFeature(String key, String id, String baseDesc, String baseLabel, client.Graphic feature, Dictionary <String, String> fields) { Boolean featureUpdated = false; Dictionary <String, Dictionary <String, object> > fList = _items[key]; Dictionary <String, object> f = fList[id]; client.Geometry.MapPoint pt = feature.Geometry as client.Geometry.MapPoint; object hf = feature.Attributes[fields["HF"]]; object currenthf = f["HF"]; object labelobj = parseLabel(feature, fields["LABELS"], baseLabel); String df = fields["DESCFIELD"]; String descFlds = fields["DESCFLDS"]; object descriptionobj = createDescriptionString(feature, baseDesc, df, descFlds); object currentLabel = f["LABEL"]; object currentDescription = f["DESCRIPTION"]; object currentCoords = f["COORDS"]; client.FeatureService.Symbols.PictureMarkerSymbol sym = feature.Symbol as client.FeatureService.Symbols.PictureMarkerSymbol; object currentsym = f["ICON"]; if (hf != null) { String hfLabel = hf.ToString(); if (currenthf != null) { String currentHfLabel = currenthf.ToString(); if (!hfLabel.Equals(currentHfLabel)) { f["HF"] = hfLabel; featureUpdated = true; } } else { f["HF"] = hfLabel; featureUpdated = true; } } else { if (currenthf != null) { f["HF"] = null; } } if (pt != null) { String coords = pt.X.ToString() + "," + pt.Y.ToString(); if (currentCoords != null) { if (!coords.Equals(currentCoords.ToString())) { f["COORDS"] = coords; client.Geometry.MapPoint cPoint = f["POINT"] as client.Geometry.MapPoint; geoCollection.Remove(cPoint); geoCollection.Add(pt); f["POINT"] = pt; featureUpdated = true; } } else { f["COORDS"] = coords; f["POINT"] = pt; geoCollection.Add(pt); featureUpdated = true; } } if (labelobj != null) { String label = labelobj.ToString(); if (currentLabel != null) { String currentNameLabel = currentLabel.ToString(); if (!label.Equals(currentNameLabel)) { f["LABEL"] = label; featureUpdated = true; } } else { f["LABEL"] = label; featureUpdated = true; } } else { if (currentLabel != null) { f["LABEL"] = null; } } if (descriptionobj != null) { String descLabel = descriptionobj.ToString(); if (currentDescription != null) { String currentNameLabel = currentDescription.ToString(); if (!descLabel.Equals(currentNameLabel)) { f["DESCRIPTION"] = descLabel; featureUpdated = true; } } else { f["DESCRIPTION"] = descLabel; featureUpdated = true; } } else { if (currentDescription != null) { f["DESCRIPTION"] = null; } } if (sym != null) { if (currentsym == null) { f["ICON"] = sym.Source; featureUpdated = true; } } else { _refreshSymbols = true; } if (featureUpdated) { String updates_key = key + "_UPDATE"; if (!_items[updates_key].ContainsKey(id)) { _items[updates_key].Add(id, f); } else { _items[updates_key][id] = f; } if (!_items[key].ContainsKey(id)) { _items[key].Add(id, f); } else { _items[key][id] = f; } } return(featureUpdated); }