Open GoogleCodeExporter opened 9 years ago
Please
1. provide code to reproduce the issue
2. indicate which version of the code you are using, the polys branch or the
kmz branch
Original comment by geocodezip
on 5 Oct 2014 at 5:31
Original comment by geocodezip
on 5 Oct 2014 at 9:40
I'm using the kmz branch, with ProjectedOverlay.js and ZipFile.complete.js both
in the project as well.
Downloaded the code from here:
https://code.google.com/p/geoxml3/source/browse/#svn%2Fbranches%2Fkmz
Actual source code in use:
// This code is inside a "class" (function), and the following methods show the
behavior described:
this.uploadKMLFile = function() {
// A file uploader class we made
// It uses FileReader.readAsBinaryString() to pull in the text content of a file.
this.fileUploader.startUpload();
// Callback when fileUploader has a file loaded
function onFileReady( result, file ) {
this.fileUploader.clearOutFiles();
this.lastFileName = file.name;
// This is the form of using geoXML3 that works. By instantiating it into a new var,
// It does not clobber the doc saved to docs[0]
var p = new geoXML3.parser({
map: this.map,
afterParse: this.afterKMLParsed
});
p.parseKmlString( result );
// The way that FAILED was:
this.kmlParser = new geoXML3.parser({ map: self.map, afterParse: self.afterKMLParsed });
// ... And referencing the same this.kmlParser instance repeatedly, hoping its this.kmlParser.docs array would be increasing in size each time, but it doesn't.
// It just keeps appending placemarks, etc. into docs[0]. And also causes the problems described below...
}
};
this.afterKMLParsed = function( docs ) {
// Inject the properties we need into the parsed doc object
docs[0].fileName = this.lastFileName;
docs[0].visible = true;
// For some reason, geoXML3 is not making a new doc (object) for each parse in the docs array.
// It's combining ALL DOCS into the same doc!! This is not the behavior as described in their, ... ahem... docs.
// So just using this function to make each run of the parser separate up the docs, as it should
this.kmlLayers.push( docs[0] );
// If we had used this.kmlParser = new geoXML3.parser(...) as described above, not only would docs[0] be clobbered, but the reference to it in this.kmlLayers[0] would be clobbered too!
// But since we used var p = new geoXML3.parser(...) above, the instance is destroyed after function runs, and everything works fine.
};
Thanks so much!
Carlos
Original comment by car...@bumpnetworks.com
on 6 Oct 2014 at 4:36
Please provide a complete minimal example that exhibits the problem.
(see http://sscce.org/ or http://stackoverflow.com/help/mcve)
Original comment by geocodezip
on 7 Oct 2014 at 5:40
Ok, here is a complete working example:
http://jsbin.com/pesiz/1/edit?html,js,console,output
In order to see the problem, just click the "Choose File" input button on the
top left of the map. (Thick red border.)
Choose a KML file from your hard drive. The KML files I'm using are just plain
text files ending in ".kml"
The map should re-center to show the KML data. The parsing was successful.
Now, in the JSBin console (3rd panel), type in TEST.geo.kmlLayers and hit
enter. Ignore the output in JSBin. Just open the real web inspector console
(cmd+opt+I on Chrome) and view the console tab. You should see an Array with
one element, the first doc parsed. If you open it up, you'll see fileName =
"(your file name)" and visible = true. (The two properties I injected into the
object.)
Now do it again. Click the file upload button. Choose a second KML file. (It
has to be a different file.) The file is parsed, shown on the map. Success!
However.... Now type in TEST.geo.kmlLayers into the console again, and you'll
see the problem.
You'll see two objects, and they're both the same!! Array element 0 (zero) is
the same as 1! And in [0], the filename and visible properties are undefined.
If you continue parsing new KML files in the same way, you'll see that array
elements [1] - [...n] work fine. Just [0] continually gets clobbered.
Also, you'll probably notice the docs array (inside geoXML3.parser.docs) never
grows in size. It just keeps appending the features of each new doc to the
first doc in docs[0]
Now here is the slightly modified code that works:
http://jsbin.com/fageje/1/edit?html,js,console,output
You can do all the same steps over again and when you write TEST.geo.kmlLayers
in the console, you'll see that array element [0] never gets clobbered.
This is because I'm starting with a brand new geoXML3 instance every time and
it never gets a chance to store more than one doc in its memory / scope.
I hope this is clear.
Thanks!
Carlos
Original comment by car...@bumpnetworks.com
on 8 Oct 2014 at 1:34
Original issue reported on code.google.com by
car...@bumpnetworks.com
on 5 Oct 2014 at 12:28