This article only describes phenomena and treatment measures, does not discuss the principle.
In the development process encountered this exception, after the query online is a cross-domain access problem, the solution is given by jquery cross-domain access mechanism to solve,
Do I need to find Arcgistiledmapservicelayer related code directly to refactor?
And the solution is as follows, http://resources.arcgis.com/en/help/rest/apiref/config.html, the main idea is to set up the ArcGIS Server service, service is someone else's, can not be set.
The code below, when you need to call another URL when you switch the map type, reports the following error.
if (TP = = "MP") {// removed before Map.removelayer (basemap); // Map New Arcgistiledmapservicelayer ("http://xxx.xxx.xxx.xxx.xxx.xxx"); $ ("#mptype"). Val ("MP"); Map.addlayer (basemap); }
In fact, two layer domain name is similar, do not know why this problem occurs.
Later, when the map was initialized, the two arcgistiledmapservicelayer were instantiated, and when the map was switched, the layers were added, deleted, and not instantiated, which solved the problem.
The approximate code is as follows:
functionLoadmap (lnt,lat,zo0o) {Zoom=zo0o; Require (["Esri/map", "Esri/toolbars/navigation", "Esri/layers/arcgistiledmapservicelayer"],function(Map, Navigation, Arcgistiledmapservicelayer) {options= {Logo:false, Fadeonzoom:true, Slider:true, Sliderposition:"Bottom-left", Sliderstyle:"Large" }; Inilat=lat; INILNT=LNT; Map=NewEsri. Map ("Mapdiv", Options); Basemap=NewArcgistiledmapservicelayer ("Http://xxx.xxx.xxx.xxx"); Annolayer=NewArcgistiledmapservicelayer ("http://bb.bbb.ccc.ddd"); Map.addlayer (Annolayer); Spatialreference=map.spatialreference; Map.on ("Mouse-down",function(evt) {Console.log (evt.mappoint.x.tofixed (3) + "," + evt.mappoint.y.tofixed (3)); }); Map.centerandzoom (Newesri.geometry.Point (LNT, LAT), zoom); Navtoolbar=NewNavigation (map); }); }
The map switch code is modified as follows:
function Maptypeswitch (TP) { require ([function (MAP, Arcgistiledmapservicelayer, Esriconfig) { false ; if (TP = = "MP") {// remove before $ ("#mptype"). Val ("MP"); Map.removelayer (annolayer); Map.addlayer (basemap); } }); }
ArcGIS Javascript Exception No ' access-control-allow-origin ' header