javascript - Google Earth API link.setHref not working when using variable -



javascript - Google Earth API link.setHref not working when using variable -

the variable getting right info not working in href parameter. added button variable see in browser. if set hard code value, commented, works.

<?php @session_start(); $idcoord = $_get['search_fd0']; $kmlpath = "http://nonprasa.t15.org/kml/pr" . $idcoord . "/doc.kml"; ?> <!doctype html public "-//w3c//dtd xhtml 1.0 strict//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>google earth api sample</title> <script src="http://www.google.com/jsapi?key=abqiaaaaupsjpk3mbtdpj4g8cqbnjrragtyh6uml8madna0ykuwnna8vnxqczvbxtx2dyyxgstoxpwhvig7djw" type="text/javascript"></script> <script type="text/javascript"> function addsamplebutton(caption, clickhandler) { var btn = document.createelement('input'); btn.type = 'button'; btn.value = caption; if (btn.attachevent) btn.attachevent('onclick', clickhandler); else btn.addeventlistener('click', clickhandler, false); // add together button sample ui document.getelementbyid('sample-ui').appendchild(btn); } function addsampleuihtml(html) { document.getelementbyid('sample-ui').innerhtml += html; } </script> <script type="text/javascript"> var ge; google.load("earth", "1"); function init() { // var kmlfile = '\"<?php echo $kmlpath; ?>\"'; var kmlfile = '<?php echo $kmlpath;?>'; google.earth.createinstance('map3d', initcallback, failurecallback); addsamplebutton(kmlfile, buttonclick); } function initcallback(instance) { ge = instance; ge.getwindow().setvisibility(true); // add together navigation command ge.getnavigationcontrol().setvisibility(ge.visibility_auto); // add together layers ge.getlayerroot().enablelayerbyid(ge.layer_borders, true); ge.getlayerroot().enablelayerbyid(ge.layer_roads, true); createnetworklink(); document.getelementbyid('installed-plugin-version').innerhtml = ge.getpluginversion().tostring(); } function failurecallback(errorcode) { } function createnetworklink() { var networklink = ge.createnetworklink(""); networklink.setdescription("networklink open fetched content"); networklink.setname("open networklink"); networklink.setflytoview(true); // create link object var link = ge.createlink(""); //link.sethref("http://nonprasa.t15.org/kml/pr0302013/doc.kml); link.sethref (kmlfile); // attach link networklink networklink.setlink(link); // add together networklink feature earth ge.getfeatures().appendchild(networklink); // @ placemark created var la = ge.createlookat(''); la.set(18, -67, 0, // height ge.altitude_relative_to_ground, 0, // heading 0, // straight-down tilt 1500 // range (inverse of zoom) ); ge.getview().setabstractview(la); } function buttonclick() { // current view. var lookat = ge.getview().copyaslookat(ge.altitude_relative_to_ground); // zoom out x times current range. lookat.setrange(lookat.getrange() * 5.0); // update view in google earth. ge.getview().setabstractview(lookat); } </script> </head> <body onload="init()" style="font-family: arial, sans-serif; font-size: 8px; border: 0;"> <div id="sample-ui"></div> <div id="map3d" style="width: 1200px; height: 800px;"></div> <br> <div>installed plugin version: <span id="installed-plugin-version" style="font-weight: bold;">loading...</span></div> </body>

the javascript variable kmlfile local init function, going undefined when effort utilize in createnetworklink function.

to highlight mean take @ following, have removed other code clarity...

function init() { var kmlfile = '<?php echo $kmlpath;?>'; // kmlfile defined here } function createnetworklink() { link.sethref(kmlfile); // kmlfile undefined here alert(kmlfile); // have told much... }

to prepare create kmlfile global variable available within scope of createnetworklink function. create variable outside init method,, have ge variable.

again, take @ next other code removed clarity.

<script type="text/javascript"> var ge; var kmlfile; // kmlfile defined here function init() { kmlfile = '<?php echo $kmlpath;?>'; // set variable } function createnetworklink() { link.sethref(kmlfile); // kmlfile available here } </script>

javascript google-earth-plugin

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

Hibernate criteria by a list of natural ids -

ios - Lagging ScrollView with UIWebview inside -