2

I've taken a basic webmap 'ESRI HomeButton' and I'm trying to create a modularized webmap setup from it. I want to break down this simple webmap to have it utilizing a module system with config files and more. Then I can take other single-use webmaps and breakout the widgets into separate files much more easily and approach everything very much like the FlexViewer environment.

The problem I am having is that in my widgetHomeButton.js file, I took the HomeButton.js code and added in three lines...

In my require, I added "widgets/homebutton/config" to point to my config.js file. I should mention I have a package.js file that sets up the folders so that 'widgets' points to package_path + "path/to/widgets" just like in the example.

In my function, I added widgetConfig as the variable to store the config.js file contents, which happen to be JSON style data.

Then in the HomeButton widget code I added a single line of code that reads...

console.log( widgetConfig );

And all I get are errors. Any ideas what I am doing wrong?

  • What kind of errors are you getting? – James Lawruk Jul 23 '14 at 11:17
2

If I understand your question correctly, Use dojo/text! and JSON.parse to grab config:

Assumes directory structure something like:

/src/js/MyWidget
  - /templates
    - MyWidget.html
  - MyWidget.js
  - MyWidgetConfig.js

MyWidget.js:

// Define Widget Module
define(
  [
    "dojo/_base/declare",
    "dojo/dom-construct",
    "dojo/text!./templates/MyWidget.html",
    "dojo/text!./MyWidgetConfig.js",
  ],
  function (declare, domConstruct, template, widgetConfigJson) {
    'use strict'; // ECMAScript 5 Strict Mode

    return declare(null, {
        constructor: function (map, srcNodeRef) {
          this.map = map;

          // place templated html
          domConstruct.place(template, srcNodeRef);

          // parse json config into object.
          // name file .js instead of .json
          var widgetConfig = JSON.parse(widgetConfigJson);
        });
    });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.