static void OnAttributesChange(DependencyObject o, DependencyPropertyChangedEventArgs args) { HoverResults hr = o as HoverResults; if (hr == null) { return; } hr.Graphic = hr.Layer.Graphics.FirstOrDefault(item => item.Attributes == hr.Attributes); //null or matching graphic #if DEBUG if (hr.Attributes == null) { Debug.WriteLine(string.Format("@@Change, NULL, {0}", MapApplication.GetLayerName(hr.Layer))); } else if (hr.Attributes.ContainsKey("NAME")) { Debug.WriteLine(string.Format("@@Change, {0}, {1}", hr.Attributes["NAME"], MapApplication.GetLayerName(hr.Layer))); } else { Debug.WriteLine(string.Format("@@Change (no NAME field), {0}", MapApplication.GetLayerName(hr.Layer))); } #endif PositionMapTip.rebuildMapTipContentsBasedOnFieldVisibility(hr); }
private void attachApplicationMapTipToLayer(GraphicsLayer layer, Graphic g) { #if DEBUG Debug.WriteLine(string.Format("@@Attaching map tip to layer: {0}", MapApplication.GetLayerName(layer))); #endif // Create a new control each time a popup is to be displayed. This is to reset the controls to their // initial state. If this is not done, and you have controls like ToggleButtons, they may retain their // expanded or collapsed state even though binding is supposed to reset this. This way, you have a // consistent starting point for the display of a popup. HoverResults hoverResults = new HoverResults() { Style = HoverLayoutStyleHelper.Instance.GetStyle("HoverPopupContainerStyle"), Layer = layer, Graphic = g, Map = AssociatedObject }; // Associate map tip control with layer layer.MapTip = hoverResults; layer.MapTip.SizeChanged -= MapTip_SizeChanged; layer.MapTip.SizeChanged += MapTip_SizeChanged; // re-establish delay TimeSpan delay = (TimeSpan)AssociatedObject.GetValue(DelayMapTipHide.HideDelayProperty); layer.MapTip.SetValue(GraphicsLayer.MapTipHideDelayProperty, delay); }
} // private Layer createLayer(string id, bool vis) private void getLyrSignature(Map map, ESRI.ArcGIS.Client.Layer l) { // get all Layer parameters string typ = lyr.GetType().ToString(); string[] parts = typ.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries); if (parts.Length > 0) { typ = parts[parts.Length - 1]; } lyrType = typ; lyrName = MapApplication.GetLayerName(l); popupOn = ESRI.ArcGIS.Client.Extensibility.LayerProperties.GetIsPopupEnabled(l); // sublayers popups on/off http://forums.arcgis.com/threads/58106-Popup-for-visible-layers-only?highlight=popups var ids = ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetIdentifyLayerIds(l); //var ids = new System.Collections.ObjectModel.Collection<int>(); var xmlszn = new System.Xml.Serialization.XmlSerializer(typeof(System.Collections.ObjectModel.Collection <int>)); var sw = new StringWriter(); xmlszn.Serialize(sw, ids); identifyLayerIds = string.Format("{0}", sw.ToString().Trim()); if (typ == "ArcGISTiledMapServiceLayer") { var lr = (ArcGISTiledMapServiceLayer)lyr; lyrUrl = lr.Url; proxy = lr.ProxyURL; } else if (typ == "OpenStreetMapLayer") { var lr = lyr as ESRI.ArcGIS.Client.Toolkit.DataSources.OpenStreetMapLayer; lyrUrl = "http://www.openstreetmap.org/"; } else if (typ == "ArcGISDynamicMapServiceLayer") { var lr = (ArcGISDynamicMapServiceLayer)lyr; lyrUrl = lr.Url; proxy = lr.ProxyURL; imageFormat = lr.ImageFormat; } else if (typ == "FeatureLayer") { var lr = (FeatureLayer)lyr; lyrUrl = lr.Url; renderer = getRenderer(lr); proxy = lr.ProxyUrl; } else if (typ == "GraphicsLayer") { var lr = (GraphicsLayer)lyr; lyrUrl = getContent(lr); renderer = getRenderer(lr); proxy = ""; } return; } // private string getLyrSignature(Map map, ESRI.ArcGIS.Client.Layer lyr)
// Get mouse position void GraphicsLayer_MouseEnterOrMove(object sender, GraphicMouseEventArgs args) { _mousePos = args.GetPosition(AssociatedObject); GraphicsLayer graphicsLayer = sender as GraphicsLayer; #if DEBUG if (args.Graphic != null) { if (args.Graphic.Symbol is ESRI.ArcGIS.Client.Clustering.FlareSymbol) { Debug.WriteLine(string.Format("@@MouseEnter/Move, flare, {0}", MapApplication.GetLayerName(graphicsLayer))); } else if (args.Graphic.Attributes.ContainsKey("NAME")) { Debug.WriteLine(string.Format("@@MouseEnter/Move, {0}, {1}", args.Graphic.Attributes["NAME"], MapApplication.GetLayerName(graphicsLayer))); } else { Debug.WriteLine(string.Format("@@MouseEnter/Move, no NAME field, {0}", MapApplication.GetLayerName(graphicsLayer))); } } #endif if (ESRI.ArcGIS.Client.Extensibility.LayerProperties.GetIsPopupEnabled(graphicsLayer)) { if (!ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetPopUpsOnClick(graphicsLayer)) { HoverResults hoverResults = graphicsLayer.MapTip as HoverResults; if (graphicsLayer.MapTip == null) //if not a custom map tip { //if first time, attach map tip to layer attachApplicationMapTipToLayer(graphicsLayer, args.Graphic); hoverResults = graphicsLayer.MapTip as HoverResults; } //if map tip dirty, rebuild map tip if (hoverResults != null) { if (ESRI.ArcGIS.Mapping.Core.LayerExtensions.GetIsMapTipDirty(graphicsLayer) && args.Graphic == hoverResults.Graphic) { rebuildMapTipContentsBasedOnFieldVisibility(hoverResults); } //clear map tip dirty flag ESRI.ArcGIS.Mapping.Core.LayerExtensions.SetIsMapTipDirty(graphicsLayer, false); } } else { graphicsLayer.MapTip = null; } } else if (graphicsLayer.MapTip is HoverResults) { graphicsLayer.MapTip = null; } }
/// <summary> /// Checks whether a layer is in a measurable state /// </summary> /// <param name="layer">The layer to check</param> /// <param name="map">The map containing the layer</param> /// <returns></returns> internal static bool IsMeasurable(this Layer layer, Map map) { // Check whether the layer is visible, of a measurable type, has a defined layer name, and is not // hidden due to scale dependency bool measurable = layer.Visible && ((layer is ArcGISDynamicMapServiceLayer) || (layer is GraphicsLayer && ((GraphicsLayer)layer).GeometryType() != null && ((GraphicsLayer)layer).GeometryType() != ESRI.ArcGIS.Client.Tasks.GeometryType.MultiPoint)) && !string.IsNullOrEmpty(MapApplication.GetLayerName(layer)) && layer.IsInVisibleRange(map); // For map service layers, make sure at least one sub-layer is visible if (measurable && layer is ArcGISDynamicMapServiceLayer) { ArcGISDynamicMapServiceLayer dynLayer = (ArcGISDynamicMapServiceLayer)layer; // Check sub-layer visibility directly and as defined by the sub-layer's scale dependency measurable = dynLayer.Layers.Any(subLayer => dynLayer.GetLayerVisibility(subLayer.ID) && subLayer.IsInVisibleRange(map)); } return(measurable); }
/// <summary> /// Creates the permanent layer from the results of the Query /// </summary> /// <returns>Permanent <see cref="ESRI.ArcGIS.Client.FeatureLayer"/></returns> /// <remarks>The permanent layer uses the default renderer of the layer. /// The permanent layer is visible in the Map Contents panel.</remarks> private FeatureLayer CreatePermanentLayer() { // Check that the results layer is not null and use the results layer to create the permanent layer if (resultsLayer != null) { permanentLayer = resultsLayer; // Create a layer ID for displaying the layer in the map contents and attribute table string permanentLayerID = string.Format(Strings.RelatedTo, permanentLayer.LayerInfo.Name, PopupInfo.PopupItem.Title); // If there is more than one layer with the same name, add a number to the end of the name int layerCountSuffix = 0; string layerName; // Verify the next number in the sequence hasn't been used. If layers are renamed after the name is generated, a scenario may occur where // the last number used in the name is actually greater than the number of existing layers with the same name. We don't want a number to // repeat, so we check the last number used. foreach (Layer layer in map.Layers) { layerName = MapApplication.GetLayerName(layer); if (layerName != null && layerName.StartsWith(permanentLayerID)) { if (layerName.EndsWith(")")) { // Split the layer name at the end to get the last number used (number contained within the parentheses) string[] splitLayerName = layerName.Split('('); int lastNumberAppended = Convert.ToInt32(splitLayerName.Last <string>().TrimEnd(')')); // If the last number used is greater than the count of number of existing layers with the same name, // set the count to the last number used. if (lastNumberAppended > layerCountSuffix) { layerCountSuffix = lastNumberAppended; } } else // Found a layer with the same name, but no (#) suffix. This is the first layer added with this name. { // Only set the suffix based on this layer if the suffix has not yet been set (i.e. is still zero) if (layerCountSuffix == 0) { layerCountSuffix = 1; } } } } if (layerCountSuffix != 0) { permanentLayerID += string.Format(" ({0})", layerCountSuffix + 1); } MapApplication.SetLayerName(permanentLayer, permanentLayerID); // Create a unique ID for the layer. permanentLayer.ID = Guid.NewGuid().ToString(); // If the results layer is a table, don't show it in the map contents. if (resultsLayer.LayerInfo.Type == "Table") { LayerProperties.SetIsVisibleInMapContents(permanentLayer, false); } else { LayerProperties.SetIsVisibleInMapContents(permanentLayer, true); } // Set the layer renderer to the renderer of the original layer permanentLayer.Renderer = resultsLayer.LayerInfo.Renderer; } return(permanentLayer); }
/// <summary> /// Toggles the query UI on or off /// </summary> public void Execute(object parameter) { ToolExecuting = true; // Updates tool DataContext with savedConfiguration. var toolViewModel = toolView.DataContext as QueryViewModel; if (toolViewModel == null) { toolViewModel = savedConfiguration != null ? new QueryViewModel(savedConfiguration) : new QueryViewModel(); toolView.DataContext = toolViewModel; } else if (savedConfiguration != null) { toolViewModel.ApplyChanges(savedConfiguration); } // Sets map and proxy url based on application settings. if (MapApplication.Current != null) { toolViewModel.Map = MapApplication.Current.Map; if (MapApplication.Current.Urls != null) { toolViewModel.ProxyUrl = MapApplication.Current.Urls.ProxyUrl; } } // Updates default/selection on each query expression. toolViewModel.ResetExpressions(); // Sets the result layer name. toolViewModel.SetLayerNameAction = (layer, title) => { if (layer != null && !string.IsNullOrEmpty(title)) { var index = 1; string layerName = title; if (MapApplication.Current != null && MapApplication.Current.Map != null && MapApplication.Current.Map.Layers != null) { LayerCollection layers = MapApplication.Current.Map.Layers; while (layers.Any(l => MapApplication.GetLayerName(l) == layerName)) { index++; layerName = string.Format("{0} ({1})", title, index); } } MapApplication.SetLayerName(layer, layerName); } }; // Adds result layer to map. toolViewModel.AddLayerAction = (layer) => { if (layer != null) { if (MapApplication.Current.Map != null && MapApplication.Current.Map.Layers != null) { if (!MapApplication.Current.Map.Layers.Contains(layer)) { MapApplication.Current.Map.Layers.Add(layer); } } } }; // Removes result layer from map. toolViewModel.RemoveLayerAction = (layer) => { if (layer != null) { if (MapApplication.Current.Map != null && MapApplication.Current.Map.Layers != null) { if (MapApplication.Current.Map.Layers.Contains(layer)) { MapApplication.Current.Map.Layers.Remove(layer); } } } }; // Updates layer selection on map after query is executed. toolViewModel.SelectLayerAction = (layer) => { if (layer != null) { MapApplication.Current.SelectedLayer = layer; } }; // Zooms to result layer. toolViewModel.ZoomToExtentAction = (geometry) => { if (geometry != null) { var env = geometry.Extent; if (env.Width > 0 || env.Height > 0) { env = new Envelope(env.XMin - env.Width * EXPAND_EXTENT_RATIO, env.YMin - env.Height * EXPAND_EXTENT_RATIO, env.XMax + env.Width * EXPAND_EXTENT_RATIO, env.YMax + env.Height * EXPAND_EXTENT_RATIO); if (MapApplication.Current.Map != null) { MapApplication.Current.Map.ZoomTo(env); } } else { if (MapApplication.Current.Map != null) { MapApplication.Current.Map.PanTo(env); } } } }; // Updates visibility of data grid after query is expecuted. toolViewModel.UpdateDataGridVisibility = (visibility) => { UpdateFeatureDataGridVisibility(visibility); }; // Displays QueryToolView. MapApplication.Current.ShowWindow(toolViewModel.QueryTitle, toolView, false, null, (s, e) => { ToolExecuting = false; // Clears map of query results when done. toolViewModel.ClearResults(); foreach (ExpressionViewModel exp in toolViewModel.QueryExpressions) { exp.ClearValidationExceptions(); } }, WindowType.Floating); // Executes query on click when there are no visible expression. if (!toolViewModel.HasVisibleExpression) { if (toolViewModel.Execute.CanExecute(null)) { toolViewModel.Execute.Execute(null); } } }