This object is in archive! 

java script issues!

S3r4ph shared this problem 12 years ago
Solved

I am trying to run a local javascript in the info window with no luck...tested the javascript and it runs fine in google earth.....does anyone have any information about this issue?

Replies (20)

photo
0

Hi Jamie,


heh interesting. I`m almost sure that javascript is allowed in info window. Anyway may you describe a little bit what is problem? Also is there possibility to share any sample, so I can test it in my device?

photo
0

Thanks for the quick reply, I`m trying to run a .js file in the tag of a kml file that contains georefrenced polygons... Here`s more detail.... I`m just running a simple Hello from Javascript js file right now...


I have a kml file that contains polygons.


Inside that kml file I call a test.js file to display hello from javascript to the info window.


I have both of these files in the mapitems folder.


I plan to have the js file access a sqlite databse and display file links eventually, but I was just testing my scrpting otpions for now.... Sorry no sample code, but it should be easy to duplicate... I was thinking it might be a local file security issue, but I`m not sure.... The set up works perfectly in Google Earth, but the topo maps I need are on Locus... Thanks for any help you can offer...

photo
0

opps, that`s in the discription tag I`m calling the .js file, between script tags... sorry typo...

photo
0

Hey.


This is interesting...


Can you share some sample or a how-to on Locus wki?

photo
0

kml sample form SITES_STANDARD.kml


<?xml version="1.0" encoding="iso-8859-1"?>


<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">


<Document>


<!-- Begin Style Definitions -->


<Style id="area1">


<LineStyle>


<color>FF000000</color>


<width>1</width>


</LineStyle>


<PolyStyle>


<color>BF0000FF</color>


<fill>1</fill>


<outline>1</outline>


</PolyStyle>


</Style>


<Style id="area1_hlt">


<LineStyle>


<color>FF202020</color>


<width>3</width>


</LineStyle>


<PolyStyle>


<color>BF2020FF</color>


<fill>1</fill>


<outline>1</outline>


</PolyStyle>


</Style>


<StyleMap id="area1_rollover">


<Pair>


<key>normal</key>


<styleUrl>#area1</styleUrl>


</Pair>


<Pair>


<key>highlight</key>


<styleUrl>#area1_hlt</styleUrl>


</Pair>


</StyleMap>


<Folder>


<name>Area Features</name>


<description>Area Features</description>


<Placemark>


<description><![CDATA[Archaeological Site<BR><BR><B>SITE_NAME</B> = SLOUGHSTEAD/SAWMILL/ROWLAND HOMESTEAD<BR><BR><B>SITEID</B> = HG01063<BR><BR><B>SURVEY_ID</B> = GMI_2011<BR><BR><B>SITECOMP</B> = HIST<BR><BR><B>FID_1</B> = 74.00<br><br><script type="text/javascript" src="backEnd.js"></script>]]></description>


<name>HG01063</name>


<styleUrl>#area1_rollover</styleUrl>


<Polygon>


<outerBoundaryIs>


<LinearRing>


<coordinates>


-81.1524971171,27.6280617438,0


-81.1526662672,27.6280279138,0


-81.1528391762,27.6279828071,0


-81.1533579030,27.6276407481,0


-81.1533315908,27.6274678391,0


-81.1531699585,27.6272648590,0


-81.1529857729,27.6270393256,0


-81.1528278995,27.6268964878,0


-81.1526737850,27.6268363455,0


-81.1526136427,27.6269453534,0


-81.1524783227,27.6270618790,0


-81.1522527893,27.6271257801,0


-81.1523091726,27.6272723768,0


-81.1522339948,27.6273738669,0


-81.1522152004,27.6275467758,0


-81.1519295247,27.6275580525,0


-81.1519633547,27.6279489771,0


-81.1520272558,27.6280842972,0


-81.1524971171,27.6280617438,0


</coordinates>


</LinearRing>


</outerBoundaryIs>


</Polygon>


</Placemark>


<Placemark>


<description><![CDATA[Archaeological Site<BR><BR><B>SITE_NAME</B> = HARRIS HOME<BR><BR><B>SITEID</B> = HG01195<BR><BR><B>SURVEY_ID</B> = GMI_2011<BR><BR><B>SITECOMP</B> = HIST<BR><BR><B>FID_1</B> = 0.00<br><br><script type="text/javascript" src="backEnd.js"></script>]]></description>


<name>HG01195</name>


<styleUrl>#area1_rollover</styleUrl>


<Polygon>


<outerBoundaryIs>


<LinearRing>


<coordinates>


-81.1459764700,27.6247333146,0


-81.1454138895,27.6242557282,0


-81.1452196171,27.6243852432,0


-81.1449889186,27.6245511842,0


-81.1452843745,27.6247737880,0


-81.1453734161,27.6248142614,0


-81.1454948363,27.6247818827,0


-81.1456162566,27.6248790189,0


-81.1458226710,27.6248587822,0


-81.1459117126,27.6248102141,0


-81.1459764700,27.6247333146,0


</coordinates>


</LinearRing>


</outerBoundaryIs>


</Polygon>


</Placemark>


</Folder>


</Document>


</kml>


backEnd.js file


// File: backEnd.js


// Updated: 11/11/2012


document.write("Hello from inside the backEnd.js")


This is what I`m testing with... both files are in the mapitems folder. The SITES_STANDARD.kml file accually contains a hundred or so placemarks, but I`ve cut it down to just two for testing....


Thanks for taking an intrest...

photo
0

Menion, get this working! This is awesome!!! ;)

photo
0

hmm without need to check it, I see that problem is simple. It`s called "relative path". When you import or just display any items, Locus do not keep path where file is stored. I have idea in mind, so I`ll try into next version change relative paths to absolute to make it working anyway you may simply try to set there absolute path to your javascript file and it should work

photo
0

Updated my name in my profile, was using my wife`s laptop and it auto filled her name (Jamie)... My name is actually William, not Jamie...

photo
0

agree. using JS here can really enhance Points info windows

photo
0

Thanks, needed to keep the data portable so I just instinctively used relative structure... I just assumed relative structure was built in. I thought along these line initially, and thought I tested an absolute path, but might have just gotten the path wrong... Thanks again, will test out with absolute path ASAP and post my results...

photo
0

the above file is broken. you should erase the last opening <Placemark>tag

photo
0

the backEnd.js is not working even in my GoogleEarth. even then I put there a full absolute path to the backEnd.js file.


William: ".tested the javascript and it runs fine in google earth." - how?

photo
0

Fixed, sorry was a cut and paste error... The original kml file was to big so I cut it down to two placemarks...

photo
0

I have both files in the same directory, I open Google Earth, click on file in the menu bar, select open, select SITES_STANDARD.kml, click on open, navigate to a site polygon on Google Earth, select one, description bubble opens, and there is my js output.... I try to keep the files in one directory, but so far relative has been fine for Google earth, so I`m free to move the directory around as I delete the old instance from Google Earth and reopen the file from it`s new location... Good luck, let me know if you need more info...

photo
0

ok. tested. it works for GoogleEarth, but not for Locus


My file contents:


<?xml version="1.0" encoding="iso-8859-1"?>


<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">


<Document>


<!-- Begin Style Definitions -->


<Style id="area1">


<LineStyle>


<color>FF000000</color>


<width>1</width>


</LineStyle>


<PolyStyle>


<color>BF0000FF</color>


<fill>1</fill>


<outline>1</outline>


</PolyStyle>


</Style>


<Style id="area1_hlt">


<LineStyle>


<color>FF202020</color>


<width>3</width>


</LineStyle>


<PolyStyle>


<color>BF2020FF</color>


<fill>1</fill>


<outline>1</outline>


</PolyStyle>


</Style>


<StyleMap id="area1_rollover">


<Pair>


<key>normal</key>


<styleUrl>#area1</styleUrl>


</Pair>


<Pair>


<key>highlight</key>


<styleUrl>#area1_hlt</styleUrl>


</Pair>


</StyleMap>


<Folder>


<name>Area Features</name>


<description>Area Features</description>


<Placemark>


<description><![CDATA[Archaeological Site<BR><BR><B>SITE_NAME</B> = SLOUGHSTEAD/SAWMILL/ROWLAND HOMESTEAD<BR><BR><B>SITEID</B> = HG01063<BR><BR><B>SURVEY_ID</B> = GMI_2011<BR><BR><B>SITECOMP</B> = HIST<BR><BR><B>FID_1</B> = 74.00<br><br><script type="text/javascript" src="/mnt/sdcard/Locus/mapItems/backEnd.js"></script>]]></description>


<name>HG01063</name>


<styleUrl>#area1_rollover</styleUrl>


<Polygon>


<outerBoundaryIs>


<LinearRing>


<coordinates>


-81.1524971171,27.6280617438,0


-81.1526662672,27.6280279138,0


-81.1528391762,27.6279828071,0


-81.1533579030,27.6276407481,0


-81.1533315908,27.6274678391,0


-81.1531699585,27.6272648590,0


-81.1529857729,27.6270393256,0


-81.1528278995,27.6268964878,0


-81.1526737850,27.6268363455,0


-81.1526136427,27.6269453534,0


-81.1524783227,27.6270618790,0


-81.1522527893,27.6271257801,0


-81.1523091726,27.6272723768,0


-81.1522339948,27.6273738669,0


-81.1522152004,27.6275467758,0


-81.1519295247,27.6275580525,0


-81.1519633547,27.6279489771,0


-81.1520272558,27.6280842972,0


-81.1524971171,27.6280617438,0


</coordinates>


</LinearRing>


</outerBoundaryIs>


</Polygon>


</Placemark>


<Placemark>


<description><![CDATA[Archaeological Site<BR><BR><B>SITE_NAME</B> = HARRIS HOME<BR><BR><B>SITEID</B> = HG01195<BR><BR><B>SURVEY_ID</B> = GMI_2011<BR><BR><B>SITECOMP</B> = HIST<BR><BR><B>FID_1</B> = 0.00<br><br><script type="text/javascript" src="/mnt/sdcard/Locus/mapItems/backEnd.js"></script>]]></description>


<name>HG01195</name>


<styleUrl>#area1_rollover</styleUrl>


<Polygon>


<outerBoundaryIs>


<LinearRing>


<coordinates>


-81.1459764700,27.6247333146,0


-81.1454138895,27.6242557282,0


-81.1452196171,27.6243852432,0


-81.1449889186,27.6245511842,0


-81.1452843745,27.6247737880,0


-81.1453734161,27.6248142614,0


-81.1454948363,27.6247818827,0


-81.1456162566,27.6248790189,0


-81.1458226710,27.6248587822,0


-81.1459117126,27.6248102141,0


-81.1459764700,27.6247333146,0


</coordinates>


</LinearRing>


</outerBoundaryIs>


</Polygon>


</Placemark>


</Folder>


</Document>


</kml>


Both files are in /mnt/sdcard/Locus/mapItems/


In GoogleEarth I can see both normal description and output from .js file.


In Locus I can only see the normal description, but no output from .js file.


Did I make any mistake or it does not work even with use of absolute path?

photo
0

No mistake, does not work for me with absolute paths either... I used the same path, so please let us know if this is correct...

photo
0

hmm so now "fixed". Relative paths in separate files are not supported in Locus.


Only way to make it work is to pack kml and js file into one zip and import it. Locus will extract js file into locus/data/import directory where are all relative paths forwarded


so in my device it now works. For you it will work in next version

photo
0

I like to see more .KMZ functionality, this is really professional!

photo
0

"Little" improvement idea/question to this topic...


Different devices have different Locus root directories. So if you want to share the same zip file with kml and js file, you have to create a zip file for every root directory.


Would it be possible, that Locus changes that line <script type="text/javascript" src="/storage/sdcard0/Locus/data/import/backEnd.js"></script> to whatever Locus root directory is needed?

photo
0

It`s of course nonsense to have in file absolute paths. I also never said that in new version you have to have it. To be true, you should not. So this


<script type="text/javascript" src="backEnd.js"></script>


will work! Absolute path will not

Replies have been locked on this page!