Code: Select all
using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
namespace TestArcGisCshtml5
{
public class ArcGISMapControl : Canvas
{
public ArcGISMapControl()
{
this.Loaded += ArcGISMapControl_Loaded;
}
void ArcGISMapControl_Loaded(object sender, RoutedEventArgs e)
{
// Make sure that we are not running inside the Simulator (only running inside the web browser is currently supported):
if (CSharpXamlForHtml5.Environment.IsRunningInJavaScript == false)
{
this.Children.Add(new TextBlock()
{
Text = @"
The ArcGIS Map Control currently
does not support runnning inside
the Simulator. Please run inside
your web browser instead."
});
}
else
{
// Always ensure that the control is loaded into the visual tree before messing up with its HTML DOM representation (not really useful here because we are inside the "Loaded" event):
if (!CSharpXamlForHtml5.DomManagement.IsControlInVisualTree(this))
throw new Exception("The control is not loaded into the visual tree. Consider waiting until the Loaded event before calling this piece of code.");
// Get a reference to the HTML DOM representation of the control. This will return the "div" used to render the control in HTML:
object div = CSharpXamlForHtml5.DomManagement.GetDomElementFromControl(this);
// Set the ID of the div so that we can reference it from the JavaScript code:
((dynamic)div).id = "mapDiv";
// Call the JavaScript code that will load the ArcGIS JavaScript librabries, load the ArcGIS CSS stylesheets, and render the map inside the aforementioned div:
JSIL.Verbatim.Expression(@"
function loadScript(url, callback)
{
// Add the script tag to the head.
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
script.onreadystatechange = callback;
script.onload = callback;
// Fire the loading.
head.appendChild(script);
}
function loadCss(url, callback)
{
// Add the link tag to the head.
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'http://js.arcgis.com/3.13/esri/css/esri.css';
link.media = 'all';
// Then bind the event to the callback function.
// There are several events for cross browser compatibility.
link.onreadystatechange = callback;
link.onload = callback;
// Fire the loading.
head.appendChild(link);
}
var loadMap = function() {
require([""esri/map"", ""dojo/domReady!""], function(Map) {
map = new Map(""mapDiv"", {
center: [-56.049, 38.485],
zoom: 3,
basemap: ""streets""
});
});
};
loadCss(""http://js.arcgis.com/3.13/esri/css/esri.css"", function() {
loadScript(""http://js.arcgis.com/3.13/"", function() {
loadMap()
});
});
");
}
}
}
}
Code: Select all
<Page
x:Class="TestArcGisCshtml5.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestArcGisCshtml5">
<local:ArcGISMapControl/>
</Page>
Code: Select all
function myFunction(a, b) {
return a * b;
}
Code: Select all
var myFunction = function (a, b) {
return a * b
};
Return to “General Discussion and Other”
Users browsing this forum: No registered users and 11 guests