How to add a draggable circle?
See original GitHub issueHey 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>
);
}
Issue Analytics
- State:
- Created 8 years ago
- Comments:10
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.please someone create a full documented example for draggable markers