Windows Phone 7 Map Control with custom layer in offline mode - windows-phone-7

Hi WP7 mobile passionate developers!
I'm trying to use the default provided Bing Map control from Windows Phone controls.
Specifically I'm trying to use a custom TileSource to provide a custom made tiled map that will be stored in the project as a folder (Content files) or in isolate storage.
Down I present the custom class I try to use with map tiles/images stored in "map" folder in ZXY storage format as content files.
public class CustomTileSource : Microsoft.Phone.Controls.Maps.TileSource
{
private string uriFormat = #"map/{0}/{1}/{2}.png";
public string UriFormat
{
get { return uriFormat; }
set { uriFormat = value; }
}
public override Uri GetUri(int x, int y, int zoomLevel)
{
var url = string.Format(UriFormat, zoomLevel, x, y);
return new Uri(url, UriKind.Relative);
}
}
Trying to use this is not working and custom tiles are not shown although no error is thrown.
Does anyone tried to use windows phone map control this way?
If that's not the right approach which one is? Any workaround?
Thank you in advance!
Claudiu

Have you set the Build Action on your image(s) to Content?

The Exception is:
This operation is not supported on a relative URI.
at System.Uri.get_AbsoluteUri()
at System.Windows.Media.MultiScaleTileSource.GetTileLayerUrl(IntPtr nativeTarget, Int32 tileLevel, Int32 tileX, Int32 tileY, Int32 uTileImageIndex, IntPtr& fullTileUri, UInt32& fullTileUriLength)
How to get an image from IsolatedStorage, Ressource or MediaLibrary with UriKind.Absolute i not already found out
...maybe you know?

This seems to be quite a FAQ problem - Map Tile Caching for Offline Viewing - shame there isn't an FAQ solution :/

Did you try constructing an absolute file url using the app id as described in this question? Map Tile Caching for Offline Viewing

I tried,
Did you try constructing an absolute file url using the app id as described in this question? Map Tile Caching for Offline Viewing
Map component is not showing me images, but simple
Image.Source = new BitmapImage(new Uri("file:///Applications/Install/0277CC52-888B-4593-A28D-4CFF818E81E7/Install/maps/-1040122162.jpg", UriKind.Absolute));
Is showing image...

You can find a solution in the blog http://invokeit.wordpress.com/2012/06/30/bing-mapcontrol-offline-tiles-solution-wpdev-wp7dev/
In general, you just need
Override GetUri function in TileSource class: return null to let MapLayerTile ignore this tile, and save the tile information to some background worker
In the background worker, loading the tile from anywhere, either isolation storage or network, and then manually add it to a MapLayer control.

Related

Uploading an image on a button click in XMAL

Why this does not load the image?
private void OnButtonClickedLoadImage(object sender, EventArgs e)
{
ImageSource imgSrc =
ImageSource.FromFile("C:\\MyApp\\MyPicture.png");
ImageViewerc.Source = imgSrc;
}
If you want to load local images, in Android, Place images in the Resources/drawable directory with Build Action: AndroidResource. In ios, The preferred way to manage and support images since iOS 9 is to use Asset Catalog Image Sets. Then use Asset Catalog Image Sets. The picture name can get the picture.
Thank you all (including Jason) for your help. Based on everyone's comment above, I corrected my code to properly load my image like this:
ImageSource imgSrc = ImageSource.FromResource("MyApp.pic2.png", typeof(ImageResourceExtension).GetTypeInfo().Assembly);
ImageViewerc.Source = imgSrc;
The image must be accessed like this: AppName.ImageFileName.ext (I was missing the AppName
Also I should note that the character case between the actual file name in Solution Explorer and the code-behind MUST MATCH or image won't load.

How to retrieve an image from WP7 photo library?

I'm developing an application where the user can add photos from windows phone 7 photo library and assign them to a particular view. To do this I save the OriginalFileName on the database (LINQ to SQL). Later I want to recover the photo and load it into the view. Do you know what I can do? currently I have this code but does not work.
When the user has selected the picture I keep his name in the variable fileName:
private void photoChooserTask_Completed (object sender, PhotoResult e)
{
BitmapImage image = new BitmapImage ();
e.OriginalFileName = fileName;
image.SetSource (e.ChosenPhoto);
this.Thumbnail.Source = image;
this.Thumbnail.Stretch = Stretch.UniformToFill;
}
Later, when the user wants to save this setting I save the fileName in database.
This is the code when I load the view that must contain the photo.
imgSource var = new BitmapImage (new Uri (picture.Url, UriKind.Absolute));
item.LeftImage.Source = imgSource;
Where picture.Url contains the filename.
Any idea? I saw on the internet that you can keep the whole image, but give it the best possible.
What you should do is save the picture returned from the PhotoChooserTask in the IsolatedStorage.
You will then be able to load it when needed.
Here is how to Read and Save Images.
For what you need is to get the picture by browsing the MediaLibrary without using PhotoChooserTask, because as you experienced, the file name might not be the same if you use different methods.
For the custom MediaLibrary browsing interface, you could refer to this codeplex project:
https://multiphotochooser.codeplex.com/

How to use System.Drawing.Image in RDLC Image Control?

Is it possible to use System.Drawing.Image in an RDLC Image Control?
All I have been reading were 3 methods:
database
embeded resource
external file
Thank you thank you.
EDIT:
Following up from this .NET or C# library for CGM (Computer Graphics Metafile) format? I now got the image in System.Drawing.Image format and want to display it as part of the report (as an image) --- that's what I want to do.
Not sure if this is what you are looking for, but if you have an image in code and you want to show it in the report, create a wrapper object that has a property that returns the image as a byte array and give then an instance of this wrapper-class with the valid image to the report as a ReportDataSource.
Something like:
ReportDataSource logoDataSource = new ReportDataSource();
logoDataSource.Name = "LogoDS";
logoDataSource.Value = new List<LogoWrapper>() { yourLogoWrapper };
localReport.DataSources.Add(logoDS);
In the report you then you can the image as it were from the database
=First(Fields!LogoByteArrayProperty.Value, "LogoDS")
The wrapper looks something like:
class LogoWrapper{
...
public byte[] LogoByteArrayProperty{
get{
// Return here the image data
}
}
}
I use this quite often. It has the advantage that I don't have to add the image to the db or add it as a resource of every report. And furthermore, the app can say which image should be used.
Please note, the given image format must be known from the rdlc-engine.
The last question would be, how to convert a system.drawing.image to a byte array. I work with WPF and therefore, I dont known. But I'm sure google will respond to this question very reliable.
You Can use the 'Database' Source Option along with Parameters to Dynamically set Image Source from Byte Arrays.
Code Behind:
var param2 = new ReportParameter()
{
Name = "CompanyLogo",
Values = { Convert.ToBase64String(*ByteArrayImageObject*) }
};
ReportViewer1.LocalReport.SetParameters(param2);
rdlc File:
1- Add Text Parameters 'CompanyLogo' and 'MIMEType'
2- Set the Value Property of the Image to =System.Convert.FromBase64String(Parameters!CompanyLogo.Value)
3- Set MIME Type Property to
=Parameters!MIMEType.Value
4- Use 'Database' As Source
How can I render a PNG image (as a memory stream) onto a .NET ReportViewer report surface
i am not quite sure what do you want to do with this but in general it is not possible.Image Control is just a image holder in the RDLC files.These 3 options specify the location from where the image control takes the image which to display from- database, embeded resource or external file. If you give me more info on what do you want to achieve i can give you some kind of solution.
Best Regards,
Iordan

WP7: Pass parameter to new page?

In a Windows Phone 7 Silverlight application I call a new page using
NavigationService.Navigate(new Uri("/View/SecondPage.xaml", UriKind.Relative));
Now I want to pass parameters to the new page. I understand a simple parameter can be passed using:
NavigationService.Navigate(new Uri("/View/TilgungsratePage.xaml?id=4711", UriKind.Relative));
and read in the new page using
protected override void OnNavigatedTo(Microsoft.Phone.Navigation.PhoneNavigationEventArgs e)
{
base.OnNavigatedTo(e);
String id = NavigationContext.QueryString["id"];
}
For simple parameters this is ok, but how do I pass a list?
Complex objects?
Anything but simple values?
In his book "Programming Windows Phone 7" (chapter 6, section 3, "Sharing Data Among Pages") Charles Petzold recommends properties in the App class (derived from Application). Every page has access to it via Application.Current. Also interesting is the dictionary PhoneApplicationService.Current.State. It's usefull for tombstoning. The whole chapter maybe interesting for reading.
You should also look at MVVM pattern and the messenger class.
Here's some references:
MVVM Overview
MVVM Foundation Messenger
Good SO question on the messenger from MVVM Light
MVVM Light Blog
take a look how I've implemented navigation in PhoneCore Framework: A framework for building of WP7 application. Shortly, I've built my navigation service on top of WP7 navigation. It uses custom page mapping and allows to pass custom parameters to view model automatically.
Use global variables, make a new class for GlobalVariables:
public static class GlobalVariables
{
public static string my_string = "";
public static int my_int = -1;
}
Then you can access the Global Variables class for different pages:
GlobalVariables.variable_name;
You should save the object to IsolatedStorage.
Just Serialize it with Json.net library and save the string to IsolatedStorage. On the next page get the string from IsolatedStorage and convert it back to the object you want with the json.net library!

QueryString Concept in Windows phone 7 developement?

I am using Silverlight to develop a Windows Phone 7 application. My requirement is when clicking on 1 image then it can be displayed in next page and zoomin that image automatically in that page. In the same way by clicking on another images same approach has to be occur. Give Detail explanation and Code For that One i'm new in windows phone application developer.
There are several ways to achieve this, but perhaps the simplest way is to use the Navigate method.
When the user clicks on your first image, grab the "id" of that image (or url, or whatever you need to pass to the second page), and add it to the navigation string like this:
NavigationService.Navigate(
new Uri(string.Format("/MyNewPage.xaml?image={0}",myImageID), UriKind.Relative));
Then on the destination page, you can extract that item from the navigation string in the OnNavigatedTo handler:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
myImageID = int.Parse(NavigationContext.QueryString["imageID"]);
}
Like I say, this is a very simplistic approach, and you can implement something much nicer with databinding, but it will do the trick.

Resources