<html> <head> <!-- TITRE --> <title>Cartographie 2.0</title> <!-- FORMATAGE --> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- DOCTYPE --> <!DOCTYPE html> <!-- XHTML --> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <!-- CSS --> <link rel="stylesheet" href="css/interface.css" type="text/css"> <!-- JAVASCRIPT --> <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.3/"></script> <script type="text/javascript" src="js/jquery-1.9.1.min.js" ></script> <script type="text/javascript" src="js/jquery-ui-1.10.1.custom.min.js" ></script> <script type="text/javascript"> dojo.require("esri.map"); oData = { "nom":"Coaticook", "extent": { "xmin": -8007750, "ymin": 5622181, "xmax": -7978153, "ymax": 5647140 } }; dojo.ready(function() { var oMapper = new Mapper(oData); oMapper.init(); oMapper.initMap(); }); function Mapper(oData) { this.map; this.setMap = setMap; this.getMap = getMap; this.div_map; this.init = init; this.builDivs = buildDivs; this.oData = oData; this.initMap = initMap; this.basemap = basemap; this.addLayers = addLayers; function init() { buildDivs(); } function buildDivs() { this.div_map = $('<div id="map"></div>'); $('#main').append(this.div_map); } function initMap() { var initialExtent = new esri.geometry.Extent({ 'xmin': oData.extent.xmin, 'ymin': oData.extent.ymin, 'xmax': oData.extent.xmax, 'ymax': oData.extent.ymax, 'spatialReference': new esri.SpatialReference({ wkid: 102100 }) }); var map = new esri.Map("map", { extent: initialExtent, "fadeOnZoom": true, logo: true, showAttribution: false }); setMap(map); console.log(getMap); addLayers(); } function setMap(map) { this.map = map; } function getMap() { return this.map; } function addLayers() { var layers = new Array(); layers.push(basemap()); console.log(layers); var map = getMap(); map.addLayers(layers); console.log(map); } function basemap() { var baseMapUrl = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer"; var baseMap = new esri.layers.ArcGISTiledMapServiceLayer(baseMapUrl, {id:'basemap'}); return baseMap; } } </script> </head> <body> <div id="main" class="container"> </div> </body> </html>
Solved! Go to Solution.