Google Maps Custom Polygon with image as background and hover effect - html

Is it possible to create a webapp using Google Maps API V3 that uses custom images for countries or regions, that change on mouseover and mouseclick?
I have looked at google.maps.GroundOverlay and ProjectedOverlay but haven't found a solution. An example would be also great. Thank you.

Yes, it's possible..there are a couple ways to do it
One way is to use OverlayView - see demo here Showing/Hiding overlays
From the documentation:
Set the custom object's prototype to a new instance of google.maps.OverlayView(). This will effectively "subclass" the overlay class.
Create a constructor for your custom overlay, and set any initialization parameters to custom properties within that constructor.
Implement an onAdd() method within your prototype, and attach the overlay to the map. OverlayView.onAdd() will be called when the map is ready for the overlay to be attached..
Implement a draw() method within your prototype, and handle the visual display of your object. OverlayView.draw() will be called when the object is first displayed as well.
You should also implement an onRemove() method to clean up any elements you added within the overlay.
After that, you would then need to add an eventListener on the map for the click event for instance to activate this OverlayView, here's an example of how to add a click eventListener on the map https://developers.google.com/maps/documentation/javascript/examples/event-arguments

Related

differentiate between user drag and animateCamera on google maps in flutter

In Flutter and using the google_maps_flutter library (v0.5.28), I'm trying to find a way to capture a user drag/pan and differentiate it from calling animateCamera(...) on the map's controller. Either method equally triggers the map's onCameraMove event.
I've tried layering a GestureDetector over top of it, but the drag/pan won't pass through. **edit - what I really mean is wrapping the map in one, not actually putting one over it in a stack. Sorry.
I've tried adding custom gesture detectors to the map's gestureDetectors collection, but they don't seem to fire when I specifically wire up the onUpdate event to the PanGestureDetector I put in that collection.
Various iterations and customizations to the above.
So, I'm presenting this question with the listed qualifications:
How do I capture a user's panning the google maps widget, separating the resulting event so I can easily determine that it's a user pan versus camera animation, or even handle it completely independently?
Ultimately, I just want to capture the user drag, use that to call a setState(...) on boolean flag that I'm using elsewhere.
I fully recognize I've probably overlooked something obvious in all my rat-holing.
Thanks!

Custom layer/overlay in google maps

Is it possible to create custom layers/overlays in google maps?
As an example, would it be possible to have one layer with polygons, another with circles, and a third with markers? and then hide/show these layers individually?
I tried looking at the documentation, but the layers seems to only be a fixed set of predefined layers. And overlays seems to only support image overlays.
Any help on this is appreciated.
I'm not sure if there exists a better way to do this, but I've found a workaround to a similar problem. My example utilizes markers and polylines, but it should be easy to extend the functionality to circles and polygons too.
Link to JSFiddle
Basically it works like this:
Initialize the map.
User selects an option what he would like to see on the map.
Click triggers a method (see HTML part of the fiddle) in the map object that first clears the map and then pushes new overlays on map.
The data that is currently shown on map is stored in arrays, and the map clearing method simply goes through these arrays and checks if there exists any content on map, and removes them if does.
Hope this helps. Cheers!

What method to call to update my overlay view in google map?

I've defined an overlay (implementing OverlayView) and after defining my overlay, I need to update some content in overlay. But it doesn't take effect unless I move the map.
What method to call so my overlay updates without moving the map? Is there a update/render method to update the view?
You can call the draw() function on the OverlayView, see the reference for more info.
I resolved the issue by using setMap(null) for removing the overlay and then redraw the complete overlay.

Is there a way to find all Overlays attached to a map?

I have a gmap object that is created by a JSF components (PrimeFaces p:gmap) and it might have some Overlays (Markers) attached to it. So my own client-side javascript doesn't have a direct reference the Overlay objects.
Is there some way where I can get a collection of all the Overlays currently painted on a map?
with v3 of the Maps API, no. There is no documented method to do this.
A internal array somewhere might hold it, but you couldn't rely on it ( and its obfuscated short name would change with each release).

Effects and animations with Google Maps markers

I would like to know how to create effects / animations over Google Maps markers. Specifically, I would like to zoom-in/out or "fade" a marker after a given amount of time. Could it be possible with HTML5 ? Is there any jquery effect library for doing this?
(I could use a map tile server for creating map tile overlays and re-generate tile overlays every second, but I guess it is very processing-intensive...)
Thanks in advance
I haven't seen any library to do this, and there isn't functionality in the API to fade Markers per say.
Instead, what you can do is simulate markers by creating your own Custom Overlay that looks like a marker. A custom overlay usually contains a div, which you can easily control the opacity of using JavaScript / jQuery based on a class or id you assign during the custom overlay construction.
As an example, if you look at this page you can see the is a button used to toggle the visibility, you could just as easily change that JavaScript to control the opacity of something.
I am looking at doing something similar.
If you set the marker option 'optimized: false' for all markers, each will have its own element, you can then use jQuery to select all the markers on your map using something along the lines of $('#map_canvas img[src*="filename"]'), assuming that you're using custom images for the markers.
What this doesn't address is relating each element in the array returned to a specific marker.
I think that you could add the markers to the map one at a time, re-run the jquery selector, and compare the elements returned vs. the previous run, to see which element was new. I haven't tested this part (I have what I say in the first paragraph), as I'm working towards something slightly different.
You should then be able to adjust the opacity/size of the image directly.
This might get clunky for large numbers of markers.
Paragraph two above is stupid.
Add a marker to the map, making sure to set the optimized:false option. then
var freshlyAddedMarkerImage = $('#map_canvas img[src*="your_marker_icon"][class!="adjustMe"]');
The newly added marker won't have the class, so will be the only element selected. Before setting the className, you could set an ID, add the element to an array in the same index position as the corresponding marker object is held in another array, etc.
This should be a lot less clunky to implement than what I proposed previously. I'll try and come back with a working example soon.
I suppose if you knew that there were groups of markers that would share the same transform (zoom/fade), due to being the same age or whatever, then you could add all of them and only do the jQuery select at the end, before looping through the returned elements setting a class that would allow you to adjust them en-masse.