Set cammera to a rectangle

Showing 1-9 of 9 messages
Set cammera to a rectangle bahram 9/1/08 4:14 PM
Hi there
I have tow points (x1,y1)-(x2,y2) and I want to set the camera to just
view the boundary of this rectangle appreciated if someone can help
guide me how can I set the camera.
TQ
Bahram
(unknown) 9/1/08 4:11 PM <This message has been deleted.>
Re: Set cammera to a rectangle Roman Nurik 9/2/08 1:38 PM
Hi Bahram,

This feature isn't available yet; there's a feature request out at
http://code.google.com/p/earth-api-samples/issues/detail?id=29 that
you can 'star' for notifications of when workarounds or updates are
available.

- Roman
Re: Set cammera to a rectangle TinyGrasshopper 9/2/08 5:39 PM
Below is a function that'll give you an approximate view of a
rectangle. It works quite well in the tests i've done - to be honest
it works a lot better than I expected given how rough the maths are :)

Anywayz, you feed it the lat/lngs of your rectangle and it passes you
back a KmlCamera object which you can pass to
GEPlugin.getView().setAbstractView() to set the current view.

Example webpage here: http://www.tinyg.com/googlearthtest6.html

Code:

function createCameraFromRectangle(plugin, lat1, lng1,  lat2, lng2) {
        var r = 6378700;
        var fov = 34;

        var camera = ge.createCamera('');

        camera.setLatitude((lat1 + lat2) / 2.0);
        camera.setLongitude((lng1 + lng2) / 2.0);
        camera.setHeading(0.0);
        camera.setTilt(0.0);

        var dy = Math.max(lat1, lat2) - Math.min(lat1, lat2);
        var dx = Math.max(lng1, lng2) - Math.min(lng1, lng2);

        var d = Math.max(dy, dx);

        d = d * Math.PI / 180.0;

        var dist = r * Math.tan(d / 2);

        var alt = dist / (Math.tan( fov * Math.PI / 180.0));

        camera.setAltitude(alt);

        return camera;
Re: Set cammera to a rectangle TinyGrasshopper 9/2/08 5:40 PM
Example webpage has a commented version of the function too ;)
Re: Set cammera to a rectangle TinyGrasshopper 9/2/08 7:54 PM
Just updated the comments on the example page to give a bit more of an
idea of what it's actually doing.
Re: Set cammera to a rectangle TinyGrasshopper 9/3/08 10:35 PM
As you might have seen in another post, I've extended the code i did
yesterday to allow you to zoom to the extents of a given feature.
Maybe this is also useful to you?

From the other thread (
http://groups.google.com/group/google-earth-browser-plugin/browse_thread/thread/6b1ec72dd502cc3a/3e004a540d9e290a#3e004a540d9e290a
):

Since i had to do it for my own site, I've put together some code to
zoom to the extents of a feature. Have a look at the source code of
this sample page:

http://www.tinyg.com/googlearthtest7.html

Basically you do:

zoomToFeature(plugin, feature);

where "plugin" is your plugin instance and feature is the feature to
zoom to.

The components of that function may also be useful:

extent = getFeatureExtent(plugin, feature);

This will return a LatLonAltBox with the extents of a feature
(including any sub features).

camera = createCameraFromRectangle(plugin, north, east, south, west);

This will return a camera that will show the extents between north,
south, east and west.

camera = createCameraFromLatLonAltBox(plugin, box);

This will return a camera that will show the extents within the given
LatLonAltBox.

Hope this is helpful,

Cheers,
Chris
Re: Set cammera to a rectangle Earth API Guru 9/5/08 3:26 AM
Hey TinyGrasshopper,

Nice functions! Really usefull, googd stuff...

F.

On Sep 4, 6:35 am, TinyGrasshopper wrote:
> As you might have seen in another post, I've extended the code i did
> yesterday to allow you to zoom to the extents of a given feature.
> Maybe this is also useful to you?
>
> From the other thread (http://groups.google.com/group/google-earth-browser-plugin/browse_thr...
> > > > > > Bahram- Hide quoted text -
>
> - Show quoted text -
Re: Set cammera to a rectangle bahram 9/7/08 6:14 AM
Thanks TinyGrasshopper
it's really work thanks alot.