vue-leaflet/Vue2Leaflet

LIcon encapsulation breaks $refs

Open

#385 opened on May 1, 2019

View on GitHub
 (9 comments) (0 reactions) (0 assignees)JavaScript (1,942 stars) (380 forks)batch import
bugconfirmedhelp wanted

Description

Description

Steps to Reproduce

  <l-marker
    ref = "marker-container"
    :lat-lng = "[-10, 10]"
  >
    <l-icon
      ref = "icon-container"
      :icon-size = "iconSize"
      :icon-anchor = "iconAnchor"
    >
      <canvas
        ref = "mark-canvas"
        :width = 'iconSize[0]'
        :height = 'iconSize[1]'
        :style = "{
          position: 'absolute',
          left: '0px',
          top: '0px',
        }"
      />
    </l-icon>
  </l-marker>
</template>

Then try to draw into this.$refs['mark-canvas'].

Expected Results

The marker/icon/canvas matches what is drawn to the canvas.

Actual Results

Nothing appears on the canvas. It turns out that there are in fact two canvases, and the visible one is not accessible through $refs as expected (drawing goes to the second, non-visible canvas).

I could access the visible canvas copy with this.$refs['marker-container'].mapObject.getElement().firstChild but is that really the way it is supposed to work (after waiting long enough, in mounted or in $nextTick even that fails)?

Browsers Affected

  • [ x ] Firefox

Probably others too.

Versions

  • Leaflet: v1.3.4
  • Vue: v2.5.18
  • Vue2Leaflet: v2.1.1

Contributor guide