dojo.require("dijit.layout.BorderContainer"); dojo.require("dijit.layout.ContentPane"); dojo.require("esri.map"); dojo.require("esri.renderer"); dojo.require("esri.graphic"); dojo.require("esri.dijit.Legend"); dojo.require("esri.utils"); dojo.require("dijit.layout.AccordionContainer"); dojo.require("esri.layers.FeatureLayer"); var map; var basemap; var trafficmap; var basemapServiceSource; var featuremapServiceSource; var trafficServiceSource; var renderer; var loading; function init() { // for now, these are referring to a single source basemapServiceSource = "http://co-gis-01/ArcGIS/rest/services/dev_RTIA/rtia/MapServer"; //Add the topographic layer to the map. View the ArcGIS Online site for services http://arcgisonline/home/search.html?t=content&f=typekeywords:service basemap = new esri.layers.ArcGISDynamicMapServiceLayer(basemapServiceSource); basemap.setVisibleLayers([0, 1, 2, 4, 5, 6]); map = new esri.Map("map", { // remove logo logo:false }); //loading image. id loading = dojo.byId("loadingImg"); dojo.connect(map,"onUpdateStart",showLoading); dojo.connect(map,"onUpdateEnd",hideLoading); /* IDs of Layers for http://co-gis-01/ArcGIS/rest/services/dev_ExIS/exis/MapServer Site Name (0) Section ID (1) AADT some (2) AADT all (3) AdministrativeAreas_CongressionalDistricts (4) AdministrativeAreas_Provinces (5) AdministrativeAreas_Regions (6) */ map.addLayer(basemap); // executes function on onLoad event dojo.connect(map, 'onLoad', function(theMap) { dojo.connect(dijit.byId('map'), 'resize', map,map.resize); zoomToLayer(); }); } function zoomToLayer() { var requestHandle = esri.request({ url: "http://co-gis-01/ArcGIS/rest/services/dev_RTIA/rtia/MapServer/2", content: { f:"json" }, callbackParamName: "callback" }); requestHandle.then(requestSucceeded, requestFailed); } function requestSucceeded(response, io) { var extent = new esri.geometry.Extent(response.extent); dojo.byId("extent").innerHTML = dojo.toJson(extent.toJson()); map.setExtent(extent); } function requestFailed() { alert("requestFailed"); } function showLoading() { esri.show(loading); map.disableMapNavigation(); map.hideZoomSlider(); } function hideLoading(error) { esri.hide(loading); map.enableMapNavigation(); map.showZoomSlider(); } dojo.addOnLoad(init);
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>RTIA Map</title> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" > <link rel="stylesheet" type="text/css" href="gis.css" /> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script> <script type="text/javascript" src="rtia_culled.js"></script> </head> <body> <div id="map" class="mainmap"> <img id="loadingImg" src="images/loading.gif" class="loadimage"/> </div> <!--div id="legendDiv" style="width:600px; height:600px; border:1px solid #000"--> </div> <span id="extent"></span> </body> </html>
Solved! Go to Solution.
function featureUpdateEnd(error, info) { var localExtent; if (featuremap.graphics.length > 0) { for (var i = 0; i < featuremap.graphics.length; i++) { if (featuremap.graphics.geometry instanceof esri.geometry.Polyline) { try { if (i == 0) { localExtent = new esri.geometry.Extent(featuremap.graphics.geometry.getExtent().toJson()); } else { localExtent = localExtent.union(featuremap.graphics.geometry.getExtent()); } } catch (err) { //alert(String(i) + " is caught: " + err.message); } } } localExtent = localExtent.expand(1.25); map.setExtent(localExtent.getExtent()); } }
function featureUpdateEnd(error, info) { var localExtent; if (featuremap.graphics.length > 0) { for (var i = 0; i < featuremap.graphics.length; i++) { if (featuremap.graphics.geometry instanceof esri.geometry.Polyline) { try { if (i == 0) { localExtent = new esri.geometry.Extent(featuremap.graphics.geometry.getExtent().toJson()); } else { localExtent = localExtent.union(featuremap.graphics.geometry.getExtent()); } } catch (err) { //alert(String(i) + " is caught: " + err.message); } } } localExtent = localExtent.expand(1.25); map.setExtent(localExtent.getExtent()); } }