[GIS] Problems with ESRI JavaScript API

arcgis-javascript-apijavascript

I'm having some problems to get started using the ESRI JavaSript API. I have a test map service published on my notebook but I can't get it to display. I don't have problems with esri hosted services, just the ones I'm trying to host.

Here is some code:

<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1" type="text/javascript"></script>
<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >
<script type="text/javascript">
    dojo.require("esri.map");
    dojo.require("esri.geometry");
    dojo.require("esri.layers");
    var map;
    function init() {
        esri.config.defaults.io.proxyUrl = "/proxy/proxy.ashx";
        map = new esri.Map("mapDiv");
        // var basemapURL = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
        var myURL = "http://brpnb010/arcgis/rest/services/teste/MapServer";

        // var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);
        var myLayer = new esri.layers.ArcGISTiledMapServiceLayer(myURL);

        // map.addLayer(basemap);
        map.addLayer(myLayer);

        dojo.connect(map, "onExtentChange", showExtent);
    }

    function showExtent(extent) {
        var s = "";
        s = "XMin: " + extent.xmin +
        " YMin: " + extent.ymin +
        " XMax: " + extent.xmax +
        " YMax: " + extent.ymax;

        dojo.byId("onExtentChangeInfo").innerHTML = s;
    }

    dojo.addOnLoad(init);
</script>

I'm using Visual Studio to develop, and when the page loads, I get a "Could not load cross domain resources" error.

edit I'm using version 2.1 of the Javascript API. And I'm developing on localhost, which has the brpnb010 name.

Any ideas?

Thanks,

George

Best Answer

Post more code. Could not load cross domain resource either means you spelled a dojo require wrong or you are accessing JavaScript files via xhr that have different domain names. Use firefox and firebug and look at the net and console tabs and post what errors you are getting there

Also what's up with the proxy. You shouldn't need that on localhost dev.

I also don't think you need to require .geometry or .layer

this works:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Test Page</title>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1" type="text/javascript"></script>
<link href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.1/js/dojo/dijit/themes/claro/claro.css" rel="stylesheet" type="text/css" >
<script type="text/javascript">
    dojo.require("esri.map");
    //dojo.require("esri.geometry");
    //dojo.require("esri.layers");
    var map;
    function init() {
        map = new esri.Map("mapDiv");
        // var basemapURL = "http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer";
        var myURL =  "http://mapserv.utah.gov/ArcGIS/rest/services/UtahBaseMap-Topo/MapServer";

        // var basemap = new esri.layers.ArcGISTiledMapServiceLayer(basemapURL);
        var myLayer = new esri.layers.ArcGISTiledMapServiceLayer(myURL);

        // map.addLayer(basemap);
        map.addLayer(myLayer);

        dojo.connect(map, "onExtentChange", showExtent);
    }

    function showExtent(extent) {
        var s = "";
        s = "XMin: " + extent.xmin +
        " YMin: " + extent.ymin +
        " XMax: " + extent.xmax +
        " YMax: " + extent.ymax;

        dojo.byId("onExtentChangeInfo").innerHTML = s;
    }

    dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div id="mapDiv"></div>
<div id="onExtentChangeInfo"></div>
</body>
</html>