Postby labbr01 » Thu Apr 14, 2016 11:54 am
Esri is moving to API 4.0, actually in beta 3.
Esri recommand for new starting project to use immediatly 4.0, because there are a lot of breaking changes from previous version 3.15.
Since cshtml5 is also beta, would like use version 4.0 as soon as possible. I have begin to create a Esri.ArcGIS.Client wrapper around esri class (geometry, point, polygon, ArcGISDynamicMapServiceLayer, Map, SpatialReference, Field, FeatureSet, BufferParameter, Query, Relationship etc, etc).
I have around hundred of classes just to be able support 3 main things:
-add (or remove) layer on an existing map,
-turn on and off layer or label on the layer
-query feature on mouse click and get as result descriptive data of active layer, including related data (esri Relationship class)
Before going too far with 3.13, i want to move to Esri javascript Api 4.0 to avoid having to recode for breaking changes of Esri API.
With a standard html page, i am able to use the esri API 4.0 and view the map.
I have adapt the cshtml5 example (using cshtml5 beta 7.2 and esri 3.13 api) to convert code to the esri 4.0 beta 3. But, i cant't get any map displayed! have a message about «required» undefine, and if i try to run compile code in explorer, the console shows problem about css.
The «ArcGISMapControl» modified method for ArcGIS 4.0 api look like this:
async void ArcGISMapControl_Loaded(object sender, RoutedEventArgs e)
{
// Get a reference to the HTML DOM representation of the control (must be in the Visual Tree):
object div = Interop.GetDiv(this);
// Make sure that the Div has an ID, because the ArcGIS map controls requires an ID:
Interop.ExecuteJavaScript("if (!$0.id) { $0.id = $1 }", div, Guid.NewGuid().ToString());
// Version 4.0 of ArcGIS Javascript API
// Load the ArcGIS libraries and CSS files:
await Interop.LoadJavaScriptFile("https://js.arcgis.com/4.0beta3/esri/css/main.css");
await Interop.LoadCssFile("https://js.arcgis.com/4.0beta3/");
Interop.ExecuteJavaScript(@"
var divId = $0.id;
var methodToRememberJavaScriptMapObject = $1;
var zoom = $2;
require([
""esri/Map"",
""esri/views/MapView"",
""dojo/domReady!""
], function (Map, MapView) {
var map = new Map({
basemap: ""streets""
});
var view = new MapView({
container: divId, //reference to div section
map: map, //reference to the map object created before
zoom: zoom, //sets the zoom level based on level of detail (LOD)
center: [15, 65] //sets the center point of view in lon/lat
});
methodToRememberJavaScriptMapObject(view);
});
", div, (Action<object>)MethodToRememberJavaScriptMapObject, _zoom);
}
But the same map in a plain html page work!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>Get started with MapView - Create a 2D map</title>
<style>
html, body {
padding: 0;
margin: 0;
}
</style>
<link rel="stylesheet" href="https://js.arcgis.com/4.0beta3/esri/css/main.css"></p>
<script src="https://js.arcgis.com/4.0beta3/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"dojo/domReady!"
], function (Map, MapView) {
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "viewDiv", //reference to the scene div created in step 5
map: map, //reference to the map object created before the scene
zoom: 4, //sets the zoom level based on level of detail (LOD)
center: [15, 65] //sets the center point of view in lon/lat
});
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
I am using VS 2013 and IE 11.0.
Bruno L