Select to view content in your preferred language

WebAppBuilder Widget

922
4
Jump to solution
06-08-2018 07:40 AM
rajujee
New Contributor III

Thanks Rob and Rebeca for always being helpful. I am looking for a widget in WebAppBuilder that performs following functionality on widgt launch (click).

  1. Get current map location(lat,long) and scale

Send to a URL e.g. http://MyServer/MyMapApplication/default.aspx?lon=--80.203&lat=43.035&zoom=15

 

Is there a widget already available that has built in functionality? Is there a sample widget you could provide.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Raju,

   You can modify the URL Button widget for this purpose:

///////////////////////////////////////////////////////////////////////////
// Copyright © 2018 Robert Scheitlin. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////

define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'jimu/BaseWidget',
    'jimu/WidgetManager'
  ],
  function(
    declare,
    lang,
    BaseWidget,
    WidgetManager) {
    var clazz = declare([BaseWidget], {

      name: 'UrlButton',
      baseClass: 'widget-urlbutton',
      isOpening: false,

      onOpen: function(){
        if(!this.isOpening){
          this.isOpening = true;
//RJS ADD
          var mapCeneter = var lat = this.map.extent.getCenter();
          var lat = mapCeneter.getLatitude();
          var lon = mapCeneter.getLongitude();
          var level = this.map.getLevel();
//RJS End Add
//RJS Edit
          window.open(this.config.LinkUrl + "?lon=" + lon + "&lat=" + lat + "&zoom=" + level, "_blank");
//RJS End Edit
          setTimeout(lang.hitch(this, function(){
            this.isOpening = false;
            WidgetManager.getInstance().closeWidget(this);
          }), 300);
        }
      }
    });
    return clazz;
  });

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Raju,

   You can modify the URL Button widget for this purpose:

///////////////////////////////////////////////////////////////////////////
// Copyright © 2018 Robert Scheitlin. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////

define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'jimu/BaseWidget',
    'jimu/WidgetManager'
  ],
  function(
    declare,
    lang,
    BaseWidget,
    WidgetManager) {
    var clazz = declare([BaseWidget], {

      name: 'UrlButton',
      baseClass: 'widget-urlbutton',
      isOpening: false,

      onOpen: function(){
        if(!this.isOpening){
          this.isOpening = true;
//RJS ADD
          var mapCeneter = var lat = this.map.extent.getCenter();
          var lat = mapCeneter.getLatitude();
          var lon = mapCeneter.getLongitude();
          var level = this.map.getLevel();
//RJS End Add
//RJS Edit
          window.open(this.config.LinkUrl + "?lon=" + lon + "&lat=" + lat + "&zoom=" + level, "_blank");
//RJS End Edit
          setTimeout(lang.hitch(this, function(){
            this.isOpening = false;
            WidgetManager.getInstance().closeWidget(this);
          }), 300);
        }
      }
    });
    return clazz;
  });
rajujee
New Contributor III

I am looking to get map extent (minX, minY, maxX, maxY). I am getting type error in the widget (. Could you please guide

  var minxx = this.map.extent.getMinx(); //TypeError: this.map.extent.xMin is not a function

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Raju,

   The extent class does not have a getMinx() function. It is just extent.minx.

0 Kudos
rajujee
New Contributor III

Thanks Rob. could you please help why i am not getting extent (xmin, xmax, ymin, ymax) in other format (xmin: -8897322.107622242, ymin: 5343300.437750983, xmax: -8885092.18309663, ymax: 5348345.281617797).

{wkid: 102100}.

Is there a way to convert into WGS-84 (minx=-79.82269048690796&miny=43.16071271896362&maxx=-

79.71282720565796&maxy=43.24250936508179).

Your help is appreciated.

0 Kudos