0
votes

I am building a geo-visualization application for my dissertation, using google's tools, most notably Google Earth api. I am trying to combine some regions with my placemarks so that i can create different levels of detail, so that some placemarks (larger polygons representing regions) appear when the camera is far enough and other, smaller polygons (representing smaller areas) appear when the camera zooms in (and the larger ones would dissapear).

I know theoreticaly that to achieve this i must enclose the placemarks in regions and set min and max pixels values but my problem starts when i try to create the region itself.

More specificaly, i succeed in creating the region, but an error ocures when i try to append it in a folder. The Error message doesn't help me much because it comes from the init callback function that contains the rest of the code.

"Uncaught Error: Error calling method on NPObject. "

The part of the code that has the problem is the following:

                    //Try to create region
                    //experimental
                    var folder = ge.createFolder('');
                    var region = ge.createRegion('');
                    var box = ge.createLatLonAltBox('');
                    box.setAltBox(<?= $latitude + 0.035 ?>, <?= $latitude - 0.035 ?>, <?= $longitude + 0.035 ?>, <?= $longitude - 0035 ?>, 0.0, 0.0, 0.0, ge.ALTITUDE_CLAMP_TO_GROUND);
                    region.setLatLonAltBox(box);
                    var lod = ge.createLod('');
                    lod.setMinLodPixels(20.0);
                    region.setLod(lod);

                    //---------------------

                    // Create the placemark.
                    //and add it to the map
                    var placemark = makeSimplePlacemark(<?= $latitude ?>, <?= $longitude ?>,  '<?= $location ?>');
                    folder.getFeatures().appendChild(region);
                    folder.getFeatures().appendChild(placemark); 
                    ge.getFeatures().appendChild(folder);

If i remove the line that reads: "folder.getFeatures().appendChild(region);" it works fine, but i need the regions, or another solution perhups. And i am almost sure that the problem is something simple that i am missing... :(

Any help is appreciated. Thank you in advance for your time.

3

3 Answers

0
votes

I don't know if this will work or not, but just for fun, try making all four create* callss in the code with arbitrary names instead of ''.

var folder = ge.createFolder('test1');
var region = ge.createRegion('test2');
var box = ge.createLatLonAltBox('test3');
box.setAltBox(<?= $latitude + 0.035 ?>, <?= $latitude - 0.035 ?>, <?= $longitude + 0.035 ?>, <?= $longitude - 0035 ?>, 0.0, 0.0, 0.0, ge.ALTITUDE_CLAMP_TO_GROUND);
region.setLatLonAltBox(box);
var lod = ge.createLod('test4');

I've received the error you mentioned before when passing '' as the argument to create* methods.

0
votes

I found the answer after all. A good night's sleep always helps i guess.

It seems i was wrong in trying to add the region to folder item as a child node using append. I had figured i should do this because in kml format both region and placemark nodes are nested in the folder node at the same level.

But it seems that through the plugin API there is a dedicated setRegion(kmlRegion) member for this purpose. The good thing is that this member exists in kmlPlacemarks too, so i dn't even need to create the folder (for this reason at least).

The correct code is:

                    //Try to create region          
                    //experimental
                    var region = ge.createRegion('');
                    var box = ge.createLatLonAltBox('');
                    box.setAltBox(<?= $latitude + 0.035 ?>, <?= $latitude - 0.035 ?>, <?= $longitude + 0.035 ?>, <?= $longitude - 0.035 ?>, 0.0, 0.0, 0.0, ge.ALTITUDE_CLAMP_TO_GROUND);
                    region.setLatLonAltBox(box);
                    var lod = ge.createLod('');
                    lod.set(128,-1,64,256);
                    region.setLod(lod);

                    //---------------------

                    // Create the placemark.
                    //and add it to the map
                    var placemark = makeSimplePlacemark(<?= $latitude ?>, <?= $longitude ?>,  '<?= $location ?>');
                    placemark.setRegion(region);
                    ge.getFeatures().appendChild(placemark);

How did i miss that member in the first place... I should stop and rest more often :/

0
votes

I had another thought on getting KML into a Google Earth Plugin. I ran into similar issues trying to figure out which methods would add which objects at which points in the KML hierarchy. In my application I was able to circumvent using the KML structure portions of the API at all by using code that wrote the KML I wanted as a string and then using the method parseKML as in:

var myKML = '';
//build kml text and assign it to myKML
built_track = ge.parseKml(myKML);
ge.getFeatures().appendChild(built_track);