﻿function ClearMarkers()
{
/// <summary>
/// Remove ALL markers from Xaml
/// </summary>
	var plugin = document.getElementById("SilverlightControl");
    var sl8 = document.getElementById("SilverlightControl");
    var markerCanvas = sl8.content.findName("canvasMarkers");
    markerCanvas.children.clear();
    added = false;
}


function dotXaml (name, x, y)
{
    return '<Ellipse xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RenderTransformOrigin="0.5,0.5" Fill="#FF00FF00" Stroke="#FF00FF00" x:Name="'+name+'" Width="11" Height="11" Canvas.Left="'+x+'" Canvas.Top="'+y+'" />';
}

function flagXaml (name, x, y)
{
   return '<Path  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RenderTransformOrigin="1,1" '
        +' Canvas.Left="'+x+'" Canvas.Top="'+y+'" Fill="#88FF0000" Stretch="Fill" Stroke="#88FF0000" '
		+' x:Name="'+name+'" Width="20.64" Height="20" '
		+' Data="M272,331 L258,307 C258,307 251,320 251,320 260.31452,322.61644 259.6371,313.90411 259.6371,313.90411 267.08871,324.9178 270.64516,331.65753 270.64516,331.65753 272.67742,330.34246 272,331 272,331 z" '
		+' />';
}

function flagNameXaml (name, x, y)
{
      return '<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="'+(x-21)+'" Canvas.Top="'+(y-21)+'" x:Name="'+name+'" Opacity="1.0">'
        +' <Path  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RenderTransformOrigin="1,1" '
        +' Fill="#880000FF" Stretch="Fill" Stroke="#880000FF" '
		+' Width="20.64" Height="20" '
		+' Data="M272,331 L258,307 C258,307 251,320 251,320 260.31452,322.61644 259.6371,313.90411 259.6371,313.90411 267.08871,324.9178 270.64516,331.65753 270.64516,331.65753 272.67742,330.34246 272,331 272,331 z" '
		+' />'
		+' <TextBlock Canvas.Left="20" Width="16" Height="20" Text="'+name+'" FontSize="11" Foreground="#FF0000FF" />'
		+' </Canvas>';
}

function flagImageXaml (name, x, y, url)
{
      return '<Canvas xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="'+(x-21)+'" Canvas.Top="'+(y-21)+'" x:Name="'+name+'" Opacity="1.0">'
        /*+' <Image Canvas.Left="0" Canvas.Top="0" Width="50" Height="50" Source="http://www.solarviews.com/thumb/mars/marsatmo.jpg" />'
        */+' <Path  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RenderTransformOrigin="1,1" '
        +' Fill="#880000FF" Stretch="Fill" Stroke="#880000FF" '
		+' Width="20.64" Height="20" '
		+' Data="M272,331 L258,307 C258,307 251,320 251,320 260.31452,322.61644 259.6371,313.90411 259.6371,313.90411 267.08871,324.9178 270.64516,331.65753 270.64516,331.65753 272.67742,330.34246 272,331 272,331 z" '
		+' />'
		+' <TextBlock Canvas.Left="20" Width="16" Height="20" Text="'+name+'" FontSize="11" Foreground="#FF0000FF" />'
		+' </Canvas>';
}

function drawFlag (name, x, y)
{
	var plugin = document.getElementById("SilverlightControl");
    var canvas = plugin.content.findName("canvasMarkers");
    var xaml   = flagNameXaml  (name, x, y); // dotXaml flagXaml
    var xamlC  = plugin.content.createFromXaml(xaml);
    canvas.children.add(xamlC);
}


function tileImageXaml (row, col, tileSize)
{
/// <summary>
/// Draw the Image Xaml to hold a tile image. The 'x:Name standard'
/// for the tiles is t_[row]_[col], which will be unique for a grid
/// of any size and can be easily generated in code 
/// </summary>
    var xName = 't_' + row + '_' + col; // t_0_0
    var canvasLeft = row * tileSize;
    var canvasTop = col * tileSize;
    return '<Image xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RenderTransformOrigin="0.5,0.5" x:Name="'+xName+'" Width="'+tileSize+'" Height="'+tileSize+'"'
+'           Source="" ImageFailed="OnImageFailedHandler" '
+'           Stretch="Fill" Canvas.Left="'+canvasLeft+'" Canvas.Top="'+canvasTop+'">'
+'      <Image.RenderTransform>'
+'        <TransformGroup>'
+'          <ScaleTransform ScaleX="1" ScaleY="1" />'
+'          <SkewTransform AngleX="0" AngleY="0" />'
+'          <RotateTransform Angle="0" />'
+'          <TranslateTransform X="0" Y="0" />'
+'        </TransformGroup>'
+'      </Image.RenderTransform>'
+'    </Image>';
}