What Does Local file mean for KML? - kml

The Documentation for Google Earth says I should be able to access files on my local drive, yet i cannot find an example and when I try to use the KML on my local drive it doesn't seem to be loading. I see a lot of answers saying it can't be done, But why does the Documentation say otherwise?
My Code
var href = 'http://code.google.com/'
+ 'D:/visual studio 12/Projects/myMap/myMap/myPoints.Kml';
Example
Network Links
A network link contains a element with an (a hypertext reference) that loads a file. The can be a
local file specification or an absolute URL. Despite the name, a
does not necessarily load files from the network. The
in a link specifies the location of any of the following: •An
image file used by icons in icon styles, ground overlays, and screen
overlays •A model file used in the element •A KML or KMZ
file loaded by a Network Link
The specified file can be either a local file or a file on a remote
server. In their simplest form, network links are a useful way to
split one large KML file into smaller, more manageable files on the
same computer.
So far, all of our examples have required that the KML code be
delivered to Google Earth from the local machine. Network links give
you the power to serve content from a remote location and are commonly
used to distribute data to large numbers of users. In this way, if the
data needs to be amended, it has to be changed only at the source
location, and all users receive the updated data automatically.
I have done some changeing and testing and figured out the error has to be in my HTML file not in the KML file. If I click on the HTML file I get the same results as I do running my program.
Am I correct in thinking that you run your HTML file and it should call the KML? Or do I just call the KML to open GE?
This is my Sample HTML I am tring to make run.
<!DOCTYPE html>
<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
var ge;
google.load("earth", "1.x");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
};
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
var href = 'https://dl.dropbox.com/u/61240296/myPoints.Kml';
google.earth.fetchKml(ge, href, kmlFinishedLoading);
};
function kmlFinishedLoading(obj) {
kmlObject = obj;
if (kmlObject) {
if ('getFeatures' in kmlObject) {
kmlObject.getFeatures().appendChild(placemark);
}
ge.getFeatures().appendChild(kmlObject);
if (kmlObject.getAbstractView()) {
ge.getView().setAbstractView(kmlObject.getAbstractView());
}
}
};
function showHideKml() {
kmlObject.setVisibility(!kmlObject.getVisibility());
};
function failureCB(errorCode){};
google.setOnLoadCallback(init);
</script>
</head>
<body>
<div id="map3d" style="height: 320px; width: 679px;">
</div>
</body>
</html>

You are mistaking the meaning of local file specification. If you read the documentation it doesn't say anything about a file "on your computer" it actually says.
The (sic) can be a local file specification or an absolute URL
What this means is that the file specification can be relative or absolute - local means local relative to the domain hosting the page, not local on your home computer!
In simple terms, imagine my site is located at (this would be your Sample HTML)
http://www.somesite.com/
I also have a kml file, that contains a Network link, located at
http://www.somesite.com/kml/foo.kml
and finally some images located at
http://www.somesite.com/images/
The code in the Sample HTML - can use a local file specification or an absolute URL to refer to the files.
i.e. it can use
local google.earth.fetchKml(ge, '/kml/foo.kml', ...
absolute: google.earth.fetchKml(ge, 'http://www.somesite.com/kml/foo.kml', ...
Also, the Network Link in foo.kml can also use a local file specification or an absolute URL to refer to the image files.
i.e.
local <href>../images/pic.jpg</href>
absolute: <href>http://www.somesite.com/images/pic.jpg</href>

You mention the Documentation for Google Earth but you have tagged the question Google Maps, Google Maps API v3. Google Earth is an application that runs on your local machine and has access to your local hard drive, the other two are web based.
If you are using the Google Maps API v3, the native object that handles KML is KmlLayer, that object requires the to be publicly available so Google's servers can retrieve it and render it for display on the map.

Related

Phantom-node module unable to load external resources

i'm working on a nodejs server which renders posted html to pdf,png or jpg.
( https://github.com/svenhornberg/pagetox (server.js) if you want to try it)
It is working really good, renders complex sites but only to that point that i want do load a simple image. For example i am sending following code to my server:
<!doctype html>
<html>
<head>
<title>logo</title>
</head>
<body>
<img alt="logo" src="http://upload.wikimedia.org/wikipedia/commons/d/de/Wikipedia_Logo_1.0.png">
</body>
</html>
The Code should be okay. But the rendered response image does not contain the logo image.
As said in the phantomjs documentation (http://phantomjs.org/api/webpage/property/settings.html) localToRemoteUrlAccessEnabled is set to false, so set it to true like said in the documentation of phantom-node (https://github.com/sgentle/phantomjs-node/):
page.set('settings.localToRemoteUrlAccessEnabled', true);
page.set('settings.loadImages', true);
to prove it is set to true, i called a getter which returns true
page.get('settings.localToRemoteUrlAccessEnabled', function(data) { console.log(data);});
i'm using node v0.10.26 with phantomjs-node (0.6.1), phantomjs(1.9.7) on linux
Now the question, does anybody see a mistake ? Or can give me a hint what i am doing wrong. Or any other possibilities why phantomjs/phtanom-node isnt loading any external images
I am using the render method to generate the png, jpg or pdf file. I am calling the method inside the evaluate function as a callback, so the site should be loaded completely.
(the full code is at https://github.com/svenhornberg/pagetox/blob/master/server.js)
Edit1: I'm not behind a proxy, which maybe blocks the requests.
looks like i need to set a timeout and wait that all external resources are loaded.
page.set('content') dosen't work with dynamic content in phantomjs
i got it working, but a timeout is not what i want. If i find any better way i will post it.
What you want to set is
page.set('settings.webSecurityEnabled', false);
Which enables cross domain requests. The other option localToRemoteUrlAccessEnabled does not affect your case because you don't use file: resources but you rather overwrite about:blank.
Other issues might be SSL/TLS related. See my answer here for more help.

One folder, two KML files

We want to display two KML files into the Google Earth plugin. KML 1 will have Folder 1, containing placemarks. KML 2, will have more placemarks that belong under Folder 1. Does KML/Google Earth support that? The reason for two KML’s is that we want to display KML 1 before we finish generating KML 2. Actually, we may have several KML files...
Yes there are a number of ways to do this.
One simple way would be to create Folder 1 via the api rather than via KML.
Then when you load your KML files you can simply append them to the folder you created
For example.
var folder = ge.createFolder("folder1");
google.earth.fetchKml(ge, "your.kml", function(kml) {
if(kml) {
folder.appendChild(kml);
}
});
If you did want or need to load Folder 1 via KML you could simply target it via getElementByUrl and then append any further KML to it.
var folder = ge.getElementByUrl("your.kml#folder1");
google.earth.fetchKml(ge, "more.kml", function(kml) {
if(kml) {
folder.appendChild(kml);
}
});
Finally, the KML NetworkLink and NetworkLinkControl elements could be used to link the files together - allowing you to update your data dynamically solely via KML...but without more information on your setup it is hard to offer any specific solutions in this regard.

How to display an pdf once uploaded with jsf

I have created a file upload function which saves all the uploads to a certain place:
private String destination = "D:/Documents/NetBeansProjects/FileUpload/uploadedDocuments/";
Is this a good place to store it? Should I store it some where else?
Is it possible that once the upload is complete for a page to be displayed showing the user what they have just uploaded, like a box below showing a preview? And how would I go about doing this? I am new.
I have figured it out how to display a plain txt file and an image, however it is the pdf that is confusing me.
As to the upload location, which seems to be the IDE project folder, that's absolutely not right. You should choose a configureable and fixed location somewhere outside the IDE project folder. You should not rely on using getRealPath() or relative paths in java.io.File. It would make your webapp unportable. See also this related question: Uploaded image only available after refreshing the page.
Whatever way you choose based on the information provided in the answer of the aforementioned question (and all links therein), you should ultimately end up having a valid URL pointing to the PDF file in question such as http://example.com/files/some.pdf.
Then, you can serve the PDF file on a webpage using either an <iframe>:
<iframe src="/files/some.pdf" width="600" height="400"></iframe>
Or an <object>:
<object data="/files/some.pdf" type="application/pdf" width="600" height="400">
some.pdf <!-- This link will only show up when the browser doesn't support showing PDF. -->
</object>
Keep in mind that showing PDFs in a browser is only supported in browsers having Adobe Reader plugin. Note that the <object> approach will gracefully degrade to a link when the browser doesn't support displaying application/pdf content.

Region-based network links in Google Earth API

I have many large KML data-sets, which are served using a hierarchy of region-based network-links; as described in the KML reference:
Using Regions in conjunction with NetworkLinks, you can create a hierarchy of pointers, each of which points to a specific sub-Region. The <viewRefreshMode>, as shown in the following KML file, has an onRegion option, which specifies to load the Region data only when the Region is active. If you provide nested Regions with multiple levels of detail, larger amounts of data are loaded only when the user's viewpoint triggers the next load.
This works nicely when loaded in Google Earth.
I now wish to load these in an application using the Google Earth plug-in. And I need to access the loaded content via the Google Earth API; (i.e. attach click events, alter styles) to integrate the content into the application.
The issue is, I haven't found any reference to an 'on-load' event for network links. In my mind, the way this would work is:
Load top-level network link via the API, attaching a call-back function which will be invoked when the network-link is loaded.
In the call-back function, parse the KML returned by network link. For intermediate levels in the regionation hierarchy, this KML will contain only network links to the next regionation level. Load these into the plug-in via the API, again specifying the same call-back function, which will be invoked when these are loaded (i.e. when their region becomes visible).
Eventually, the KML returned will contain the actual 'content'. At this stage we load the actual content (i.e. placemarks) into the plug-in, after performing any desired modifications (e.g. attaching event-listeners, setting styles, etc).
I'm thinking the javascript would look something like the following.
Please note: this is just a rough sketch to perhaps aid in understanding my question. I am NOT asking why this code doesn't work.
//create network link
var networkLink = ge.createNetworkLink("");
networkLink.setName("Regionated hierarchy root");
// create a Link object
//the network-links contained in the kml that will be returned in this file
//are region-based; they will only be loaded when the user zooms into the relevant
//region.
var link = ge.createLink("");
link.setHref("http://foo.com/regionatedRoot.kml");
// attach the Link to the NetworkLink
networkLink.setLink(link);
//specify the callback function to be invoked when the network link is loaded
//this is is the part that doesn't actually exist; pure fiction...
networkLink.onLoad = networkLinkLoaded;
// add the NetworkLink feature to Earth
ge.getFeatures().appendChild(networkLink);
// function which will be invoked when a network-link is loaded
// i.e. when its region becomes active
function networkLinkLoaded(kml) {
//parse the kml returned for child network links,
//this will create the network link KmlObject, with a
//region specified on it.
for (childNetworkLink in parseNetworkLinks(kml)) {
//and append them, again hooking up the call-back
childNetworkLink.onLoad = networkLinkLoaded;
ge.getFeatures().appendChild(childNetworkLink);
}
//if the user has zoomed in far enough, then the kml returned will
//contain the actual content (i.e. placemarks).
//parse the kml returned for content (in this case placemarks)
for (placemark in parsePlacemarks(kml)) {
//here we would attach event-listeners to the placemark
ge.getFeatures().appendChild(placemark);
}
}
Is this possible?
Have I taken a wrong turn in my thinking? I believe I have followed recommended practices for managing large KML datasets, but I am unsure how to use these via the API.
Addendum:
As an example of the type of problem I am trying to solve:
Imagine you are building a web application using the Google Earth Plugin, and you want to display a placemark for every set of traffic-lights in the world. The placemarks should only display at an appropriate level-of-detail (e.g. when the camera is at 5km altitude). When a user clicks on a placemark, we want the web app to load statistics for that set of traffic-lights, and display them in a sidebar.
How would you engineer this?
You wouldn't need access to the object data directly to provide the functionality you require. You would handle the data load exactly like you have done, using a hierarchy of region-based network-links.
Then if your usage scenario is like the one you set out in your addendum then you would simply use the target data from the click event to load your statistical data based on the placemarks as required.
For example, you could simply set up a generic mousedown event handler on the window object and then test to see if the target is a placemark. You can add this generic listener before you load any data and it will still be fired when you click on your dynamically loaded placemarks. There is no need to attach individual event-listeners to the placemarks at all.
e.g.
window.google.earth.addEventListener(ge.getWindow(), 'mousedown', onWindowMouseDown);
var onWindowMouseDown = function(event) {
if (event.getTarget().getType() == 'KmlPlacemark') {
// get the placemark that was clicked
var placemark = event.getTarget();
// do something with it, or one of its relative objects...
var document = placemark.getOwnerDocument();
var parent = placemark.getParentNode();
// etc...
}
}
Not sure if this is quite what you want but there is a kmltree api that will:
build out the kml tree for you based on the kml given
allow you to have a 'kmlloaded' event handler
http://code.google.com/p/kmltree/
function initCB(instance){
ge = instance;
ge.getWindow().setVisibility(true);
var gex = gex = new GEarthExtensions(ge);
var tree = kmltree({
url: 'http://foo.com/regionatedRoot.kml',
gex: gex,
mapElement: $('#map3d'),
element: $('#tree'),
});
$(tree).bind('kmlLoaded', function(event, kmlObject){ //do something here });
tree.load();
}
it does require you to bring in another js api but it works pretty good and gives you some good built in functionality.
So far I haven't found anything just from the plug-in that will fire an event when the kml is loaded...
you might be able to try using fetchKml() especially if you are hardcoding that url for the link in there?
google.earth.fetchKml(ge, 'http://foo.com/regionatedRoot.kml', function(kmlObject){
//do logic here
});

How to intercept a Javascript/CSS file request from the Webpage at the cleint side, and load alternative files insted?

For example, a webpage loads its JavaScript files like this inside the head tag:
<script src="http://www.somedomain.com/js/somejsfile.js"></script>
or for CSS files:
<link rel="stylesheet" type="text/css"
href="http://www.somedomain.com/somecssfile.css">
What I want to achieve is that, while loading the page itself, instead of the original http://www.somedomain.com/js/somejsfile.js it should load another file http://www.anotherdomain.com/js/anotherfile.js
May be via some custom firefox/chrome (preferably not IE) extension or something else.
Hint:
This can be also used to subsitute jQuery library etc. to load from local source instead of remote Google* hosted file.
injecting your own content script at "document_start" will give you the chance to analise and modify the document, even before the DOM is constructed and any script is started.
But at that time, all CSS files are already loaded. Perhaps you may redefine them with other CSS.
See "run_at" property in "content-scripts" property, in manifest.json:
http://code.google.com/chrome/extensions/content_scripts.html

Resources