Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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

share|improve this question
    
So you're running this via localhost? Oh, and what version of the Javascript API are you using? –  Michael Todd Jan 15 '11 at 6:47
    
Hey Michael. I've edited the question to include answers to your questions :D –  George Jan 15 '11 at 19:32
2  
What does Fiddler show? fiddler2.com/fiddler2 –  Kirk Kuykendall Jan 15 '11 at 20:18
add comment

3 Answers 3

up vote 3 down vote accepted

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>
share|improve this answer
    
When developing with OpenLayers you need a proxy to show WFS services (I know it's not case, just tried a lot of different things to see if it worked). I'll check out fiddler and firebug and i'll post some info here. –  George Jan 16 '11 at 14:36
    
i would start out removing the proxy and the dojo.require's that are not necessary and see if it works. I'm thinking you're getting the could not load xd resource because of your requires. –  Steve Jan 17 '11 at 1:04
    
@George, have you got this working yet? –  Steve Feb 16 '11 at 18:58
    
yea I got it working. Wrong dojo name. :P –  George Mar 7 '11 at 19:49
add comment

I think the problem is in the API requires at the top, they keep changing at each version. Try dojo.require("esri.tasks.geometry") instead of "esri.geometry" at version AGS JS API 2.1. Also, I don't see a need for "esri.layers" to simply add a layer. This would need to be further qualified if you were going to work with a layer object (such as GraphicsLayer, or FeatureLayer). Just make sure you are using the correct object(s) per your DOJO/JS API version.

share|improve this answer
add comment

Is your local service really a Tiled service? If not, you should be using an esri.layers.ArcGISDynamicMapServiceLayer(myURL);

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.