<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Widgets not added when using view.ui.add(widget, placement) in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/widgets-not-added-when-using-view-ui-add-widget/m-p/1162246#M76951</link>
    <description>&lt;P&gt;I am trying to add a legend, home button, and basemap toggle to my basic map UI.&amp;nbsp; I build the widgets and add them with view.ui.add(widget, placement), and although there are no errors there are also no widgets.&lt;/P&gt;&lt;P&gt;I can use view.ui.remove(widget), and it will remove the specified default widget (attribution or zoom), although view.ui.components always reports the two default widgets (no more, no fewer).&lt;/P&gt;&lt;P&gt;There's obviously something basic I'm missing, but it has defied me for a few frustrating days now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Start a new Angular project and create a component:&lt;/P&gt;&lt;PRE&gt;ng new scratch  # Create a new Angular project called "scratch"
cd scratch  # Move into its directory
ng g c map-view  # g_enerate a new c_omponent called "map-view"
npm install @arcgis/core  # Install the arcgis javascript API node module&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;app.component.html:&lt;/P&gt;&lt;PRE&gt;&amp;lt;app-map-view-component style="max-height:600px;"&amp;gt;&amp;lt;/app-map-view-component&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;app.component.css:&lt;/P&gt;&lt;PRE&gt;@import 'https://js.arcgis.com/4.23/@arcgis/core/assets/esri/themes/light/main.css';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;map-view/map-view.component.html&lt;/P&gt;&lt;PRE&gt;&amp;lt;div style="height: 600px;"&amp;gt;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;map-view/map-view.component.ts&lt;/P&gt;&lt;PRE&gt;import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../environments/environment';
import MapView from '@arcgis/core/views/MapView';
import WebMap from '@arcgis/core/WebMap';
import Legend from '@arcgis/core/widgets/Legend';
import BasemapToggle from '@arcgis/core/widgets/BasemapToggle';
import esriConfig from '@arcgis/core/config';
import Home from "@arcgis/core/widgets/Home";

@Component({
  selector: 'app-map-view-component',
  templateUrl: './map-view.component.html',
  styleUrls: ['./map-view.component.css']
})
export class MapViewComponent implements OnInit, OnDestroy {

  @ViewChild('mapViewDiv', { static: true }) private elementRef!: ElementRef;
  private mapView: MapView = new MapView();

  private map!: WebMap;

  constructor() {
    esriConfig.apiKey = environment.apiKey;
  }

  ngOnInit(): void {
    this.initMap().then(() =&amp;gt; {
      this.initWidgets();
    });
  }

  ngOnDestroy(): void {
    if (this.mapView) {
      this.mapView.destroy;
    }
  }

  initMap(): Promise {
    let container = this.elementRef.nativeElement;

    this.map = new WebMap({
      basemap: "arcgis-topographic"
    });

    const view = new MapView({
      container: container,
      map: this.map,
      center: [-95, 46.5],
      zoom: 6,
    });

    const homeButton = new Home({
      view: view,
      id: "home",
    });
    view.ui.add(homeButton, "bottom right");  // Does nothing
    console.log("Added home button");
    console.log(view.ui.components);

    this.mapView = view;
    return this.mapView.when();
  }

  initWidgets() {
    const legend = new Legend({
      view: this.mapView,
    });
    this.mapView.ui.add(legend, "top right");  // Does nothing
    console.log("Added legend");
    console.log(this.mapView.ui.components);

    const bmToggle = new BasemapToggle({
      view: this.mapView,
      nextBasemap: "hybrid",
    });
    this.mapView.ui.add(bmToggle, "bottom right");  // Does nothing
    console.log("Added basemap toggle");
    console.log(this.mapView.ui.components);
  }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Apr 2022 18:25:27 GMT</pubDate>
    <dc:creator>BillMitchell</dc:creator>
    <dc:date>2022-04-07T18:25:27Z</dc:date>
    <item>
      <title>Widgets not added when using view.ui.add(widget, placement)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/widgets-not-added-when-using-view-ui-add-widget/m-p/1162246#M76951</link>
      <description>&lt;P&gt;I am trying to add a legend, home button, and basemap toggle to my basic map UI.&amp;nbsp; I build the widgets and add them with view.ui.add(widget, placement), and although there are no errors there are also no widgets.&lt;/P&gt;&lt;P&gt;I can use view.ui.remove(widget), and it will remove the specified default widget (attribution or zoom), although view.ui.components always reports the two default widgets (no more, no fewer).&lt;/P&gt;&lt;P&gt;There's obviously something basic I'm missing, but it has defied me for a few frustrating days now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Start a new Angular project and create a component:&lt;/P&gt;&lt;PRE&gt;ng new scratch  # Create a new Angular project called "scratch"
cd scratch  # Move into its directory
ng g c map-view  # g_enerate a new c_omponent called "map-view"
npm install @arcgis/core  # Install the arcgis javascript API node module&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;app.component.html:&lt;/P&gt;&lt;PRE&gt;&amp;lt;app-map-view-component style="max-height:600px;"&amp;gt;&amp;lt;/app-map-view-component&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;app.component.css:&lt;/P&gt;&lt;PRE&gt;@import 'https://js.arcgis.com/4.23/@arcgis/core/assets/esri/themes/light/main.css';&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;map-view/map-view.component.html&lt;/P&gt;&lt;PRE&gt;&amp;lt;div style="height: 600px;"&amp;gt;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;map-view/map-view.component.ts&lt;/P&gt;&lt;PRE&gt;import { Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../environments/environment';
import MapView from '@arcgis/core/views/MapView';
import WebMap from '@arcgis/core/WebMap';
import Legend from '@arcgis/core/widgets/Legend';
import BasemapToggle from '@arcgis/core/widgets/BasemapToggle';
import esriConfig from '@arcgis/core/config';
import Home from "@arcgis/core/widgets/Home";

@Component({
  selector: 'app-map-view-component',
  templateUrl: './map-view.component.html',
  styleUrls: ['./map-view.component.css']
})
export class MapViewComponent implements OnInit, OnDestroy {

  @ViewChild('mapViewDiv', { static: true }) private elementRef!: ElementRef;
  private mapView: MapView = new MapView();

  private map!: WebMap;

  constructor() {
    esriConfig.apiKey = environment.apiKey;
  }

  ngOnInit(): void {
    this.initMap().then(() =&amp;gt; {
      this.initWidgets();
    });
  }

  ngOnDestroy(): void {
    if (this.mapView) {
      this.mapView.destroy;
    }
  }

  initMap(): Promise {
    let container = this.elementRef.nativeElement;

    this.map = new WebMap({
      basemap: "arcgis-topographic"
    });

    const view = new MapView({
      container: container,
      map: this.map,
      center: [-95, 46.5],
      zoom: 6,
    });

    const homeButton = new Home({
      view: view,
      id: "home",
    });
    view.ui.add(homeButton, "bottom right");  // Does nothing
    console.log("Added home button");
    console.log(view.ui.components);

    this.mapView = view;
    return this.mapView.when();
  }

  initWidgets() {
    const legend = new Legend({
      view: this.mapView,
    });
    this.mapView.ui.add(legend, "top right");  // Does nothing
    console.log("Added legend");
    console.log(this.mapView.ui.components);

    const bmToggle = new BasemapToggle({
      view: this.mapView,
      nextBasemap: "hybrid",
    });
    this.mapView.ui.add(bmToggle, "bottom right");  // Does nothing
    console.log("Added basemap toggle");
    console.log(this.mapView.ui.components);
  }
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 18:25:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/widgets-not-added-when-using-view-ui-add-widget/m-p/1162246#M76951</guid>
      <dc:creator>BillMitchell</dc:creator>
      <dc:date>2022-04-07T18:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Widgets not added when using view.ui.add(widget, placement)</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/widgets-not-added-when-using-view-ui-add-widget/m-p/1162278#M76952</link>
      <description>&lt;P&gt;Hi there,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Looks like you are missing the dashes (-) from the placement strings.&amp;nbsp;&lt;/P&gt;&lt;P&gt;They should should be `&lt;EM&gt;bottom-right&lt;/EM&gt;`. &amp;nbsp;You can find the placement strings here:&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-ui-DefaultUI.html#add" target="_blank" rel="noopener"&gt;https://developers.arcgis.com/javascript/latest/api-reference/esri-views-ui-DefaultUI.html#add&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Apr 2022 19:42:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/widgets-not-added-when-using-view-ui-add-widget/m-p/1162278#M76952</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-04-07T19:42:26Z</dc:date>
    </item>
  </channel>
</rss>

