Hi,
I tried to use a DynamicMapServiceLayer as a basemap.
In API ArcGIS 4.1 it works :
service_basemap = new MapImageLayer({url: <service url>, title: <title>, id : <id>, spatialReference: 3857});
basemap_name = new Basemap({baseLayers: [ service_basemap ], title: <title>, id : <id>});
In API ArcGIS 3.18, i tried to adapt this code but it doesn't work.
In ArcGIS API 3.17, I can load it with basemap gallery widget with an error :
undefined init.js:113:480
m()init.js:113
h/e<()init.js:114
.cache["dojo/_base/array"]/</e.filter()init.js:71
h()init.js:114
but i can't use it on application start
So, is someone know how to use Dynamic map service Layer as a basemap with the API ArcGIS 3.18 or 3.17 ?
Thanks for your help.
Guillaume ARNAUD
In 3.17, below is the snippet to create a Basemap.
var basemap = new Basemap({
layers: [ new BasemapLayer({
url:"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyBasemap/MapServe..."})],
title: "Public Safety",
});
I allready try this.
Your answer works with Tiled Map but not with Dynamic Map Service. I have a white page. My code :
require(["esri/basemaps", "esri/geometry/Extent", "esri/map", "dojo/domReady!"],
function (esriBasemaps, Extent, Map){
esriBasemaps.Cadastre = {
baseMapLayers: [{url: "https://lacarto.ledepartement82.fr/arcgis/rest/services/Raster_WGS84/Cadastre/MapServer"}
],
title: "Cadastre"
};
//Définition de l'extent par défaut
var extent_standard = new Extent(0.725180211, 43.758998916, 2.007557285, 44.405176623);var map = new Map("maCarte", {
basemap: "Cadastre",
extent: extent_standard,
fitExtent:true
});
});
I try also with ;
require(["esri/layers/ArcGISDynamicMapServiceLayer", "esri/dijit/Basemap", "esri/geometry/Extent", "esri/map",
"dojo/domReady!"
], function (MapImageLayer, Basemap, Extent, Map){
var layer_cad = new MapImageLayer(
"https://lacarto.ledepartement82.fr/arcgis/rest/services/Raster_WGS84/Cadastre/MapServer",
{
id : j
}
);
var fdp_cad = new Basemap({
id: j,
layers: [ layer_cad ],
title: liste_fdp.nom
});
//Définition de l'extent par défaut
var extent_standard = new Extent(0.725180211, 43.758998916, 2.007557285, 44.405176623);var map = new Map("maCarte", {
basemap: fdp_cad,
extent: extent_standard,
fitExtent:true
});
});
result is the same. With the second option, basemap is loading when we call it with basemap gallery and when we have a tiled map layer on start
In the second option, you cannot use the fdp_cad as a parameter for Map options, as it is expecting string value.
Use map.setBasemap method instead.
require(["esri/layers/ArcGISDynamicMapServiceLayer", "esri/dijit/Basemap", "esri/geometry/Extent", "esri/map",
"dojo/domReady!"
], function (MapImageLayer, Basemap, Extent, Map){
var layer_cad = new MapImageLayer(
"https://lacarto.ledepartement82.fr/arcgis/rest/services/Raster_WGS84/Cadastre/MapServer",
{
id : j
}
);
var fdp_cad = new Basemap({
id: j,
layers: [ layer_cad ],
title: liste_fdp[i][j].nom
});
//Définition de l'extent par défaut
var extent_standard = new Extent(0.725180211, 43.758998916, 2.007557285, 44.405176623);
var map = new Map("maCarte", {
extent: extent_standard,
fitExtent:true
});
map.setBasemap(fdp_cad);
});
I try,
<script>
var map;
var fdp_cad;
require([
"esri/layers/ArcGISDynamicMapServiceLayer", "esri/dijit/Basemap", "esri/geometry/Extent", "esri/map",
"dojo/domReady!"
], function (MapImageLayer, Basemap, Extent, Map){
var layer_cad = new MapImageLayer(
"https://lacarto.ledepartement82.fr/arcgis/rest/services/Raster_WGS84/Cadastre/MapServer",
{
id : "toto"
}
);
fdp_cad = new Basemap({
id: "toto",
layers: [ layer_cad ]
});
//Définition de l'extent par défaut
var extent_standard = new Extent(0.725180211, 43.758998916, 2.007557285, 44.405176623);map = new Map("maCarte", {
extent: extent_standard,
fitExtent:true
});
map.setBasemap("fdp_cad");
});
</script>
</head><body>
<div id="maCarte"></div>
</body>
I allready have a white window.
If i set basemap: "topo" in config ( see the basemap "topo" ) then i call : map.setBasemap(fdp_cad); in firebug, I have an error:
TypeError: h is undefined
Trace de la pile :
.cache["esri/layers/TiledMapServiceLayer"]/</l<._setMap@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:731:198
.cache["esri/_coremap"]/</e<._addLayerHandler@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:363:169
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
.cache["esri/_coremap"]/</e<._addLayer/c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:359:320
.cache["esri/_coremap"]/</e<._addLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:360:4
.cache["esri/_coremap"]/</e<.addLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:392:376
.cache["esri/_coremap"]/</e<._addBasemap/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:403:171
.cache["dojo/_base/array"]/</e.forEach@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:70:346
.cache["esri/_coremap"]/</e<._addBasemap@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:403:117
.cache["esri/_coremap"]/</e<._basemapLoaded@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:402:472
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
.cache["esri/_coremap"]/</e<.setBasemap/t@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:401:33
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
l/</c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:119:70
.cache["esri/layers/ArcGISTiledMapServiceLayer"]/</n<._initLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:724:357
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
v/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:676:36
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
f/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:671:249
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:163
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:163
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
.cache["dojo/_base/xhr"]/</b.xhr/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:92:116
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:279
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:419
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:452
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:419
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
n@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:138:247
e@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:142:393
.cache["esri/layers/TiledMapServiceLayer"]/</l<._setMap@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:731:198
.cache["esri/_coremap"]/</e<._addLayerHandler@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:363:169
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
.cache["esri/_coremap"]/</e<._addLayer/c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:359:320
.cache["esri/_coremap"]/</e<._addLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:360:4
.cache["esri/_coremap"]/</e<.addLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:392:376
.cache["esri/_coremap"]/</e<._addBasemap/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:403:171
.cache["dojo/_base/array"]/</e.forEach@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:70:346
.cache["esri/_coremap"]/</e<._addBasemap@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:403:117
.cache["esri/_coremap"]/</e<._basemapLoaded@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:402:472
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
.cache["esri/_coremap"]/</e<.setBasemap/t@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:401:33
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
l/</c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:119:70
.cache["esri/layers/ArcGISTiledMapServiceLayer"]/</n<._initLayer@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:724:357
.cache["dojo/_base/lang"]/</e.hitch/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:63:207
v/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:676:36
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
f/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:671:249
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:393
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:163
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:163
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
c@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:104:61
d@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:103:182
.cache["dojo/_base/Deferred"]/</b.Deferred/this.callback@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:105:10
.cache["dojo/_base/xhr"]/</b.xhr/<@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:92:116
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:279
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:419
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:452
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
.cache["dojo/Deferred"]/</a@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:108:146
.cache["dojo/Deferred"]/</h@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:419
.cache["dojo/Deferred"]/</k@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:107:205
.cache["dojo/Deferred"]/</g/this.resolve@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:109:280
n@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:138:247
e@https://lacarto.ledepartement82.fr/api_arcgis_317/init.js:142:393
init.js:113:480
Thanks for you help
Guillaume,
Or another option would be this sample:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Basemap Toggle</title>
<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.18/esri/css/esri.css">
<style>
html, body, #map {
padding:0;
margin:0;
height:100%;
}
</style>
<script src="http://js.arcgis.com/3.18/"></script>
<script>
var map;
require([
"esri/map",
"esri/dijit/Basemap",
"esri/dijit/BasemapLayer",
"esri/geometry/Extent",
"esri/basemaps",
"dojo/domReady!"
], function(
Map,
Basemap,
BasemapLayer,
Extent,
esriBasemaps
) {
esriBasemaps.kytcbase = {
baseMapLayers: [{url: "http://maps.kytc.ky.gov/arcgis/rest/services/BaseMap/KYTCBaseMap/MapServer"}],
thumbnailUrl: "http://maps.kytc.ky.gov/arcgis/rest/services/BaseMap/KYTCBaseMap/mapserver/info/thumbnail",
title: "Kentucy Base"
};
map = new Map("map", {
extent: new Extent({xmin:-179.6191629086413,ymin:17.881242000418013,xmax:-65.2442340001989,ymax:71.40623536706858,spatialReference:{wkid:4269}}),
basemap: 'kytcbase'
});
});
</script>
</head>
<body>
<div id="map" class="map">
</div>
</body>
</html>
Like before, your solution works with tiled Map Service but not with Dynamic Map Service
Guillaume,
I have not found a way to add a ArcGISDynamicMapServiceLayer as a basemap. What I am able to get working is not specifying a basemap in the map constructor at all and then just add the ArcGISDynamicMapServiceLayer to the map using addLayer or addLayers methods.
I think so.
As, I need to use a personal Basemap Gallery, i create a specific reponse on "basemap-change" on event :
I declare a free new Basemap in my array of peronnal basemap.
bmp = new Basemap({id : "id0",layers : [ "<white tiled or simple one>" ],thumbnailUrl : "thumbnail of dyn_layer",title : "title of dynamic map"});
I add a property on bmp which declare the layer dynamic :
bmp.layers[0].dyn_layer = new ArcGISDynamicMapServiceLayer("<url of mapservice>", {id : "myid");
I declare a global variable for the program (dyn_bm) which remember if the basemap use one dynamic map service.
I add map event on basemap-change
map.on("basemap-change", function(bmc){
if (dyn_bm) {
carte.removeLayer(dyn_bm);
dyn_bm = null;
}
if (bmc.current.infos[0].dyn_layer) {
dyn_bm = bmc.current.infos[0].dyn_layer;
carte.addLayer(dyn_bm);
}
});
It works.
To make simple and don't have to make an other test when the app start, i load the first basemap with
map.setBasemap(bmp);
As, I need to use a personal Basemap Gallery, i create a specific reponse on "basemap-change" on event :
I declare a free new Basemap in my array of peronnal basemap.
bmp = new Basemap({id : "id0",layers : [ "<white tiled or simple one>" ],thumbnailUrl : "thumbnail of dyn_layer",title : "title of dynamic map"});
I add a property on bmp which declare the layer dynamic :
bmp.layers[0].dyn_layer = new ArcGISDynamicMapServiceLayer("<url of mapservice>", {id : "myid");
I declare a global variable for the program (dyn_bm) which remember if the basemap use one dynamic map service.
I add map event on basemap-change
map.on("basemap-change", function(bmc){
if (dyn_bm) {
carte.removeLayer(dyn_bm);
dyn_bm = null;
}
if (bmc.current.infos[0].dyn_layer) {
dyn_bm = bmc.current.infos[0].dyn_layer;
carte.addLayer(dyn_bm);
}
});
It works.
To make simple and don't have to make an other test when the app start, i load the first basemap with
map.setBasemap(bmp);