POST
|
Hi Jennifer, What I was missing is in this line: await feature.AddAttachmentAsync("test.png", "image/png", bytes); I put "image/" instead of "image/png", which is what breaks things. Thank you! Best, Yifan
... View more
08-07-2017
10:43 AM
|
0
|
0
|
1099
|
POST
|
Thanks for the reply Nagma. I am developing for Android and the API is different from WPF. So, unfortunately, your suggestion would not work. Still appreciate it!
... View more
08-02-2017
04:14 PM
|
1
|
0
|
1099
|
POST
|
Hi, I am adding an attachment to a feature on the feature service. My issue is I am able to add the attachment to the feature, but I am not sure how to push the attachment to the feature service. Here is what I did: private async void save() {
await feature.LoadAsync();
// bytes is the byte array containing data of the file
var result = await feature.AddAttachmentAsync(App._file.Name, @"image/", bytes);
ServiceFeatureTable sft = feature.FeatureTable as ServiceFeatureTable;
await sft.UpdateFeatureAsync(feature);
await sft.ApplyEditsAsync();
} Debugging shows that feature.AddAttachmentAsync() works as expected. After that line, I tried feature.GetAttachmentAsync() and it returns the just added attachment. However, I was not able to sync the attachment to the feature service. That feature service has attachment enabled. Am I missing any steps here? Appreciate any help. Best Yifan
... View more
08-02-2017
02:47 PM
|
0
|
4
|
1890
|
POST
|
Hi, I encountered a strange issue with pulling data from the feature service. The problem is that a feature pulled from a feature service loses some of the fields that was in its feature table. What I am doing is I pulled a feature layer hosted on the portal and queried the feature layer. The result feature, however, only contains a portion of the fields that are in its feature table. Here I first created a feature layer from a service feature table. string url = "*******/FeatureServer/0";
Uri uri = new Uri(url);
ServiceFeatureTable sft = new ServiceFeatureTable(uri);
_mapViewModel.fireExLayer = new FeatureLayer(sft); Then I query the feature layer and get the Selectedfeature. (I removed error checking code here) var queryParams = convertTapToQuery(e.Location.X, e.Location.Y, 1);
var result = await _mapViewModel.fireExLayer.SelectFeaturesAsync(queryParams, SelectionMode.New);
_mapViewModel.SelectedFeature = result.ToList()[0]; At last, I try to get the attributes of the SelectedFeature by doing this: As seen in the screenshot, for each field in the feature table of a feature, I tried to get the attribute value of that field, but this triggers an exception, whose message says “the given key was not present in the dictionary.” I was bewildered seeing the field from a feature’s own feature table is not a key in the feature’s attribute dictionary. What am I doing wrong here? Appreciate any help and thoughts! Best, Yifan
... View more
07-31-2017
04:06 PM
|
0
|
2
|
1647
|
POST
|
Could you elaborate how to query group content? GetGroupsAsync does not seem to provide a way to query the content in a group.
... View more
07-11-2017
09:43 AM
|
0
|
2
|
922
|
POST
|
The PortalGroup class, which can be accessed through getGroupsAsync, does not provide a way to see the content in the group. But thanks still Nagma!
... View more
07-11-2017
09:39 AM
|
0
|
0
|
922
|
POST
|
I need to access a secured feature layer that belongs to my group. I have implemented the OAuth login and am able to access my own content. However, I cannot seem to be able to find a way to reach into my groups content list. Anyone has any suggestions? Thanks!
... View more
07-10-2017
01:53 PM
|
0
|
6
|
1287
|
POST
|
After researching on the await and async programming of C#, I realized my problem was because of a deadlock. setting the configureAwait(false) avoids the deadlock by allowing the MobileMapPackage.openAsync to pick up an idle thread from the threadpool instead of waiting for the UI SynchronizationContext. See the quote below on this issue: The root cause of this deadlock is due to the way await handles contexts. By default, when an incomplete Task is awaited, the current “context” is captured and used to resume the method when the Task completes. This “context” is the current SynchronizationContext unless it’s null, in which case it’s the current TaskScheduler. GUI and ASP.NET applications have a SynchronizationContext that permits only one chunk of code to run at a time. When the await completes, it attempts to execute the remainder of the async method within the captured context. But that context already has a thread in it, which is (synchronously) waiting for the async method to complete. They’re each waiting for the other, causing a deadlock. Link is here: Async/Await - Best Practices in Asynchronous Programming
... View more
07-05-2017
04:19 PM
|
0
|
0
|
1060
|
POST
|
Thanks a lot @Greg DeStigter the mmpk file works. I've been trying different things and found out that adding ConfigureAwait(false) to the OpenAsync(mmpkPath) fixes this issue. See my new code below, note the change on line 26: I am still researching why I have to add ConfigureAwait here. If you know the reason, can you please share it here?
private async Task<MobileMapPackage> OpenMmpkAsync()
{
try
{
//string filePath = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "map.mmpk");
//MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(filePath);
//var mmpk = await MobileMapPackage.OpenAsync(Path.Combine(DownloadViewModel.GetDataFolder(), AppSettings.CurrentSettings.PortalItemName));
var mmpkName = "map.mmpk";
AssetManager assestManager = this.Assets;
// Open the map package asset
using (var packageAsset = Assets.Open(mmpkName))
{
// Copy it to a writable location
using (var packageTarget = OpenFileOutput(mmpkName, FileCreationMode.WorldWriteable))
{
packageAsset.CopyTo(packageTarget);
}
}
var mmpkPath = GetFileStreamPath(mmpkName).AbsolutePath;
return await MobileMapPackage.OpenAsync(mmpkPath).ConfigureAwait(false);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
return null;
}
}
Greg DeStigter wrote: Yifan Liu I'm using your code almost exactly in an Android test app that I have and it seems to be working as I expect. Perhaps it's related to your MMPK file. Could you try another and see if it works? Here's the bulk of my test code for reference: [Activity(Label = "LocalData.Droid", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override async void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var mmpk = await OpenMmpkAsync();
SetContentView(new MapView() { Map = mmpk.Maps.FirstOrDefault() });
}
private async Task<MobileMapPackage> OpenMmpkAsync()
{
try
{
var mmpkName = "multiplemaps.mmpk";
using (var mmpkAsset = Assets.Open(mmpkName))
using (var mmpkTarget = OpenFileOutput(mmpkName, FileCreationMode.WorldWriteable))
{
mmpkAsset.CopyTo(mmpkTarget);
}
var mmpkPath = GetFileStreamPath(mmpkName).AbsolutePath;
return await MobileMapPackage.OpenAsync(mmpkPath);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex);
return null;
}
}
}
... View more
07-05-2017
03:00 PM
|
0
|
0
|
1060
|
POST
|
Hi, I am developing a Xamarin app for Android using the arcGIS .NET for Android SDK. I am trying to load a mobile map package with this method shown below. My problem is that on line 19, the OpenAsync never return and the await never yield the control to the caller of this LoadMMPK() method. My application gets stuck here. A bit of explanation of the code: The mobile map package is in the Asset folder of my Android project, which gets copied to the android device (line 6 to 16). Then I call the OpenAsync on line 19 to load the mmpk. I checked the Android device, the map package was successfully written into the device, and the mmpkPath passed into the OpenAsync method is valid and points to the right mobile map package. Anyone can help me point out what might be the cause of my issue here? Thank you private async Task<MobileMapPackage> LoadMMPK()
{
try
{
var mmpkName = "map.mmpk";
AssetManager assestManager = this.Assets;
// Open the map package asset
using (var packageAsset = Assets.Open(mmpkName))
{
// Copy it to a writable location
using (var packageTarget = OpenFileOutput(mmpkName, FileCreationMode.WorldWriteable))
{
packageAsset.CopyTo(packageTarget);
}
}
var mmpkPath = GetFileStreamPath(mmpkName).AbsolutePath;
MobileMapPackage mmpk = await MobileMapPackage.OpenAsync(mmpkPath);
return mmpk;
}
catch (FileNotFoundException ex)
{
Console.Write(ex.Message);
return null;
}
}
... View more
07-03-2017
11:26 AM
|
0
|
4
|
1868
|
Title | Kudos | Posted |
---|---|---|
1 | 08-02-2017 04:14 PM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|