Cache expiration with kml files and google maps - google-maps

I have some dynamically generated KML files that I'd like to display on Google Maps. That's the easy part, I've done it a few times before, no problem.
What I want is for the KML files to only be cached by Google for a request. That is to say, if a person visits a page with a Google Maps embed, which has my KML loaded and displayed, I want that KML file to be used for that page load. But if the user were to refresh the page (having the same Google maps URL), I would like the KML file to be re-fetched.
The simple "just add a timestamp argument" doesn't work, as I'm not going to be in control of the urls passed to Google Maps on the page (just most of the url).
Looking at the <Link> and <networkLink> tags, they seem to let you control expiration, caching, refresh, etc., on an external resource. Reading the documentation, it would seem that using <refreshMode>onChange<refreshMode> to use a two-layered approach will get me what I want.
After testing this, Google isn't actually refreshing the content of the linked KML file, even after 10-20 minutes and multiple maps reloads (when I provide the same url to the Maps search box).
These are the KML files that I am using:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<NetworkLink>
<Link>
<href>URL</href>
<refreshMode>onChange</refreshMode>
</Link>
</NetworkLink>
</Document>
</kml>
...
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<name>NAME</name>
<visibility>1</visibility>
<Style>
STYLE
</Style>
GEOMETRY
</Placemark>
</Document>
</kml>
... With URL, NAME, STYLE, and GEOMETRY replaced with correct content. Does anyone have an idea of what I might be doing wrong? Or if what I want is possible?

This is what I know:
onChange will cache the response completely unless you enable viewport passthrough on the KML loading via <viewFormat>, I've not seen any refresh after several hours.
onExpire with the use of a 'max-age' header on the linked KML file does not work in Google Maps (as per documentation), though I saw behavior described in [1], which could be related to a default internal Google Maps expire time.
onExpire with the use of <NetworkLinkControl> and <expires> sort-of works, in that the data seems to expire after the provided expiration time, though the behavior looked to be closer to [1]
onInterval will refresh the data, assuming your <viewRefreshTime> is sufficiently large, and will do it on its own schedule (the timing isn't reliable in the slightest) but the map view starts zoomed out completely (there doesn't seem to be a way to fix this).
[1] If you specify a 'max-age' of X seconds and you leave the page open, the KML will never refresh while the page has focus. If you move the focus to a different web page or application, then wait until some time well after the page should have refreshed (sometimes waiting 2 minutes is enough, sometimes it's not), and you go back to the page, it may make up to 30 requests in rapid succession to try to refresh the data if you don't return content, or just once if you do return content.
Long story short: cache control of KML files inside Google Maps with onExpire and onInterval is not reliable at all. At some point after your data is loaded, it will be refreshed, because Google's cache has gotten rid of it. But when does that cache expire? Some random time that is at least 5 minutes out.

For expiration, Google follows the expiration time in the headers, but enforces a minimum expiration of 5 minutes to prevent 3rd party servers from getting hit with effective denial of services attacks.

Related

Let search engines know the original image

I have a website with some large images. They are resized by default, but when you click on them, they open in a lightbox and become larger. I'd like to let the search engines know the original (bigger) images, instead of the smaller resize images included in the source code. Is there a way to let them index the bigger images?
You can't decide what google chose to index (but you can make it easier for google using thepiyush13 answer), but you can tell it what NOT to index.
Put this in your robot.txt files :
User-agent: Googlebot-Image
Disallow: /images/myImage.jpg // Put your images or directly the folder
Source : https://support.google.com/webmasters/answer/35308?hl=en
(to be adapted for other search engines)
Image sitemap is the way to go for Google
you can use Google image extensions for sitemaps to give Google more information about the images available on your pages. Image sitemap information helps Google discover images that we might not otherwise find (such as images your site reaches with JavaScript code), and allows you to indicate images on your site that you want Google to crawl and index.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://example.com/sample.html</loc>
<image:image>
<image:loc>http://example.com/image.jpg</image:loc>
</image:image>
<image:image>
<image:loc>http://example.com/photo.jpg</image:loc>
</image:image>
</url>
</urlset>
source : https://support.google.com/webmasters/answer/178636?hl=en

Google maps display customer data in balloons without disclosing it (publicly or to Google)?

I'm trying to create a map of customer locations using Google maps.
It would be very convenient to display customer information in the balloons that pop up when you click a marker. However, some of that data should not be public, and the company would rather not disclose it to Google either.
I have access to (and can set up a server if need be) that runs something server side to generate .kml, Javascript, or serve a web page (including the js in that).
I've thought of a few ways to go about this. First is embedding html in .kml and having the contents of the balloon replaced by JavaScript making an asynchronous request to a private url/server. Unfortunately, it looks like JavaScript is stripped out if you are loading a .kml file by just putting the URL of the .kml file in the search box of google maps. I also found that it seems that iframes are also stripped out. One thing I do not know is if I set up a xhtml page that uses the Google maps API if that would let me load data from a private server directly to the browser without that data being loaded through Google.
One option that appears it will work is just putting a link in the .kml html for the balloon and having that link go somewhere. But that makes a whole extra step to see what the marker is, and diminishes the value of the whole thing in the first place.
So, is there a way to do what I'm attempting to do (load private data into the placemark bubbles directly to the user's browser instead of through Google)? If so, which option is the most maintainable/clean?
With Google's map API, you can write an (x)html page that loads a google map using javascript.
You can then have that javascript load data from a server directly to the browser (in something like JSON or XML) where the javascript can parse it and then add each point to the map. That way, the data does not route through Google's servers.

Display netCDF files to Google Maps

I have some meteorological data wich are exported to netCDF format and I want to display them in Google Maps.
I tried the Panoply software, mainly following these http://marinedataliteracy.org/ops/pano_gridsvecs.htm instructions and succesfully exported the data into .kml files.
The kml file displays fine in Google Earth, but when loading it in Google Maps nothing is being displayed.
The JavaScript code that is loading the kml is definitely correct, because other types of kml are displayed correctly. Just in case, this is the code:
var kmzLayer = new google.maps.KmlLayer("LINK_TO_KML");
kmzLayer.setMap(map);
There is also a project called netcdf2gmaps here http://code.google.com/p/netcdf2gmaps/ but it seems abandoned and there is no feedback for it.
So is there any way to display the netCDF data to Google Maps?
I don't know if you solved your problem, but for reference to question title I thought to add more info.
Panoply (or IDV) export to KMZ (zipped KML) in a manner of simple PNG snapshot of their current display and lon/lat boundaries, like this:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<GroundOverlay>
<name>Maximum_temperature_Maximum_unwe in GEFS_Global_1p0deg_Ensemble_deri</name>
<Icon>
<href>Maximum_temperature_Maximum_unwe in GEFS_Global_1p0deg_Ensemble_deri.png</href>
</Icon>
<LatLonBox>
<west>-29.1622</west>
<north>55.0</north>
<east>49.1622</east>
<south>25.0</south>
</LatLonBox>
</GroundOverlay>
</kml>
And that seems like only way to Google Earth interface - bitmap images. Which is a sad fact that Google Earth is not designed for visualization or numerical model data, as it can't represent varaious other features.
If overlaying bitmap in Google Earth/Maps is the task than as you have already noticed it's just a matter of double clicking produced KMZ file:
or for Google Maps, uploading the file and pasting the path in Google Maps search bar:

How to embed a PDF file in a web site?

I simply want to embed a PDF file in a web site.
The best solution I've found is Google Docs Viewer (http://docs.google.com/viewer), but it does not work for IE and obviously that is not going to work for me.
Anyone have a clean, easy solution to this?
Update: I should add that one of the benefits of embedding the PDF file the Google viewer way is that as the PDF file I link to gets updated (and it could without notice to me), my site would automatically be holding the same PDF file (provided the full pathname doesn't change, which it does not). For this reason converting the file to an image is not preferred while.
Well since you obviously don't want to force someone to download the bloated insecure pdf plugin, why not let them use the bloated insecure flash player?
http://flexpaper.devaldi.com/
But really it is just a simple as
<iframe src="path/to/pdf" width="500" height="700">
If you do stick with the pdf embedded option, Byron is right although embedded pdf files don't look so great on a webpage. Anyway, be sure to be strict about the coding. Hence:
<iframe src="path/to/pdf" width=500 height = 700>
Should be
<iframe src="path/to/pdf" width="500" height="700">
Small alteration.
Updated answer for HTML5:
<object data="filename.pdf" type="application/pdf">
Your browser does not support pdfs, <a href="filename.pdf">click here to
download the file.</a>
</object>
You can read about it here:
http://www.w3schools.com/tags/tag_object.asp
How long is the pdf file? Can't you convert it to a very long image and display that in a div with a scrollbar?
Probably the best approach is to use the PDF.JS library. It's a pure HTML5/JavaScript renderer for PDF documents without any third-party plugins.
Online demo: http://mozilla.github.com/pdf.js/web/viewer.html
GitHub: https://github.com/mozilla/pdf.js
enter link description here
You can also use Google PDF viewer for this purpose. As far as I know it's not an official Google feature (am I wrong on this?), but it works for me very nicely and smoothly. You need to upload your PDF somewhere before and just use its URL:
<iframe src="http://docs.google.com/gview?url=http://example.com/mypdf.pdf&embedded=true" style="width:718px; height:700px;" frameborder="0"></iframe>
I just ftp mine, I do not use Google or any other s/w
you must have some need other than a PDF file sitting in a directory, what is it?
Also, why would you convert the image (and reduce PDF resolution and clarity) ?
Response to Comments
That is the ugliest thing I have seen since my last trip to Africa. You are not seriously thinking of posting that much information on a single page, are you. No one can read it, and I tried every magnification.
For that amount of info, you need to take an architectural approach.
Put a few controls on the front page, and feed the user a small amount of manageable info, about the area that they chose. Only.
Get the info from the source website/database and feed it into your website/database. Only needs to change when the source data changes. The whole linkage can be automated.
Then you just create nice clean pages, with a reasonable quantity of info, in a readable form, on each page.
This is a 20th Century Timetable. Note, not a 21st century timetable (look at Berlin or München for one of those). You really can't just scan an intense doc and provide it as an embedded PDF.
Note that you do not need the elaborate controls of CityRail. you can have just a few to allow select of the line and timetable.
then produce a page that is a simple form of the CityRail page.
or (the absolute minimum) one fully viewable, full size PDF per web page.
.
Like this simple viewable PDF. That example could be served up in one PDF for page 1 and 4 separate PDF pages for the rest; PDFs already have basic navigation, so I have used that feature and produced one 5-pager instead. Make sure you find and use the blue glass buttons and follow the navigation hints on the left top and bottom of each page.
Second to demonstrating the PDFs and navigation, look at the folder: the files are all PDFs.
Back to the original question. Now you can embed PDFs, but if you do, please do not mess with them. All the controls you have on the linked page are redundant; any browser facilitiates that even now, and will be doing so better in future. Eg. in simple viewable PDF, use your browser controls to increase/decrease magnification, move around the doc, etc.
Let's assume you finish your Google Maps page, that's the first or index page. Draw all the train lines in; when the user clicks on a train line, it takes them to either (a) a clean page produced from your db as per (1) which will look like (2), or (b) a single clean PDF in readable form as per (3). You could do the whole project just by manipulating files in directories.
A lot less work. No Google docs; no intermediate s/w to constrict you or work around. You can forget about IE and its multiple incarnations and strangulations; any other browser and its limitations. Concentrate on the data, and getting it out there in presentable form, not on the pitiful s/w and its fits and starts.
Cheers
From HTML5 :
<embed src="url" type="media-type" height="" width=""/>
For media-type refer, http://www.iana.org/assignments/media-types/media-types.xhtml
Google Docs offers an undocumented feature that lets you embed PDF files and PowerPoint presentations in a web page. The files don't have to be uploaded to Google Docs, but they need to be available online.
Here's the code I used to embed the PDF file:
but you should replace the bold URL with your own address. As I mentioned, the document viewer works for PDF and PPT files.
http://googlesystem.blogspot.com/2009/09/embeddable-google-document-viewer.html

How do I link to internal files in a KMZ file?

I'm trying to set up a KMZ file for use in Google Earth where the balloon contents are mostly defined in HTML files, which are embedded using iframes. The setup works with a plain KML file and the extra HTML files when using relative links on the local filesystem (assuming filesystem access is enabled).
My problem is that I can't find a way to create a KMZ file containing all files in an interlinked fashion. The KML specification doesn't talk about the issue at all (in fact KMZ appears only a few times in the whole document). I couldn't find any other documentation on KMZ either.
Is it possible to link to other HTML files within a KMZ? If yes: how?
Yes the Kml specification allows this, you just use relative paths.
However your issue is really to do with the security restrictions in specific applications on certain types of content.
For example the full Google Earth Client allows you to load Flash (swf) content in to Balloons whilst the Goggle Earth Plug-in does not. The same goes for iFramed content, etc.
So the answer to question would totally depend on which application are you viewing the Kml/kmz in and has nothing to do with Kml or Kmz specification.
Realize that there is the OGC KML Standard and how the specification of that standard gets interpreted and implemented in the Google Earth software. In particular there are some grey areas not well-defined in the spec that Google Earth implements as it does. The rules governing KMZ files and embedded content is not well defined and are clearly implementation specific. Some of the details are defined in Google KML Reference documentation and some are not. Some inconsistencies and undocumented features of KML and Google Earth can be found in the KML Errata.
There are restrictions both for what media content (embedded inside KMZ file) can be displayed inline within a description balloon and as well as what content can be linked to and accessed.
Here are some restrictions for <iframe> content listed in the KMZ Tutorial
The <src> element within an <iframe> element cannot point to a local
file on disk, nor can it point to a file inside a KMZ file; it must
point to a URL on the Internet that a browser can visit.
As an exception to this rule you can in fact have an HTML file within a KMZ file and include that as <src> element within an <iframe> in the feature description with a relative URL but not many other media types are supported.
If you enable the "Allow access to local files and personal data" option in Tools/Option/General menu panel then this relaxes some access rules and are able to access some links to content (e.g. HTML, PDF, etc.) as you would from a web browser but mostly local files external to the KMZ file.