Znacznik ulotki Vue2 nie jest wyświetlany

Nov 25 2020
<template>
  <l-map
    style='height: 500px'
    :center='center'
    :zoom='zoom'
  >
    <l-tile-layer
      :url='url'
      :attribution='attribution'
    >
      <l-marker :lat-lng="test">
        <l-tooltip :options="{ permanent: true, interactive: true }">
          <div>
            I am a tooltip
          </div>
        </l-tooltip>
      </l-marker>
    </l-tile-layer>
  </l-map>
</template>

<script>
import L from 'leaflet';
import {
  LMap, LTileLayer, LMarker, LTooltip,
} from 'vue2-leaflet';

delete L.Icon.Default.prototype._getIconUrl;
L.Icon.Default.mergeOptions({
  iconRetinaUrl: require('leaflet/dist/images/marker-icon-2x.png'),
  iconUrl: require('leaflet/dist/images/marker-icon.png'),
  shadowUrl: require('leaflet/dist/images/marker-shadow.png'),
});

export default {
  data() {
    return {
      url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
      attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
      center: L.latLng(47.41322, -1.219482),
      test: L.latLng(47.41322, -1.219482),
      zoom: 12,
      userLocation: false,
      userCoords: false,
    };
  },
  mounted() {
    if (!('geolocation' in navigator)) {
      return;
    }
    navigator.geolocation.getCurrentPosition(
      (pos) => {
        this.userCoords = L.latLng(pos.coords.latitude, pos.coords.longitude);
        this.userLocation = true;
        this.center = this.userCoords;
      },
      (err) => {
        console.log(err);
      },
    );
  },
  components: {
    LMap,
    LTileLayer,
    LMarker,
    LTooltip,
  },
};
</script>

Oto mój kod, w tej chwili znacznik i podpowiedź w ogóle się nie wyświetlają. Konsola nie wyświetla żadnych błędów i nie wiem, co zrobić.

Zgodnie z dokumentacją występuje problem z niewidocznymi znacznikami, ale z innych problemów, które przeczytałem, wydaje się, że znacznik jest niewidoczny, a wyskakujące okienko / etykietka będzie nadal wyświetlana, jeśli znacznik jest niewidoczny. Po prostu nic nie otrzymuję i nie widzę problemu z kodem.

Próbowałem również użyć niestandardowego obrazu markera, ale daje to ten sam wynik. Nic

Odpowiedzi

1 ghybs Nov 26 2020 at 00:14

Komponent Marker nie powinien być elementem podrzędnym warstwy kafelków, jak pokazano na przykładach Vue2-Leaflet, ale elementem podrzędnym mapy (lub grupy warstw):

https://vue2-leaflet.netlify.app/examples/simple.html

    <l-map
      :zoom="zoom"
      :center="center"
    >
      <l-tile-layer
        :url="url"
        :attribution="attribution"
      />
      <l-marker :lat-lng="withTooltip">
        <l-tooltip>
          <div>
            I am a tooltip
          </div>
        </l-tooltip>
      </l-marker>
    </l-map>