bariskau
bariskau

Reputation: 337

Remove image overlay layer in Leaflet

I'm trying to place a sketch on a building on the map with Leaflet. I succeeded in this as well, I can place and scale an image in svg format on the map. But when I add a new sketch to the map, I want the old sketch to be deleted from the map.

    map.removeLayer(sketchLayer)
    sketchLayer.removeFrom(map)
    map.removeLayer(L.sketchLayer)

i tried these

My codes,

 splitCoordinate (value) {
      const topLeftCoordinates = value.top_left.split(',')
      const topRightCoordinates = value.top_right.split(',')
      const bottomLeftCoordinates = value.bottom_left.split(',')
      this.initMap(topLeftCoordinates, topRightCoordinates, bottomLeftCoordinates)
    },
    initMap (topLeftCoordinates, topRightCoordinates, bottomLeftCoordinates) {
      let map = this.$refs.map.mapObject
      map.flyTo(new L.LatLng(topLeftCoordinates[0], topLeftCoordinates[1]), 20, { animation: true })
      const vm = this
      var topleft = L.latLng(topLeftCoordinates[0], topLeftCoordinates[1])
      var topright = L.latLng(topRightCoordinates[0], topRightCoordinates[1])
      var bottomleft = L.latLng(bottomLeftCoordinates[0], bottomLeftCoordinates[1])
      var sketchLayer = L.imageOverlay.rotated(vm.imgUrl, topleft, topright, bottomleft, {
        opacity: 1,
        interactive: true
      })
      map.addLayer(sketchLayer)
    }

Upvotes: 1

Views: 848

Answers (1)

bariskau
bariskau

Reputation: 337

Fix: The error was related to the javascript scope. I defined the sketchLayer in the data and my problem solved.

Upvotes: 1

Related Questions