GithubHelp home page GithubHelp logo

Custom marker dynamically about vue-googlemaps HOT 8 CLOSED

akryum avatar akryum commented on May 20, 2024 2
Custom marker dynamically

from vue-googlemaps.

Comments (8)

thanhthaohoang avatar thanhthaohoang commented on May 20, 2024 2
const options = await Object.assign(this.opt, {
 position: this.marker.position,
  icon: {
     url: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png',
     scaledSize: new window.google.maps.Size(25, 32)
  }
}, this.$props)

In your code, position can take the value of the position prop that you stated earlier. Indeed, when you'll change the value of the position prop from your parent component, the position of your marker will be updated too I think.

from vue-googlemaps.

thanhthaohoang avatar thanhthaohoang commented on May 20, 2024 1

Hi @ulises58 !
In my parent component, I send a prop called marker to my child component marker-places. That prop contains an object with a key position with coordinates values.
In the child component, I'm just attributing the sent position in the optionsconstant when the map is ready.
I don't know if it answers your question 😬

from vue-googlemaps.

ulises58 avatar ulises58 commented on May 20, 2024 1

Hi, thank you very much, I realized what my mistake was. Which is here

   const boundProps = [
        'animation',
        'clickable',
        'cursor',
        'position'
    ]

the position property was missing
thanks for your time @thanhthaohoang

from vue-googlemaps.

thanhthaohoang avatar thanhthaohoang commented on May 20, 2024 1

@ulises58 Glad that I helped and that you found the solution on your own !

from vue-googlemaps.

ulises58 avatar ulises58 commented on May 20, 2024

hello how I'm starting to work with the modified markers, I have a question how do you actuate the position of the marker? @thanhthaohoang

from vue-googlemaps.

ulises58 avatar ulises58 commented on May 20, 2024

Hello @thanhthaohoang , I think I did my question wrong, how to update the position of the marker after it was created for the first time?

<custom-marker
                v-for="(marker, index) of markers"
                :key="marker.id"
                :marker="marker"
                :position = "marker.position"
            >

Is this the correct way in which I must send to update the position?

I am using the same component markerPlaces code.

I am very new to this, thank you very much for your help. I know my question is very silly but I see that you have done it in a very good way.

from vue-googlemaps.

thanhthaohoang avatar thanhthaohoang commented on May 20, 2024

@ulises58 To update the marker position, you can change the value of marker.position that you send as a value prop in your child component custom-marker. Did you try this before ?

from vue-googlemaps.

ulises58 avatar ulises58 commented on May 20, 2024

@thanhthaohoang 0.0 Don't you mean something like this?

props: ['marker','position'],
       // When Google Maps is ready
       async googleMapsReady () {
           //https://pastebin.com/VYMCvS9m
           console.log(this.marker.position)
           const options = await Object.assign(this.opt, {
               position: this.marker.position,
               icon: {
                   url: 'https://maps.google.com/mapfiles/kml/shapes/parking_lot_maps.png',
                   scaledSize: new window.google.maps.Size(25, 32)
               }
           }, this.$props)

           options.map = this.$_map

           // Create Google Maps objects
           this.$_marker = new window.google.maps.Marker(options)
           // Bind the Vue props
           this.bindProps(this.$_marker, boundProps)
           // Emit the events from Google Maps
           this.redirectEvents(this.$_marker, redirectedEvents)
       },

from vue-googlemaps.

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.