POST
|
Thanks for the reply Brian. Here's another example. I have a collection of business objects I want to put on a GraphicsLayer. Properties of those objects should determine the image of the Graphic and the text shown. In WPF I had a MarkerSymbol ControlTemplate for a GraphicsLayer that bound to the attributes of the graphic. <esri:MarkerSymbol x:Key="unitPlotSymbol">
<esri:MarkerSymbol.ControlTemplate>
<ControlTemplate>
<Border BorderBrush="DarkGray" BorderThickness="1">
<Grid Margin="0,0,0,0" HorizontalAlignment="Center" VerticalAlignment="Bottom">
<Image x:Name="unitPlotImage" Source="{Binding Attributes[IMAGE]}" Stretch="None"></Image>
<TextBlock FontSize="14" Foreground="Black" FontWeight="Bold" Text="{Binding Attributes[LABEL]}" HorizontalAlignment="Center" />
</Grid>
</Border>
</ControlTemplate>
</esri:MarkerSymbol.ControlTemplate>
</esri:MarkerSymbol> It's nice, I just created the Graphics with the proper Attributes and added them to the layer. The correct image and label were applied. I don't see how this is doable in Runtime for .NET. since TextSymbols cannot bind. Now, I need to build each graphic programmatically in the ViewModel like so: foreach (CADws.UnitInfo u in units)
{
Graphic g = new Graphic();
g.Geometry = new MapPoint(u.WebMercLon, u.WebMercLat, new SpatialReference(Constants.WEB_MERC_SPATIAL_REF));
CompositeSymbol cs = new CompositeSymbol();
PictureMarkerSymbol ps = new PictureMarkerSymbol();
ps.SetSource(System.IO.File.ReadAllBytes(@"C:\GIS\Resources\" + DetermineApproriateSymbol(u)));
TextSymbol ts = new TextSymbol();
ts.Color = Colors.Black;
ts.Text = u.UnitNum;
ts.XOffset = -14;
ts.YOffset = 0;
ts.Font.FontWeight = SymbolFontWeight.Bold;
ts.Font.FontSize = 16;
cs.Symbols.Add(ps);
cs.Symbols.Add(ts);
g.Symbol = cs;
g.Attributes["LABEL"] = u.UnitNum;
if (u.Type != "P") {
g.Attributes["DETAILS1"] = String.Format("{0} {1}", u.UnitNum, GetNiceStatus(u.Status));
g.Attributes["DETAILS2"] = u.CallInfo;
g.Attributes["DETAILS3"] = u.KnownLocation;
g.Attributes["DETAILS4"] = "";
}
else
{
g.Attributes["DETAILS1"] = String.Format("{0} {1} Radio:{2}", u.UnitNum,GetNiceStatus(u.Status),u.TalkGroup);
g.Attributes["DETAILS2"] = u.CallInfo;
g.Attributes["DETAILS3"] = u.KnownLocation;
g.Attributes["DETAILS4"] = u.OfficerInfo;
}
graphics.Add(g);
} Then add that collection to my GraphicsLayer. (Initially I thought I'd just expose a ObservableCollection of Graphics from the ViewModel that the GraphicsLayer could bind to, but the elements in the MapView don't inherit it's DataContext and setting it for every element in the map programmatically seemed like a poor design.) So clearly I'm violating MVVM above. The ViewModel here is dictating how the View looks. How else can this be done?
... View more
03-18-2015
05:29 AM
|
1
|
0
|
538
|
BLOG
|
It does complicate things a little. I'm looking through the linked code and it seems to be fairly complex for just some basic map functionality. I'm failing to see the benefits of the MVVM approach. It seems like there are a number or workarounds like this trying to fit a square peg in a round whole.
... View more
03-09-2015
08:44 AM
|
0
|
0
|
1701
|
POST
|
I'm revamping some WPF Runtime apps to the new .NET API - Desktop. I've started to use the MVVM pattern but there seems to be some missing features. The first is that: "objects inside the MapView control are not in the page's control hierarchy and, therefore, cannot be referenced from the page." So the DataContext for the MapView isn't available down the control hierarchy? So in order to bind data to a map overlay I need to pass in the MapView object to the ViewModel and bind it programatically like so: var tip = _mapView.FindName("mapTip") as System.Windows.FrameworkElement;
tip.DataContext = graphic; Doesn't this negate one of the major benefits to MVVM data-binding? Similarly, symbols can't use data-binding? For example I want a TextSymbol's text to be a Graphic attribute named LABEL. I cannot do something like: <esri:TextSymbol Text="{Binding Attributes[LABEL]}" ... Finally, the examples all use code-behind pages and events, but it seems we're encouraged to use MVVM. So I guess my question is are enterprise-class applications really possible with the .NET API using MVVM? Caveat: I'm relatively new to MVVM, but an having a hard time seeing how all this is going to work.
... View more
03-09-2015
08:13 AM
|
0
|
3
|
4284
|
POST
|
I receive "Unable to complete operation., Unable to find attribute . Invalid context." when calling the NA servers' Route. Here is the code that I'm using to call the service
RouteTask routeTask = new RouteTask("http://{ourInternalServer}/arcgis/rest/services/wm_Closest_Facility/NAServer/Route");
// create the stop collection
GraphicsLayer startEndPoints = new GraphicsLayer();
Graphic testG = new Graphic();
testG.Geometry = new MapPoint(-8639323.8133,4529937.4133, new SpatialReference(WEB_MERC_SPATIAL_REF));
testG.Symbol =LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
startEndPoints.Graphics.Add(testG);
Graphic endG = new Graphic()
{
Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
Geometry = endPoint
};
startEndPoints.Graphics.Add(endG);
RouteParameters routeParameters = new RouteParameters()
{
Stops = startEndPoints,
ReturnDirections = true,
OutSpatialReference = new SpatialReference(WEB_MERC_SPATIAL_REF),
};
routeTask.Failed += (source, args) =>
{
string errorMessage = "";
try
{
errorMessage += args.Error.Message;
foreach (string detail in (args.Error as ServiceException).Details)
{
errorMessage += "," + detail;
}
}
catch (Exception e)
{
errorMessage += ", no details.";
}
tbInfo.Text = "Route failed: " + errorMessage;
CloseSidebar();
};
routeTask.SolveCompleted += (source, args) =>
{
// Get the route and apply a symbol to it
--never gets here
the endPoint is a valid MapPoint that was just plotted on the map. I'm using Runtime 10.1.1 and calling a 10.1 service. Any ideas? Or how to track down this error?
... View more
03-26-2013
05:33 AM
|
0
|
3
|
2259
|
Title | Kudos | Posted |
---|---|---|
1 | 03-18-2015 05:29 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|