0

I'm having a bit of trouble translating something that works in the options api to the composition api. I'm not really sure how to do the equivalent and maybe I'm just thinking about it the wrong way.

This works for me using the options api:

<template>
<div id="viewDiv">
  </div>
</template>
<script lang="ts">
import { loadModules } from 'esri-loader';
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'web-map',
  el: '#viewDiv',
  methods: {
    async loadMap() {
      const [
        WebMap,
        ArcGISMap,
        MapView, 
        Portal, 
        OAuthInfo, 
        esriId
      ] = await loadModules(['esri/WebMap', 'esri/Map', 'esri/views/MapView', 'esri/portal/Portal',
        'esri/identity/OAuthInfo', 'esri/identity/IdentityManager'], { css: true });

    const map = new ArcGISMap({
      basemap: 'streets'
    });

    const view = new MapView({
      container: this.$el,
      map: map,
      center: [-118, 34],
      zoom: 8
    });
    }
  },

  async mounted() {
    this.loadMap()
  },
});

</script>

You see that the container gets set to this.$el.

My current attempt using setup() looks like this:

<template>
<div ref="viewDiv">
  </div>
</template>
<script lang="ts">
import { loadModules } from 'esri-loader';
import { defineComponent } from 'vue';
import { h, ref, onMounted, reactive } from 'vue'

export default defineComponent({
  name: 'web-map',
  setup() {
    const viewDiv = ref(null);
    async function loadMap() {
      const [
        WebMap,
        ArcGISMap,
        MapView, 
        Portal, 
        OAuthInfo, 
        esriId
      ] = await loadModules(['esri/WebMap', 'esri/Map', 'esri/views/MapView', 'esri/portal/Portal',
        'esri/identity/OAuthInfo', 'esri/identity/IdentityManager'], { css: true });

      const map = new ArcGISMap({
        basemap: 'streets'
      });

      const view = new MapView({
        container: viewDiv,
        map: map,
        center: [-118, 34],
        zoom: 8
      });
    }

    onMounted(async() => {
      loadMap();
    });

    return {viewDiv}
  }
});

</script>

At the moment, of course, nothing renders.

It feels like the problem should be obvious, haha. I appreciate any help, guidance, tips. I'm using a template in the example, but if this is more easily accomplished with a render function/if that's a better practice I'd like to know.

Thanks!

TapeHead
  • 120
  • 7
  • 1
    please check this https://stackoverflow.com/a/65657499/8172857 – Boussadjra Brahim Jan 17 '21 at 16:55
  • Thank you! If I change "container: viewDiv," to "container: viewDiv.value", I can see something gets updated but nothing is actually showing on the screen. – TapeHead Jan 17 '21 at 22:46
  • Okay, so if I also change: '
    ' to '
    ' it applies the scoped style which in turns allows it to display (there was no height before). Is this the correct way to approach the problem? Is it okay to have both 'ref' and 'id' properties?
    – TapeHead Jan 17 '21 at 23:16

0 Answers0