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.

How to add a draggable circle?

See original GitHub issue

Hey there! I’m using google-map-react with GeoFire and need to implement a draggable circle as in this demo.

I didn’t see any documentation on doing something like this, so decided to try to use the Google Maps API directly. The circle shows up and the hand cursor changes to a pointer when hovering over it, but unfortunately, once I start dragging, the entire map is dragged rather than just the circle. Is there a workaround for this? (example code and screenshot below).

Thanks for the help and for making this great component!

Best, -Jedidiah

  initDraggableCircle({ map, maps }) {
    let circle = new maps.Circle({
      strokeColor: '#6D3099',
      strokeOpacity: 0.7,
      strokeWeight: 1,
      fillColor: '#B650FF',
      fillOpacity: 0.35,
      map: map,
      center: new google.maps.LatLng(...this.props.mapConfig.center),
      radius: this.props.mapConfig.radius * 1000,
      draggable: true
    });
    maps.event.addListener(circle, 'drag', ::this.onCircleDragged);
  }
  render() {
    return (
      <div>
        <h2>Welcome to the map!</h2>
        <div style={{height:"500px"}}>
          <GoogleMap center={this.props.mapConfig.center}
                     defaultZoom={this.props.mapConfig.zoom}
                     onGoogleApiLoaded={::this.initDraggableCircle}
                     yesIWantToUseGoogleMapApiInternals={true}>
            {this.geofireMarkers()}
          </GoogleMap>
        </div>
      </div>
    );
  }

image

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10

github_iconTop GitHub Comments

8reactions
kjeskecommented, Jul 4, 2016

@kad3nce I see you’ve created MapCircle component. How do you get there the map reference to apply the circle on it? Maybe you could post your implementation for that component, it might be useful.

6reactions
hemedanicommented, Mar 7, 2017

please someone create a full documented example for draggable markers

Read more comments on GitHub >

github_iconTop Results From Across the Web

Draggable Circle - Happy Coding
This code keeps track of a circle's position and size, and then uses the dist() function to check whether the cursor position is...
Read more >
Add Draggable Circle on Google Maps - techstrikers.com
In this example you will learn how to add draggable circle on google map. Here you can view the output of the example...
Read more >
92. Interactivity: a draggable circle - Fun Programming
To get started we create this program where we can click and drag a circle to a new position. The circle reacts to...
Read more >
create multiple draggable circles in canvas - Stack Overflow
I'm having trouble with making several circles ...
Read more >
Creating draggable circle in Leaflet? - GIS Stack Exchange
To make a circle draggable, you can add an event listener with a method for mousedown and one for click (from what I've...
Read more >

github_iconTop Related Medium Post

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