Retour à la documentation
/**
* @class spw.widgets.SpwScaleBar
*/
define(["dojo/_base/declare", "spw/api/SpwBaseTemplatedWidget",
"dojo/i18n!./nls/SpwScaleBar","dojo/text!./templates/SpwScaleBar.html",
"spw/api/SpwMap",
"dojo/_base/lang","dojo/on",
"dojo/keys",
"esri/dijit/Scalebar",
"dijit/layout/BorderContainer","dijit/layout/ContentPane","dijit/form/TextBox"],
function(declare, SpwBaseTemplatedWidget,
labels, template,
SpwMap,
lang, on,
keys,
Scalebar){
for(var k in Scalebar.prototype.localStrings){
Scalebar.prototype.localStrings[k] = " " + Scalebar.prototype.localStrings[k];
}
var SpwScaleBar = null;
SpwScaleBar = declare("spw.widgets.SpwScaleBar", [SpwBaseTemplatedWidget],{
templateString: template,
labels: labels,
scalebar: null,
spwMap: null,
"widgetId": "idScaleBar",
"activated": true,
"position": "map",
"mapPosition": {
"bottom": "10px",
"left": "45px"
},
constructor: function(config) {
},
postMixInProperties: function() {
this.inherited(arguments);
this.spwMap = this.spwViewer.get("spwMap");
this.own(
this.spwMap.on(SpwMap.events.MapExtentChanged, lang.hitch(this, this._mapExtentChanged))
);
},
postCreate: function() {
this.inherited(arguments);
this.scalebar = new Scalebar({
map: this.spwMap.get("esriMap"),
scalebarUnit:"metric",
scalebarStyle:"line"
}, this.scaleBarContainer);
this.own(
this.scaleInput.on("keydown", lang.hitch(this, this._scaleInputChanged)),
this.spwViewer.get('spwMap').on(this.spwViewer.get('spwMap').events.MapCreated, lang.hitch(this, function(map) {
if (this.scalebar) {
this.scalebar.destroy();
this.scalebar = null;
}
this.scalebar = new Scalebar({
map: map,
scalebarUnit: "metric",
scalebarStyle: "line"
}, this.scaleBarContainer);
}))
);
this.scaleInput.set("value", Math.round(this.spwMap.getCurrentScale()));
},
_scaleInputChanged: function(event){
if(event.keyCode === keys.ENTER && !isNaN(parseFloat(this.scaleInput.get("value")))){
var extent = this.spwMap.getExtentForScale(parseFloat(this.scaleInput.get("value")));
this.spwMap.zoomToExtent(extent, false);
}
},
_mapExtentChanged: function(){
this.scaleInput.set("value", Math.round(this.spwMap.getCurrentScale()));
}
});
return SpwScaleBar;
});