ArcGIS Javascript exception No ' access-control-allow-origin ' header

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.