question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Popup withou marker not work

See original GitHub issue

I want to show popup in custom place of map by click event. For this I write:

<MglMap ...>
 <MglPopup>
 </MglPopup>
 <!-- Some layers... -->
</MglMap>

and then set popups prop ‘showed’ to true, but popup don’t showing.

I try place popup in market, in it showing!!!

<MglMap ...>
 <MglMarker>
  <MglPopup>
  </MglPopup>
 </MglMarker>
 <!-- Some layers... -->
</MglMap>

Why popup don’t show without marker??

P.S.: Sorry for my English.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:13

github_iconTop GitHub Comments

4reactions
gorbyparkcommented, Feb 16, 2020

It’s working for me with the above code. It’s pretty weird, as I tried to create a codesandbox to prove that it’s working, and it is not working there using the exact same code! I’m pretty stumped at how I managed to do it. The only thing that would be different is that I’m using nuxt…but that still doesn’t really make sense. edit It turns out I’m using the development version since I cloned the repo and made a small unrelated change to the code already, so that explains that. For future lurkers, it’s pretty easy. Instead of doing yarn add vue-mapbox, just do yarn add https://github.com/soal/vue-mapbox.git and you’ll have the development version.

2reactions
gorbyparkcommented, Feb 16, 2020

@schellenbergk @vinayakkulkarni If you add something like @mousemove="onMapMouseMoved" to <MglMap ref="mglmap"> and then in methods have something along the lines of

onMapMouseMoved(e) {
  const features = this.$refs.mglmap.map.queryRenderedFeatures(e.mapboxEvent.point)
  if (features.length && features[0].layer.id === 'vector-layer') { // vector-layer is the id of your layer
    this.popup.coordinates = [
      e.mapboxEvent.lngLat.lng,
      e.mapboxEvent.lngLat.lat
    ]
    this.popup.showed = true // show the popup
    this.$refs.mglmap.map.getCanvas().style.cursor = 'pointer' // changes the mouse to a pointer
  } else {
    this.$refs.mglmap.map.getCanvas().style.cursor = '' // changes mouse back to standard
    this.popup.showed = false // hide the popup when mouse not over layer
  }

You’ll need to add <MglPopup> as well

<MglPopup
  :coordinates="popup.coordinates"
  :showed="popup.showed"
  anchor="top"
>

your data section should look something like this

data() {
  return {
      popup: {
        coordinates: [-122.9, 50.1], // this can't be blank!  it won't be shown but pick something
        showed: false,
        content: `stuff will go here, hopefully`
      }
  }
}

It works just like the stock mapbox gl works, the only thing is you need to use e.mapboxEvent instead of just e like all the examples show! That took a while to figure out.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Changing anchor point for popup without marker using ...
These popups opens when I click on a marker, but now I just want a simple popup to be visible when the map...
Read more >
How can I prevent a popup to show when clicking ...
What is the right way to prevent a popup from showing without using the clickable : false property of the marker object? All...
Read more >
Leaflet for R - Popups and Labels
You can create labels without the accompanying markers using the addLabelOnlyMarkers function. The "leaflet" R package is copyright © 2014-2016 RStudio, Inc.
Read more >
Problem cookie popup marker
1) Const is invalid. I should be const . Function is wrong. It needs to be function . Button is wrong. It needs...
Read more >
Pop up always visible without clicking on the marker in leaflet
Pop-up cannot be enabled by default. Another way is to keep the pop up from closing when pressed on the map or other...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found