Select to view content in your preferred language

LocalLayer - Apply definitionExpression by Url parameters and zoom to the new map extent

4090
10
06-07-2016 03:11 AM
NatashaManzuiga
Regular Contributor

Hi All, using LocalLayer widget, is it possible to pass Url Parameters and use them to apply definitionExpression at startup and then zoom to the new extent..?

And then is it possible to set the default map extent ?

Thanks,

Naty

10 Replies
RobertScheitlin__GISP
MVP Emeritus

Naty,

   The LL widget does not provide any URL parameters that can be used. The URL parameters that are supported are the one that WAB lists.

Use URL parameters—Web AppBuilder for ArcGIS | ArcGIS

So No to the definition expression for a layer and Yes to the maps extent.

NatashaManzuiga
Regular Contributor

Robert, I applied setLayerDefinitions using the config of the LocalLayer Widget.

Now I'm trying to set the map extent and to zoom to the new extent...but the following code doesnt work.

            lLayer.setLayerDefinitions(layerDefinitions);

              var allGraphics = [];

              array.forEach(this.map.graphicsLayerIds, function(graphicLayerId){

                  allGraphics = allGraphics.concat(this.map.getLayer(graphicLayerId).graphics);

              });

              var myFeatureExtent = graphicsUtils.graphicsExtent(allGraphics);  

Thanks,

Naty

RobertScheitlin__GISP
MVP Emeritus

Naty,

  What do you mean it does not work? I do not see any code where you are using the myFeatureExtent.

0 Kudos
NatashaManzuiga
Regular Contributor

Robert, I wanted to do something like this.

           var allGraphics = [];
          array.forEach(this.map.graphicsLayerIds, function(graphicLayerId){
              allGraphics = allGraphics.concat(this.map.getLayer(graphicLayerId).graphics);
          });
         var myFeatureExtent = graphicsUtils.graphicsExtent(allGraphics);
         this.map.initialExtent= myFeatureExtent.expand(1.2); 
         this.map.zoomToInitialExtent();

but I get this error...

fail to startup widget LocalLayer. .cache["esri/graphicsUtils"]/</h.graphicsExtent@http://localhost:7001/test/arcgis_js_v316_api/arcgis_js_api/library/3.16/3.16/init.js:1477:121

clazz<.startup/<@http://localhost:7001/test/widgets/LocalLayer/Widget.js:166:36

Thanks,

Naty

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Naty,

So I assume you have added the esri/graphicsUtils require to the Widgets.js? I am really not sure here as I have never had a need to do this.

0 Kudos
NatashaManzuiga
Regular Contributor

Yes, I added the esri/graphicsUtils...

/*global define, window, dojo*/

define([

    'dojo/_base/declare',

    'jimu/BaseWidget',

    'esri/graphicsUtils',

    'jimu/ConfigManager',

    'jimu/MapManager',

    'jimu/utils',

    'esri/urlUtils',

    'dojo/_base/lang',

    'dojo/_base/array',

    'dojo/_base/query',

    'dojo/topic',

    'dojo/aspect',

    'jimu/LayerInfos/LayerInfos',

    'esri/geometry/webMercatorUtils',

    'esri/layers/ArcGISDynamicMapServiceLayer',

    'esri/layers/ArcGISTiledMapServiceLayer',

    'esri/layers/FeatureLayer',

    'esri/layers/WebTiledLayer',

    'esri/layers/ImageParameters',

    'esri/dijit/BasemapGallery',

    'esri/dijit/BasemapLayer',

    'esri/dijit/Basemap',

    'esri/basemaps',

    'esri/dijit/PopupTemplate',

    'esri/symbols/jsonUtils',

    "esri/symbols/TextSymbol",

    "esri/layers/LabelClass",

    "esri/Color",

    'dojo/domReady!'

  ],

  function(

    declare,

    BaseWidget,

    graphicsUtils,

    ConfigManager,

    MapManager,

    utils,

    urlUtils,

    lang,

    array,

    query,

    topic,

    aspect,

    LayerInfos,

    webMercatorUtils,

    ArcGISDynamicMapServiceLayer,

    ArcGISTiledMapServiceLayer,

    FeatureLayer,

    WebTiledLayer,

    ImageParameters,

    BasemapGallery,

    BasemapLayer,

    Basemap,

    esriBasemaps,

    PopupTemplate,

    jsonUtils,

    TextSymbol,

    LabelClass,

    Color)

0 Kudos
NatashaManzuiga
Regular Contributor

Robert, after I applied definitionExpression, I tried with this code:

for (var j=0, jl=mymap.layerIds.length; j<jl; j++) {

            var currentLayer = mymap.getLayer(mymap.layerIds);

            //alert("id: " + currentLayer.id);

          }

        mymap.setExtent(currentLayer.fullExtent);

but it seems like lLayer.fullExtent doesnt change...
after lLayer.setLayerDefinitions(layerDefinitions);

How can I get the new layer extent?

Thanks,

Naty

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Naty,

I think the issue is that you are expecting the layer extent to change based on the definition expression and that is NOT the case the layer extent is static and not affected by the visible layers based on a definition expression. The way you were attempting before getting the graphics and then using graphicsUtils to get the extent of the graphics is the correct route. The problem is likely a timing issue as the LL widget is working with the layers before they are added to the map and thus getting the graphics extent could be an issue until they are added to the map. Like I said before I have not had a need to do this so I can not say for sure, but I think you need to change the maps extent after the layer is added using the layer added event on the map. I think there is code in the LL widget to work with the layer after it is added to the map for some other reason so you would just tag your code into that function.

0 Kudos
NatashaManzuiga
Regular Contributor

Robert, I tried to put the code after

    window._viewerMap.addLayers(_layersToAdd);

but nothing changed...

Thanks,

Naty

0 Kudos