Giter VIP home page Giter VIP logo

Comments (2)

eregnier avatar eregnier commented on June 16, 2024 1

hey @shieldcy

let say you have this code (that it try to use from your exemple)

<gmap-custom-marker
    :marker="setMarker(pin.lat, pin.lng)"
    :class="{addzIndex : pin.id == selectedId}"
>
   <yout-custom-component/>
 </gmap-custom-marker>

with your custom component like below :

<template>

    <div
      :ref="'marker_el_'+pin.id"
      class="mapmarker"
      tabindex="0"
      @click="toggleBox(pin.id)"
    >
      <div class="price">
        <span class="text">
          €{{ pin.text }}
        </span>
      </div>
      <div
        v-if="selectedMapListing == pin.id"
        class="box"
      >
        <div v-if="pin" class="thumbnail">
          .....
        </div>
        <div class="detail">
          .....
        </div>
      </div>
    </div>
</template>
<script>
export default {
    mounted() {
        console.log('the map item', this.$parent.$map)
        // Do some computation with the map object
    }
}
</script>

Then it should be possible to compute your panel location depending on map information (this is google an underlaying map object you have to study) and compare it to your marker position then choose to move left or right some content of the custom marker (maybe making it larger and use relative / absolute positions)

I never had to do this but I would do it this way (maybe I am naive) the first time.

Is it clear enough or do you need something else ?

Eric

from vue2-gmap-custom-marker.

shieldcy avatar shieldcy commented on June 16, 2024

Thanks for your reply @eregnier

What I did in case anyone is interested (I am not sure if this is a good solution but it works):
I used a "ref" as eregnier mentioned above. And checked the position of the parent element to the child element
Parent element = whole map (mapPos)
Child element = marker popup box (popupPos)

toggleBox (id) {
  // clearing the classes before re-adjusting
  this.$refs['marker_el_' + id][0].classList.remove('adjustTop')
  this.$refs['marker_el_' + id][0].classList.remove('adjustLeft')
  this.$refs['marker_el_' + id][0].classList.remove('adjustRight')
  
  // get the positions
  let mapPos = this.$refs['map'].getBoundingClientRect()
  let popupPos = this.$refs['marker_el_' + listingId][0].getBoundingClientRect()
  let position = {}
  position.top = popupPos.top - mapPos.top
  position.right = popupPos.right - mapPos.right
  position.left = popupPos.left - mapPos.left
  
  // set the classes (the numbers used below are what I wanted based on the position of my map and popups
  if (position.top <= 350) {
    this.$refs['marker_el_' + id][0].classList.add('adjustTop')
  }
  if (relativePos.left <= 150) {
    this.$refs['marker_el_' + id][0].classList.add('adjustLeft')
  }
  if (relativePos.right >= -150) {
    this.$refs['marker_el_' + id][0].classList.add('adjustRight')
  }
}

And in css I set position absolute to the marker popup

.adjustTop {
  top: 0px !important;
  position: absolute;
}

.adjustLeft {
  left: 0px !important;
  position: absolute;
}

.adjustRight {
  right: 0px !important;
  position: absolute;
}

from vue2-gmap-custom-marker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.