Select to view content in your preferred language

Help DynamicMapService doesn't display

496
1
08-26-2010 12:02 PM
AlejandroMorales
New Contributor
Hi, I wonder If anyone could help me,

I got this code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Measure Distances</title>
  <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.0/js/dojo/dijit/themes/tundra/tundra.css">
  <script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.0" type="text/javascript"></script>

    <script type="text/javascript">
        dojo.require("esri.map");
        dojo.require("esri.tasks.geometry");
        dojo.require("esri.toolbars.draw");
        dojo.require("dojo.number");

        var geometryService;

        function init() {
            //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
            //If this null or not available the project and lengths operation will not work.  Otherwise it will do a http post to the proxy.
            esriConfig.defaults.io.proxyUrl = "/arcgisserver/apis/javascript/proxy/proxy.ashx";
            esriConfig.defaults.io.alwaysUseProxy = false;

            var startExtent = new esri.geometry.Extent(-80.0571, 41.3697, -74.4321, 44.0822, new esri.SpatialReference({ wkid: 4326 }));
            var map = new esri.Map("map", { extent: startExtent });
            dojo.connect(map, "onLoad", initFunctionality);

            //map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer"));
            map.addLayer(new esri.layers.ArcGISDynamicMapServiceLayer("http://servarcgisprd/ArcGIS/rest/services/MapaBase/MapServer"));

            geometryService = new esri.tasks.GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");

            dojo.connect(geometryService, "onLengthsComplete", outputDistance);
        }

        function initFunctionality(map) {
            var tb = new esri.toolbars.Draw(map);

            var lengthParams = new esri.tasks.LengthsParameters();

            //on draw end add graphic, project it, and get new length
            dojo.connect(tb, "onDrawEnd", function (geometry) {
                map.graphics.clear();
                lengthParams.polylines = [geometry];
                lengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_METER;
                lengthParams.geodesic = true;
                //call GeometryService.lengths() with projected geometry
                geometryService.lengths(lengthParams);
                var graphic = map.graphics.add(new esri.Graphic(geometry, new esri.symbol.SimpleLineSymbol()));
            });

            tb.activate(esri.toolbars.Draw.FREEHAND_POLYLINE);
        }

        function outputDistance(result) {
            dojo.byId("distance").innerHTML = dojo.number.format(result.lengths[0] ) + " meters";
        }

        dojo.addOnLoad(init);
    </script>

  </head>
  <body>
    Click and hold down on the map to draw a line that will be added to the map.  The application will then use the geometry service to project and compute the length of the line.
    <div id="map" class="tundra" style="width:1024px; height:512px; border:1px solid #000;"></div>
    Distance: <span id="distance"></span>
  </body>
</html>

Well the problem is that I press F5 to run it, and it does, but the map doesn't display ... I don't know why ... I thought it was the spatial reference but... I'm not sure
the spatial reference is:

Spatial Reference: PROJCS["WGS_1984_UTM_Zone_15N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",500.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-93.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],UNIT["Kilometer",1000.0]]

Anyone knows ?
0 Kudos
1 Reply
AlejandroMorales
New Contributor
I know why it doesn't display the map!
It was because :
// var startExtent = new esri.geometry.Extent(-80.0571, 41.3697, -74.4321, 44.0822, new esri.SpatialReference({ wkid: 4326 }));
var map = new esri.Map("map"); //, { extent: startExtent });

this lines had the extent parameter on it, so I just commented and It work, but I have another problem now :S please help me If you know how

My map doesnt Zoom in or out it just stay I want to get closer
please if you know help me
0 Kudos