Skip to content

Instantly share code, notes, and snippets.

@green3g
Created March 28, 2017 20:59
Show Gist options
  • Save green3g/b0a818140676ec7da60aaa52519585e7 to your computer and use it in GitHub Desktop.
Save green3g/b0a818140676ec7da60aaa52519585e7 to your computer and use it in GitHub Desktop.
A simple url loading mixin
define([
'dojo/_base/declare',
'dojo/_base/lang'
], function (declare, lang) {
return declare(null, {
/**
* wait for previous config loaders then update the config object
*/
loadConfig: function (wait) {
if (wait) {
wait.then(lang.hitch(this, 'checkURLParams'));
} else {
this.checkURLParams();
}
return wait || this.inherited(arguments);
},
/**
* parse and check for valid url parameters and update the map config accordingly
*/
checkURLParams: function () {
var search = location.search.substring(1);
if (!search) {
return;
}
search = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');
if (search.center) {
// look for coordinates in the center parameter something like 40000,23123.2423
// here we're assuming the coordinates passed are in lat/lon
this.config.mapOptions.center = search.center.split(',');
}
if (search.zoom) {
// look for a zoom parameter
// something like 15
this.config.mapOptions.zoom = parseInt(search.zoom, 10);
}
}
});
});
define([
'dojo/_base/declare',
// minimal Base Controller
'viewer/_ControllerBase',
// *** Controller Mixins
// Use the core mixins, add custom mixins
// or replace core mixins with your own
'viewer/_ConfigMixin', // manage the Configuration
'viewer/_LayoutMixin', // build and manage the Page Layout and User Interface
'viewer/_MapMixin', // build and manage the Map
'viewer/_WidgetsMixin', // build and manage the Widgets
'config/_URLMixin',
//include our apps css
'xstyle/css!./css/main.css'
], function (
declare,
_ControllerBase,
_ConfigMixin,
_LayoutMixin,
_MapMixin,
_WidgetsMixin,
_URLMixin
//_MyCustomMixin
) {
return declare([
_URLMixin, // add a url mixin!
_ConfigMixin,
_LayoutMixin,
_MapMixin,
_WidgetsMixin,
_ControllerBase
]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment