Custom Rendering in Bing Silverlight Control - rendering

I'm ramping up on a Silverlight 2 project that leverages the Bing Maps control. One thing our UX guys are wondering is whether it is possible to customize the look of the map completely. For example, draw countries as simple outlines with different color interiors. Or draw the ocean as white and countries as black dotted shapes.
Does anyone know whether it is possible to achieve this level of customization? The MapMode class looked promising, but it doesn't seem to quite give me what I need.
Thanks,
Kent

To answer my own question, yes this is possible.
Firstly, add your own layer with a custom tile source:
<m:Map>
<m:Map.Mode>
<mCore:MercatorMode/>
</m:Map.Mode>
<m:Map.Children>
<m:MapTileLayer>
<m:MapTileLayer.TileSources>
<local:CustomTileSource/>
</m:MapTileLayer.TileSources>
</m:MapTileLayer>
</m:Map.Children>
</m:Map>
Next, define the CustomTileSource. Here is an example:
public class CustomTileSource : TileSource
{
public CustomTileSource()
: base(GetAbsoluteUrl("/ClientBin/Resources/{0}.png"))
{
}
public override Uri GetUri(int x, int y, int zoomLevel)
{
var quadKey = new QuadKey(x, y, zoomLevel);
return new Uri(String.Format(this.UriFormat, quadKey.Key));
}
public static string GetAbsoluteUrl(string strRelativePath)
{
if (string.IsNullOrEmpty(strRelativePath))
return strRelativePath;
string strFullUrl;
if (strRelativePath.StartsWith("http:", StringComparison.OrdinalIgnoreCase)
|| strRelativePath.StartsWith("https:", StringComparison.OrdinalIgnoreCase)
|| strRelativePath.StartsWith("file:", StringComparison.OrdinalIgnoreCase)
)
{
//already absolute
strFullUrl = strRelativePath;
}
else
{
//relative, need to convert to absolute
strFullUrl = System.Windows.Application.Current.Host.Source.AbsoluteUri;
if (strFullUrl.IndexOf("/ClientBin") > 0)
strFullUrl = strFullUrl.Substring(0, strFullUrl.IndexOf("/ClientBin")) + strRelativePath;
}
return strFullUrl;
}
}
Note how the tile source must return a URL. If you have an image you want to use as the map, you can use the MapCruncher tool to prepare it.

Related

How do I control the frequency of labels on LineDataSet?

In MPAndroidChart, I can control the frequency of xaxis values with setSkipLabels. However, this only affects the xaxis. How do I do the same with the lines themselves in a line chart?
I don't think the library provide a neat way to do this for LineDataSet as for X axis.
The best bet IMHO should be to use a custom ValueFormatter to set text to blank as required.
Exemple to show one label out of ten:
public class MyValueFormatter implements ValueFormatter {
private DecimalFormat mFormat;
public MyValueFormatter() {
mFormat = new DecimalFormat("###,###,##0.0"); // use one decimal
}
#Override
public String getFormattedValue(float value, Entry entry, int dataSetIndex, ViewPortHandler viewPortHandler) {
String output = "";
if (entry.getXIndex() % 10 == 0) output = mFormat.format(value);
return output;
}
}
Then, attach your formatter to your DataSet
lineDataSet.setValueFormatter(new MyValueFormatter());
This will only affect text displayed next to each value in the graph.
You could also disable drawing the circle on each value with :
lineDataSet.setDrawCircles(false);

Abstraction with variables

So I'm taking a highschool online Java class and well my teacher doesn't help...
so we are learning about abstraction and I had already done this with my "alien" class that moves, he will face one way going forward and another going backward by switching two images... However when they showed the code in an example it seemed overcomplicated and I was wondering if I am just missing something.
My Code
private String avatarRight = "Alien.png";
private String avatarLeft = "Alien1.png";
/**
* Act - do whatever the Alien wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
movement(avatarRight, avatarLeft);
gatherPart();
}
(Superclass containing movement method)
/**
* Sets up the movement keys and facing for the Object
*/
public void movement(String avatarRight,String avatarLeft)
{
if (atWorldEdge() == false)
{
if (Greenfoot.isKeyDown("w"))
{
setLocation(getX(), getY()-2);
}
if (Greenfoot.isKeyDown("d"))
{
setImage(avatarRight);
setLocation(getX()+2, getY());
}
if (Greenfoot.isKeyDown("s"))
{
setLocation(getX(), getY()+2);
}
if (Greenfoot.isKeyDown("a"))
{
setImage(avatarLeft);
setLocation(getX()-2, getY());
}
}
else
{
}
}
Their Code
{
private GreenfootImage image1;
private GreenfootImage image2;
private boolean isKeyDown;
private String key;
private String sound;
/**
* Create a Duke and initialize his two images. Link Duke to a specific keyboard
* key and sound.
*/
public Duke(String keyName, String soundFile)
{
key = keyName;
sound = soundFile
image1 = new GreenfootImage("Duke.png")
image3 = new GreenfootImage("duke2.png")
setImage(image1);
}
}
Where I just say avatarRight = "this image"
they say key = keyname
key = "key"
edit:
So the way the set it up and I set mine up initially was
private int rotation;
public Capsule(int rot)
{
rotation = rot
setRotation(rotation);
}
but the one below works perfectly fine, as far as I can tell. Is there any reason why I would do the above code rather than the one below
public Capsule(int rot)
{
setRotation(rot);
}
OK, based on the commentary I'm inclined to say you're not comparing the same things.
Where I just say avatarRight = "this image" they say key = keyname key
= "key"
That doesn't seem to be exactly accurate. Where you say
private String avatarRight = "Alien.png"; and
private String avatarLeft = "Alien1.png";
they have the png hard coded in the constructor as "Duke.png" and "duke2.png", which by the way contains an error because as far as I can see there's no image3.
So the keyName doesn't seem to directly map as you say it does. Perhaps you should investigate the code further to see how they use the key or provide equal code for both examples so we can further see the differences.
By looking at it perhaps there's a map somewhere and the key would be used to access the specific alien or other type of game object.
To address your edit.
Is there any reason why I would do the above code rather than the one
below
It's not possible to tell by that code if the reason has any value; it doesn't appear to by what you've shown. I can tell you that the reason I would do that is because I need that value elsewhere but not now. That could be for any number of reasons. You have to look at all the code available to you and see if they ever use that variable anywhere else without passing it in. Then you have found the reason or the lack there of.

Get all SmartForm items from Ektron 9 in a Taxonomy

I'm using Ektron CMS version 9.0
I have smart form content which is allocated to taxonomies e.g. I might have five smart form content items (all of same) type allocated to a taxonomy, and another three to a different taxonomy:
I need to get all content of a smart form type from a taxonomy:
public IEnumerable<T> GetListOfSmartFormFromTaxonomy<T>(long taxonomyId, bool isRecursive) where T : class
{
// TODO
}
What I have working, based on links below, is this:
public IEnumerable<TaxonomyItemData> GetListOfSmartFormFromTaxonomy(long taxonomyId)
{
TaxonomyItemCriteria criteria = new TaxonomyItemCriteria();
criteria.AddFilter(TaxonomyItemProperty.TaxonomyId, CriteriaFilterOperator.EqualTo, taxonomyId);
TaxonomyItemManager taxonomyItemManager = new TaxonomyItemManager();
List<TaxonomyItemData> taxonomyItemList = taxonomyItemManager.GetList(criteria);
return taxonomyItemList;
}
But this just gets the item's titles and ids, not the smart form data itself.
As an Ektron newbie, I don't know how to get all the items of one Smart Form type using only one call (instead of looping through each item and fetching it by ID which is not efficient)
What have I missed? I am working on this actively today and will post my findings here.
References used so far:
http://reference.ektron.com/developer/framework/Organization/TaxonomyItemManager/GetList.asp
Ektron taxonomy and library items (in v9)
EDIT
Posted my just-got-it-working solution below as an fyi and awarded closest answer as accepted. Thanks everyone for your help. Please chime in with any improvements ;)
I'd recommend using the ContentTaxonomyCriteria with the ContentManager.
long smartFormId = 42;
long taxonomyId = 127;
bool isRecursive = true;
var cm = new ContentManager();
var taxonomyCriteria = new ContentTaxonomyCriteria();
taxonomyCriteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartFormId);
taxonomyCriteria.AddFilter(taxonomyId, isRecursive);
var content = cm.GetList(taxonomyCriteria);
UPDATE
The ContentData object has a property called XmlConfiguration. When the content is based on a smartform, this property will be non-null and have a positive (non-zero) Id: content[0].XmlConfiguration.Id for example.
I often add an Extension Method to my code that will tell me whether a given ContentData is based on a smart form:
public static class ContentDataExtensions
{
public static bool IsSmartFormContent(this ContentData content)
{
return content != null && content.XmlConfiguration != null && content.XmlConfiguration.Id > 0;
}
}
That way I can take a content (or list of content) and check it very quickly in code to see if it's based on a smartform or not:
foreach (var contentData in contentList)
{
if (contentData.IsSmartFormContent())
{
// Do smart-form stuff here...
}
}
Of course, if your content is coming from the framework api and you used a criteria object that is selecting based on a specific XmlConfigurationId, then in theory you wouldn't have to use that, but it still comes in handy quite often.
I'm not quite sure I understand your organizational structure, but you do have the ability to do your own sub clauses that select directly against the database.
In this case I wouldn't use the TaxonomyItemManager, I would use the ContentManager with a special criteria:
ContentManager cApi = new ContentManager();
var criteria = new ContentCriteria();
criteria.AddFilter(ContentProperty.Id, CriteriaFilterOperator.InSubClause, "select taxonomy_item_id where taxonomy_id = " + taxonomyId);
criteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartformTypeId);
var yourContent = cApi.GetList(criteria);
That should do what you're asking for (grab the content specifically that is a member of a Taxonomy while only being of a specific SmartForm config). It's worth noting you don't need the second criteria piece (XmlConfigurationId) if your Taxonomy only contains that XmlConfiguration.
For Information, this is what I came up with. Noted Brian Oliver's comment on List but using patterns from other devs, can refactor later.
To clarify, we are creating classes from the XSDs generated from the smart forms, so have smart form types to play with. Your use may be simpler that ours.
public IEnumerable<T> GetListOfSmartFormFromTaxonomy<T>(long taxonomyId, bool isRecursive = false) where T : class
{
long smartFormId = GetSmartFormIdFromType(typeof(T));
// checks here for smartformid=0
ContentManager contentManager = new ContentManager();
ContentTaxonomyCriteria criteria = new ContentTaxonomyCriteria();
// Smart Form Type
criteria.AddFilter(ContentProperty.XmlConfigurationId, CriteriaFilterOperator.EqualTo, smartFormId);
// Taxonomy
criteria.AddFilter(taxonomyId, isRecursive);
List<ContentData> contentDataList = contentManager.GetList(criteria);
IEnumerable<T> smartFormList = ConvertToSmartFormList<T>(pressReleaseDataList);
return smartFormList;
}
private IEnumerable<T> ConvertToSmartFormList<T>(List<ContentData> contentDataList) where T : class
{
List<T> smartFormList = new List<T>();
if (contentDataList != null && contentDataList.Count > 0)
{
foreach (ContentData contentData in contentDataList)
{
if (contentData.IsSmartFormContent())
{
T smartForm = GetDeserializedContent<T>(contentData.Html);
if (smartForm != null)
{
PropertyInfo property = smartForm.GetType().GetProperty("ContentId");
if (property != null)
{
property.SetValue(smartForm, contentData.Id, null);
}
smartFormList.Add(smartForm);
}
}
}
}
return smartFormList;
}
private long GetSmartFormIdFromType(Type smartFormType)
{
SmartFormConfigurationManager manager = new SmartFormConfigurationManager();
SmartFormConfigurationCriteria criteria = new SmartFormConfigurationCriteria();
// Note: Smart Form Title must match the type's name, i.e. no spaces, for this to work
criteria.AddFilter(SmartFormConfigurationProperty.Title, CriteriaFilterOperator.EqualTo, smartFormType.Name);
List<SmartFormConfigurationData> configurationData = manager.GetList(criteria);
if (configurationData == null || configurationData.Count == 0)
{
return 0;
}
return configurationData.First().Id;
}

How to update tile created by other app?

I have two app: one UI to create a tile with Create(), the other agent to update the tile with Update(). The 2 functions worked well in one app, ie. both in UI or both in agent. But if I put Create in UI and Update() in agent, Update() can not find the tile created by Create(). What's wrong? Thanks.
private void Create()
{
ShellTile find = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("ID=shelltile"));
StandardTileData date = new StandardTileData();
date.Count = 10;
if (find == null)
{
ShellTile.Create(new Uri("/MainPage.xaml?ID=shelltile", UriKind.Relative), date);
}
}
private void Update()
{
ShellTile find = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("ID=shelltile"));
if (find != null)
{
StandardTileData date = new StandardTileData();
date.Title = "aaaaaaaaa";
find.Update(date);
}
}
Each app can only access its own tiles. If you want to update the tiles, you'll need to make a background agent in the same app. (note that a background agent can't create tiles, which leads me to believe this isn't what you're doing now)

How to give the option to change the Textbloack foreground-color,size in Windowsphone7

I am completely new in Windowsphone7.i have develop sample application in that i want give the option to change the font-color,Size,style(Italic/Bold) as Dynamically(like RadEditor) .please help me how to resolve this option.
If you Develop your Application MVVM style then it is not so hard to do this. You just need a property for every setting you want to set dynamically and then bind to this properties. And you create a Settings View where you can set the properties and if you change them you use INotifyPropertyChanged to broadcast that your properties value changed and so every control which is bound to that property will change and redraw.
GalaSoft MVVM
MVVM Codeplex
Easy MVVM sample Application for Windows Phone 7
The link you found to save an image looks ok, but i did it a bit different, actually from the CameraCaptureTask you already get a WritableBitmap Image and you can save it like this.
To save the Image:
private void SaveToIsolatedStorage(WriteableBitmap image, string fileName)
{
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (myIsolatedStorage.FileExists(fileName))
{
myIsolatedStorage.DeleteFile(fileName);
}
using (var stream = myIsolatedStorage.OpenFile(fileName, FileMode.Create))
{
Extensions.SaveJpeg(image, stream, image.PixelWidth, image.PixelHeight,0, 100);
}
}
}
To read the Image:
private WritableBitmap ReadFromIsolatedStorage(string fileName)
{
WriteableBitmap bitmap = new WriteableBitmap(200,200);
using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (store.FileExists(fileName))
{
using (var stream = store.OpenFile(fileName,FileMode.Open))
{
bitmap.SetSource(stream);
}}
}
return bitmap;
}
I hope this will work because i wrote it from scratch. :)
And in your ViewModel you should have a WritableBitmap Property which is bound to your Image Control on your View.
To use a lot of images and work with them you should read a bit more about this, because somehow SL Images use a lot of memory so you will need to address this problem somehow in the future.