Skip to content

Commit

Permalink
fix(map-ui): show scale on ie9 mercator maps
Browse files Browse the repository at this point in the history
fix missing scale when IE9 loads mercator basemaps

Closes #9951
  • Loading branch information
Spencer Wahl committed May 8, 2015
1 parent e20eae8 commit b9c83ab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 57 deletions.
35 changes: 3 additions & 32 deletions src/js/RAMP/Modules/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global define, esri, i18n, console, $, RAMP, proj4, window */
/*global define, esri, console, $, RAMP, proj4, window */

/**
*
Expand Down Expand Up @@ -141,6 +141,7 @@ define([
* @param {Object} event
*/
function _updateScale(event) {
console.log("hjkl");
if (event.levelChange) {
var currentScale = number.format(event.lod.scale),
scaleLabelText = "1 : " + currentScale;
Expand All @@ -150,36 +151,6 @@ define([
}
}

/**
* Initialize Map Scale
*
* @private
* @method _initScale
* @param {Object} event
*/
function _initScale(event) {
var map = event.map,
scaleDiv = domConstruct.create("div", {
id: "scaleDiv",
class: "esriScalebarLabel"
}),
currentScale,
scaleLabelText;
$(scaleDiv).html("<span>" + i18n.t('map.scale') + "</span><br><span id='scaleLabel'><span/>");
currentScale = number.format(map.getScale());
scaleLabelText = "1 : " + currentScale;

domConstruct.place(scaleDiv, query(".esriScalebarRuler")[0], "before");
domConstruct.empty('scaleLabel');
$("#scaleLabel").text(scaleLabelText);

// Change the css class of the scale bar so it shows up against
// the map
topic.subscribe(EventManager.BasemapSelector.BASEMAP_CHANGED, function (attr) {
$(".esriScalebar > div").removeClass().addClass(attr.cssStyle);
});
}

/**
* Republishes map events to the outside using topic.publish
*
Expand Down Expand Up @@ -372,7 +343,7 @@ define([
* @param {Object} map A ESRI map object
*/
function _initEventHandlers(map) {
map.on("load", _initScale);
//map.on("load", _initScale);
map.on("extent-change", function (event) {
_updateScale(event);

Expand Down
75 changes: 50 additions & 25 deletions src/js/RAMP/bootstrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@
* Phase X?: For mobile support, there can be a different mobileBootstrapper with only the mobile modules loaded
*
* ####Imports RAMP Modules:
* {{#crossLink "Map"}}{{/crossLink}}
* {{#crossLink "BaseMapSelector"}}{{/crossLink}}
* {{#crossLink "Maptips"}}{{/crossLink}}
* {{#crossLink "Datagrid"}}{{/crossLink}}
* {{#crossLink "Navigation"}}{{/crossLink}}
* {{#crossLink "FilterManager"}}{{/crossLink}}
* {{#crossLink "BookmarkLink"}}{{/crossLink}}
* {{#crossLink "Url"}}{{/crossLink}}
* {{#crossLink "FeatureHighlighter"}}{{/crossLink}}
* {{#crossLink "RAMP"}}{{/crossLink}}
* {{#crossLink "GlobalStorage"}}{{/crossLink}}
* {{#crossLink "GUI"}}{{/crossLink}}
* {{#crossLink "EventManager"}}{{/crossLink}}
* {{#crossLink "AdvancedToolbar"}}{{/crossLink}}
* {{#crossLink "Util"}}{{/crossLink}}
* {{#crossLink "Prototype"}}{{/crossLink}}
* {{#crossLink "FunctionMangler"}}{{/crossLink}}
* {{#crossLink "LayerLoader"}}{{/crossLink}}
*
* {{#crossLink "Map"}}{{/crossLink}}
* {{#crossLink "BaseMapSelector"}}{{/crossLink}}
* {{#crossLink "Maptips"}}{{/crossLink}}
* {{#crossLink "Datagrid"}}{{/crossLink}}
* {{#crossLink "Navigation"}}{{/crossLink}}
* {{#crossLink "FilterManager"}}{{/crossLink}}
* {{#crossLink "BookmarkLink"}}{{/crossLink}}
* {{#crossLink "Url"}}{{/crossLink}}
* {{#crossLink "FeatureHighlighter"}}{{/crossLink}}
* {{#crossLink "RAMP"}}{{/crossLink}}
* {{#crossLink "GlobalStorage"}}{{/crossLink}}
* {{#crossLink "GUI"}}{{/crossLink}}
* {{#crossLink "EventManager"}}{{/crossLink}}
* {{#crossLink "AdvancedToolbar"}}{{/crossLink}}
* {{#crossLink "Util"}}{{/crossLink}}
* {{#crossLink "Prototype"}}{{/crossLink}}
* {{#crossLink "FunctionMangler"}}{{/crossLink}}
* {{#crossLink "LayerLoader"}}{{/crossLink}}
*
* @class Bootstrapper
* @static
*
Expand All @@ -44,7 +44,7 @@

require([
/* Dojo */
"dojo/parser", "dojo/topic", "dojo/request/script", "dojo/request/xhr",
"dojo/parser", "dojo/topic", "dojo/request/script", "dojo/request/xhr", "dojo/number", "dojo/dom", "dojo/dom-construct", "dojo/query",
"esri/config", "esri/urlUtils",

/* RAMP */
Expand All @@ -54,7 +54,7 @@ require([
"ramp/globalStorage", "ramp/gui", "ramp/eventManager",
"ramp/advancedToolbar", "ramp/geoSearch",
"ramp/theme", "ramp/layerLoader", "ramp/dataLoaderGui",

/* Utils */
"utils/util",

Expand All @@ -64,7 +64,7 @@ require([
function (
/* Dojo */
parser, topic, requestScript, xhr,
esriConfig, esriUrlUtils,
esriConfig, esriUrlUtils, number, dom, domConstruct, query,

/* RAMP */
RampMap, BasemapSelector, Maptips, Datagrid, NavWidget, FilterManager, ImageExport,
Expand Down Expand Up @@ -97,6 +97,30 @@ require([
function initializeMap() {
/* Start - RAMP Events, after map is loaded */

function initScale() {
var map = RAMP.map,
scaleDiv = domConstruct.create("div", {
id: "scaleDiv",
class: "esriScalebarLabel"
}),
currentScale,
scaleLabelText;

$(scaleDiv).html("<span>" + i18n.t('map.scale') + "</span><br><span id='scaleLabel'><span/>");
currentScale = number.format(map.getScale());
scaleLabelText = "1 : " + currentScale;

domConstruct.place(scaleDiv, query(".esriScalebarRuler")[0], "before");
domConstruct.empty('scaleLabel');
$("#scaleLabel").text(scaleLabelText);

// Change the css class of the scale bar so it shows up against
// the map
topic.subscribe(EventManager.BasemapSelector.BASEMAP_CHANGED, function (attr) {
$(".esriScalebar > div").removeClass().addClass(attr.cssStyle);
});
}

// this split exists solely to separate out the parts that IE9 is
// bad at handling there is a DOM race condition somewhere in here,
// we've given up on trying to find it
Expand All @@ -121,6 +145,8 @@ require([
topic.subscribe(EventManager.Map.INITIAL_BASEMAP_LOADED, function () {
console.log("map - >> first update-end; init the rest");

initScale();

// Only initialize the bookmark link after all the UI events of all other modules have
// finished loading
// IMPORTANT: for now, only basemapselector and filtermanager have a UI complete event
Expand Down Expand Up @@ -156,7 +182,6 @@ require([
} else {
guiInits();
}

});

RampMap.init();
Expand Down Expand Up @@ -280,7 +305,7 @@ require([
esriConfig.defaults.io.proxyUrl = RAMP.config.proxyUrl;
// try to avoid the proxy if possible, but this will cause network errors if CORS is not allowed by the target server
esriConfig.defaults.io.corsDetection = !brokenWebBrowser;
// really IE9??? (╯°□°)╯︵ ┻━┻
// really IE9??? (╯°□°)╯︵ ┻━┻
if (brokenWebBrowser && RAMP.config.exportProxyUrl !== undefined) {
esriUrlUtils.addProxyRule({ proxyUrl: RAMP.config.exportProxyUrl, urlPrefix: RAMP.config.exportMapUrl });
}
Expand Down Expand Up @@ -328,4 +353,4 @@ require([
//project extents to basemap
RampMap.projectConfigExtents();
}
});
});

0 comments on commit b9c83ab

Please sign in to comment.