My Location widget being active on start

924
6
Jump to solution
11-16-2018 09:42 AM
NathanKoski
New Contributor III

Hi there,

I am building a web app and ideally it needs to open at the user's location when they start the app. So far we have the My Location widget set up as an On Screen app, and it works perfectly when turned on/off, however, I have to actually turn the widget on. 

I was experimenting if there was a way to configure My Location to simply be active on startup. I tried adding the attribute "openAtStart": true to the widgets json config, but it does not work.

Is there an alternative method for the map to open and navigate directly to the user's location by default? The app will be mostly used from inside of an iframe, so might it be possible to configure the extent that way?

Thanks in advanced.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Nathan,

   Sure you can do this with one simple line of code. Add line 17 to the widget.js in the startup function.

      startup: function() {
        this.inherited(arguments);
        this.placehoder = html.create('div', {
          'class': 'place-holder',
          title: this.label
        }, this.domNode);

        this.isNeedHttpsButNot = jimuUtils.isNeedHttpsButNot();

        if (true === this.isNeedHttpsButNot) {
          console.log('LocateButton::navigator.geolocation requires a secure origin.');
          html.addClass(this.placehoder, "nohttps");
          html.setAttr(this.placehoder, 'title', this.nls.httpNotSupportError);
        } else if (window.navigator.geolocation) {
          this.own(on(this.placehoder, 'click', lang.hitch(this, this.onLocationClick)));
          this.own(on(this.map, 'zoom-end', lang.hitch(this, this._scaleChangeHandler)));
          this.onLocationClick();
        } else {
          html.setAttr(this.placehoder, 'title', this.nls.browserError);
        }
      },

View solution in original post

6 Replies
RobertScheitlin__GISP
MVP Emeritus

Nathan,

   Sure you can do this with one simple line of code. Add line 17 to the widget.js in the startup function.

      startup: function() {
        this.inherited(arguments);
        this.placehoder = html.create('div', {
          'class': 'place-holder',
          title: this.label
        }, this.domNode);

        this.isNeedHttpsButNot = jimuUtils.isNeedHttpsButNot();

        if (true === this.isNeedHttpsButNot) {
          console.log('LocateButton::navigator.geolocation requires a secure origin.');
          html.addClass(this.placehoder, "nohttps");
          html.setAttr(this.placehoder, 'title', this.nls.httpNotSupportError);
        } else if (window.navigator.geolocation) {
          this.own(on(this.placehoder, 'click', lang.hitch(this, this.onLocationClick)));
          this.own(on(this.map, 'zoom-end', lang.hitch(this, this._scaleChangeHandler)));
          this.onLocationClick();
        } else {
          html.setAttr(this.placehoder, 'title', this.nls.browserError);
        }
      },
TomManson
New Contributor III

Robert,

Thanks for providing this simple answer. Is there an equally easy way to change the default zoom level on the My Location widget, or indeed turn the zoom feature off/have an option?

Many thanks,

Tom

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Tom,

   You can set the zoom scale right in the widgets setting dialog.

0 Kudos
TomManson
New Contributor III

Many thanks. Now I feel really silly. I’m sure that option wasn’t there last time I checked.

Tom

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Nathan,

Don't forget to mark this question as answered by clicking on the "Mark Correct" link on the reply that answered your question.

0 Kudos
SimonFonji
New Contributor III

Hello All,

When you configure the 'My Location Widget' to ask users whether to allow for their location or not, is it possible to change the message at the top e.g. 'www.arcg...pa.gov wants to' to something of your choice or it depends on the browser you are using.

Thanks,

Simon.

0 Kudos