Dirk.Schaefer

Scalebar - wrong start unit

Discussion created by Dirk.Schaefer on Mar 18, 2011
Latest reply on Dec 5, 2012 by hc_gis
Hello,

I´ve got a problem with the scalebar in my map: The Scalebar doesn´t show the right scale when the homepage is opened the first time. After dragging the map or after zooming, the scalebar works right. We use parts of the code from the ESRI-sample (http://help.arcgis.com/EN/webapi/javascript/arcgis/demos/widget/widget_scalebar.html).

And here is a short part out of my code:

<script type="text/javascript">djConfig = { parseOnLoad:true }</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.1"></script>

<script type="text/javascript">
dojo.require("dijit.dijit"); // optimize: load dijit layer
dojo.require("esri.map");
dojo.require("esri.toolbars.navigation");
dojo.require("esri.dijit.Scalebar");
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.layout.AccordionContainer");
dojo.require("dijit.form.Button");
dojo.require("dijit.Toolbar");


var map, navToolbar;
function init() {


var layersLoaded = 0; //varible to keep track of when all layers have been loaded.
var loading = dojo.byId("loadingImg"); //loading image. id

esriConfig.defaults.map.sliderLabel = null;
Eintragung des Start-Extents
var startExtent = new esri.geometry.Extent
({"xmin":3447000.000000,"ymin":5758000.000000,"xmax":3464000.000000,"ymax":5772000.000000,"spatialReference":{"wkid":31467}});

map = new esri.Map("map", {extent:startExtent});
navToolbar = new esri.toolbars.Navigation(map);
dojo.connect(map, "onLoad", showLoading);
dojo.connect(map, "onZoomStart", showLoading);
dojo.connect(map, "onPanStart", showLoading);

var nr1 = new esri.layers.ArcGISDynamicMapServiceLayer("http://nts1p008/ArcGIS/rest/services/Dienste/LP_Halle_Steinhagen/MapServer");
map.addLayer(nr1);
dojo.connect(nr1, "onUpdate", hideLoading);

var nr2 = new esri.layers.ArcGISDynamicMapServiceLayer("http://nts1p008/ArcGIS/rest/services/Dienste/TK50_SW_red/MapServer");
map.addLayer(nr2);
dojo.connect(nr2, "onUpdate", hideLoading);

dojo.connect(dijit.byId('map'), 'resize', function() { //resize the map if the div is resized
clearTimeout(resizeTimer);
var resizeTimer = setTimeout(function() {
map.resize();
map.reposition();
}, 500);
});
dojo.connect(map, 'onLoad', function(map) {
var scalebar = new esri.dijit.Scalebar({
map: map,
scalebarUnit:'metric'
});

});


function showLoading() {
esri.show(loading);
map.hideZoomSlider();
}

function hideLoading() {
layersLoaded++;
if (layersLoaded === map.layerIds.length) {
esri.hide(loading);
map.showZoomSlider();
layersLoaded = 0;
}
}
}

function extentHistoryChangeHandler() {
dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();
dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();


}
dojo.addOnLoad(init);
esri.config.defaults.map.logoLink = "http://www.kreis-guetersloh.de";

</script>
</head>



Maybe someone have recognized the same problem with the scalebar. Please let me know If you need more code. It would be nice if you can help me.

Thanks.

Outcomes