Set cammera to a rectangle

177 views
Skip to first unread message
Message has been deleted

bahram

unread,
Sep 1, 2008, 7:14:10 PM9/1/08
to KML Developer Support - Google Earth Browser Plugin
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

Roman N

unread,
Sep 2, 2008, 4:38:24 PM9/2/08
to KML Developer Support - Google Earth Browser Plugin
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

TinyGrasshopper

unread,
Sep 2, 2008, 8:39:48 PM9/2/08
to KML Developer Support - Google Earth Browser Plugin
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;

TinyGrasshopper

unread,
Sep 2, 2008, 8:40:29 PM9/2/08
to KML Developer Support - Google Earth Browser Plugin
Example webpage has a commented version of the function too ;)

TinyGrasshopper

unread,
Sep 2, 2008, 10:54:33 PM9/2/08
to KML Developer Support - Google Earth Browser Plugin
Just updated the comments on the example page to give a bit more of an
idea of what it's actually doing.

TinyGrasshopper

unread,
Sep 4, 2008, 1:35:29 AM9/4/08
to KML Developer Support - Google Earth Browser Plugin
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

fraser

unread,
Sep 5, 2008, 6:26:15 AM9/5/08
to KML Developer Support - Google Earth Browser Plugin
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 -

bahram

unread,
Sep 7, 2008, 9:14:19 AM9/7/08
to KML Developer Support - Google Earth Browser Plugin
Thanks TinyGrasshopper
it's really work thanks alot.
Reply all
Reply to author
Forward
0 new messages