user2303963
user2303963

Reputation: 31

GART Augmented Reality issue

I'm working with windows phone 8 apps and want to add augmented reality feature and I'm using GART, but I experiencing the same issue in there and even there is a solution by Igor Ralic by adding canvas.zindex to 1, I'm still experiencing the same issue (the items in world view flicker and disappear), so maybe there is anybody in here that having much better solution? I'm using mvvm patern to work with this AR

Here is my approach with mvvm

This is my mainviewmodel

private ObservableCollection<ARItem> _ardisplayLocation = null;
public ObservableCollection<ARItem> ardisplayLocation
{
    get { return _ardisplayLocation; }
    set { this.SetProperty(ref this._ardisplayLocation, value); }
}

private void UpdateTransport()
    {
        try
        {
            myMessage = "Loading web server data...";
            WebClient client = new WebClient();
            Uri uri = new Uri(transportURL1 + latitude + "%2C" + longitude + transportURL2, UriKind.Absolute);
            client.DownloadStringCompleted += (s, e) =>
            {
                MainPage mainpage = new MainPage();
                mainpage.RefreshButton();
                if (e.Error == null)
                {
                    RootObject result = JsonConvert.DeserializeObject<RootObject>(e.Result);
                    hereRestProperty = new ObservableCollection<Item>(result.results.items);

                    for (int i = 0; i < hereRestProperty.Count; i++)
                    {
                        ardisplayLocation.Add(new CityPlace()
                        {
                             GeoLocation = new GeoCoordinate(hereRestProperty[i].coordinate.Latitude,hereRestProperty[i].coordinate.Longitude),
                             Content = hereRestProperty[i].title,
                             Description = hereRestProperty[i].vicinity
                        });
                    }
                }
                else
                {
                    isFailed = Visibility.Visible;
                    myMessage = "Failed to load web server data, please refresh";
                }
                isBusy = false;
            };
            client.DownloadStringAsync(uri);
        }
        catch (Exception)
        {
            isBusy = false;
            isFailed = Visibility.Visible;
            myMessage = "Something wrong happen, please refresh";
        }
    }

and here is my ArDisplay.xaml.cs

private MainViewModel mvm { get { return this.DataContext as MainViewModel; } }

public ArDisplay()
{
    InitializeComponent();
    DataContext = App.ViewModel;
}

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    ardisplay.StartServices();
    ardisplay.ARItems = mvm.ardisplayLocation;
    base.OnNavigatedTo(e);
}

protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
    ardisplay.StopServices();
    base.OnNavigatedFrom(e);
}

and my xaml

<gart:ARDisplay Name="ardisplay" AttitudeRefreshRate="50" MovementThreshold="10">
    <gart:VideoPreview x:Name="videoPreview" Canvas.ZIndex="1"/>
    <gart:WorldView x:Name="worldView" Canvas.ZIndex="1" ItemTemplate="{StaticResource CityItemTemplate}"  MinItemScale="0.1" MaxItemScale="1.0" FarClippingPlane="300.0" NearClippingPlane="1.0"/>
    <gart:HeadingIndicator x:Name="headingIndicator" Canvas.ZIndex="1" Width="300" Height="300" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</gart:ARDisplay>

and my data template

<DataTemplate x:Key="CityItemTemplate">
    <Border BorderBrush="Black" BorderThickness="4" CornerRadius="8" Background="#FF003847" Width="320">
        <StackPanel Margin="4">
            <TextBlock x:Name="NameBlock" TextWrapping="NoWrap" Text="{Binding Content}" FontSize="38" VerticalAlignment="Center" Margin="0,0,4,0"  Grid.Column="1" TextTrimming="WordEllipsis"/>
            <TextBlock x:Name="DescriptionBlock" TextWrapping="Wrap" Text="{Binding Description}" FontSize="24" VerticalAlignment="Center" Margin="0,0,4,0" Grid.Column="1" TextTrimming="WordEllipsis" MaxHeight="168"/>
        </StackPanel>
    </Border>
</DataTemplate>

Upvotes: 0

Views: 243

Answers (1)

ttu
ttu

Reputation: 351

Canvas.ZIndex was missing from your DataTemplate

<DataTemplate x:Key="CityItemTemplate">
    <Border BorderBrush="Black" BorderThickness="4" CornerRadius="8" Background="#FF003847" Width="320" Canvas.ZIndex="2">
        <StackPanel Margin="4">
            <TextBlock x:Name="NameBlock" TextWrapping="NoWrap" Text="{Binding Content}" FontSize="38" VerticalAlignment="Center" Margin="0,0,4,0"  Grid.Column="1" TextTrimming="WordEllipsis"/>
            <TextBlock x:Name="DescriptionBlock" TextWrapping="Wrap" Text="{Binding Description}" FontSize="24" VerticalAlignment="Center" Margin="0,0,4,0" Grid.Column="1" TextTrimming="WordEllipsis" MaxHeight="168"/>
        </StackPanel>
    </Border>
</DataTemplate>

Upvotes: 1

Related Questions