is there a way to, w/ google maps v3, listen to an event that will indicate a groundoverlay asset has been loaded? I'm loading an image onto the map and would like to be notified when the asset has completed downloading and has been presented to the client. Any ideas?
As of 2021 Dec, I can confirm that #Trott idle event will NOT work at all.
idle event fired early before any ground overlay image even start loading.
see this example
https://transparentgov.net:3200/googlemaps111/default?layer_id=7&layer=Zoning_Merge¢er_lat=33.721999270778305¢er_long=-116.28975468931803¢er_zoom=17&url=https%3A%2F%2Fgis.la-quinta.org%2Farcgis%2Frest%2Fservices%2FPlanning%2Fzoning1%2FMapServer&panto=0
However, in another post, I post a working example
The idea is you need use create a html image object,
new Image()
then set source let it downloading image
image.src
Then attach event
image.onload = function
The whole working source code is here
The working example is here
https://transparentgov.net:3200/googlemaps12/default?layer_id=0&layer=SilverRock_MasterPlan_29Nov2016_s200-images.jpg¢er_lat=33.65789936781538¢er_long=-116.25862990762825¢er_zoom=15&url=https%3A%2F%2Fgis.la-quinta.org%2Farcgis%2Frest%2Fservices%2FCommunity_and_economic%2FSilver_Rock_Master_Plan%2FMapServer&panto=0&overlayOpacity=8&overlayType=overlayType_image
A straight reading of the Google Maps API v3 documentation would seem to suggest that this wouldn't work, but I've managed to do this using the idle event with addListenerOnce(). (If that doesn't work for you, edit your question to show the code you tried and we'll see if we can get it working.)
The idle event seems to fire exactly once as a way of sort of saying "map is loaded and ready to go" even though the documentation seems to suggest that a pan or zoom needs to happen to trigger it.
Since this is (to my knowledge) undocumented behavior (at least in any official documentation), it runs the risk of suddenly not working one day when the API is updated. You can make the choice to either live with that risk or try to guard against it by specifying the version of the API that you want in your <script> tag that loads the API.
Related
In my Google Maps app the user can search for a place (using Autocomplete) and the map will be re-centered upon it with map.setCenter(pos);.
This does not change zoom level though, that must be done manually with map.setZoom(x).
In Google's map, zoom automatically readjusts to perfectly show the place's boundaries, how can I replicate that behavior?
The duplicate #woelliJ found almost worked, but ended up using an old version of the API. It led me on the right track though, and I ended up finding how to make it work with the new API - map.fitBounds(autocomplete.getPlace().geometry.viewport);
I am using the platform Ushahidi Web-2.7.3 , see: http://ti5.net.br/provedorlegal.com.br, and when I zoom in beyond a certain level, the clustered markers disappear from the map. I also tested this on an older version of a site, see: http://movimentofichalimpa.org/mapa, where the clustered markers do not disappear on zooming in, but just become ungrouped, as is normal with a cluster strategy. How can I make the markers remain on the map when zooming in?
Ushahidi actually uses OpenLayers under the hood -- the images may come from Google, but the Javascript library is pure OpenLayers. These markers are actually generated by adding what is known as a context to the style attribute of the OpenLayers.Layer.Vector and an associated Cluster.Strategy. There is a good example of it working properly here: OpenLayers cluster example and if you look at the Javascript source you will see how it is done: view-source:http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/strategy-cluster-threshold.html by defining a radius in the context of the styleMap.
The reason that your example isn't working is that there is actually a script error being triggered, which is stopping the clustering/styling from being performed. The styles are defined in the file ushahidi.js. If you open a Javascript debugger you will see the error for yourself that is firing before the ushahidi.js functions are called to determine the number of features in the cluster and therefore the radius of the markers.
The actual error is http://ti5.net.br/provedorlegal.com.br/index.php/json/cluster?s=1401591600&e=1404183599&z=9, but I have no idea why, as the OpenLayers is the minified version which is very hard to debug. You might find moving your application to OpenLayers directly will help, as it will be easier to debug, and it also works on mobiles, which I know is one of the reasons people like to use Ushahidi.
I am using Google Maps JavaScript API v3 with a KML layer to display a map with custom markers.
My map links to the KML file I published as a Google Site attachment. Once loaded, the map shows each of the PlaceMarks from the KML file correctly, but will not display the popup balloons.
Rarely when I click a pin it shows the balloon (5% of the time), then none of the other pins work. When I zoom in and out my custom pin images sporadically revert to the default pin image.
I added the layerOptions to explicitly set clickable to true and suppressInfoWindows to false. It didn't change the balloon behavior.
I have tested with Chrome v19, Firefox v12, and IE8.
Update 1:
I found a typo in my KML, (bal*l*oon). Still not working right. Something is making the pins buggy.
Update 2:
v3 is now working. Google's caching made this difficult to test. Added '?nocache=0' to KML URL to prevent caching. BaloonStyle was the problem, but caching caused the typo to remain. Migrating KML to personal server.
Live HTML Map Page (Fixed)
Live KML Download (Fixed)
My references:
http://developers.google.com/maps/documentation/javascript/reference
http://ge.images.alaska.edu/workshop/advanced.htm
Google is caching your KML on purpose. The workaround is to append something like the current time to the end of your URL so that it is different every time:
var kmlFile = 'http://www.myserver.com/my.kml?'+(new Date()).getTime();
var kmlLayer = new google.maps.KmlLayer(kmlFile);
kmlLayer.setMap(myMap);
My problems:
A typo in my BalloonStyle tag
A stale cache of my KML file
This would have been easier if:
Google Maps JS threw errors when parsing KML
Google caching was reasonably fast
I started testing on a server
Update:
I moved the KML file to my server, but the cache remained stale after the first change. It seems the caching occurs when my Google Map object loads the KML overlay. I made sure it was not my system or my server caching.
The pins start acting buggy if I make a change to my KML and the cache doesn't update. All my pins show in the correct location, but one of the pins won't have a balloon. Changed the file name, works fine!
Update 2:
I reported this caching behavior as a bug on Google Maps JS API.
http://code.google.com/p/gmaps-api-issues/issues/detail?id=4196
Conclusion:
I wrote the ASP.NET/C# class to geocode addresses and build the KML doc in less time than it took to find this error.
Stop caching so hard Google!
Your KML is invalid. <Name> is not part of the spec. Change it to <name> and you should be good to go.
This is driving me crazy. I've been developing some simple embedded Google Maps such as the following:
http://publicworks.snoco.org/rdclosures/snocordclosuregmaps.html
This map in particular has several kml overlays but one of them is no longer displaying the custom placemark icons I had developed and specified. The problem KML layer is this:
http://publicworks.snoco.org/RdClosures/SnocoRdClosures4Gmaps.kml
Some time in the last few months, the custom symbols stopped displaying and have been replaced by the default placemark symbol. If you open the KML file in Google Earth, it displays properly. The KML file does validate using KmlValidator.
Through my searches on here, I saw a suggestion about using definitions at the top of the KML file and then using within each Placemark. I made that change to my KML but it did not appear to make any difference (the custom icons are still not displaying).
I realize that KML files get cached on Google's end so if you look at my javascript code, I'm using the dummy parameter trick with my KML URL path to force a refresh of the layer. The other thing I will note is that the content of this KML is not static and it frequently changes.
Any ideas? Because I'm stumped!
THANKS!
Steve
Agreed with fragileninja that something is happening with your images between your server and Google's. The usual suspects are timing out and 404s (or other server errors).
Since the KML layer is actually being rasterized to tiles on Google's servers, the request has a relatively short timeout so the tiles aren't delayed from being sent to the browser. If the icon images aren't returned in that time, usually Maps will render using the default icon (as it's doing here). However, I also have no trouble getting the icons to work when I host them on my own server, and I don't see atrocious loading times when I access your icons directly, so it is strange.
It's possible that your servers are taking a longer than usual time to respond to Google's servers specifically, or even that they're returning some HTTP error to them instead of an image.
Can you check your server logs to see if you can see the requests and if they're returning as expected?
Finally, if there's no problem there, I would suggest filing a bug on the Maps API issue tracker. Make sure to pick the appropriate template from the dropdown list (you might also consider making a simpler test case, like just using your KML file with the KmlLayer example from the docs) . If you do end up filing a bug, please link it here and I'll make sure it's looked at.
It's something to do with how your server is serving up the images. If I host the icons on mine, it works fine, and your other KML files are using icons from maps.google.com, which also works fine.
Since it works in GE, I'm guessing maybe your server is sending the wrong MIME type or something along those lines. I checked with curl and everything looks fine though, so I'm afraid I can't offer any more details than that. Hopefully this helps get you in the right direction. Good luck!
I am using the Google Maps Control for ASP.Net. I am adding one point which is current point of bus & polyline of the points from current point to last 10 points on the page load with showing popup on current point by default.
I am using update panel for the the refresh button. There is also one input field which takes number of record to show on polyline from current point. Now I want to reset my googlemapObject on refresh button click event so that in every refresh click completely new set of points, polylines should add and shown on google map.
Is there is any method like dispose to dispose current object of goolemap.
How to resolve this problem?
Regards,
Girish
I'm assuming that you are using the Google Maps Control for ASP.NET found at:
http://en.googlemaps.subgurim.net/
If that is the case - there is an example found on their site that will walk you through how to erase icons that are added to the map.
The sample code can be found right here:
http://en.googlemaps.subgurim.net/ejemplos/ejemplo_99000_Custom-Javascript.aspx
By implementing a custom Javascript Event you will be able to change the data on your map with the refresh button - without needing to do a whole page refresh.