Set cammera to a rectangle

瀏覽次數:177 次
跳到第一則未讀訊息
訊息已遭刪除

bahram

未讀,
2008年9月1日 晚上7:14:102008/9/1
收件者: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

未讀,
2008年9月2日 下午4:38:242008/9/2
收件者: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

未讀,
2008年9月2日 晚上8:39:482008/9/2
收件者: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

未讀,
2008年9月2日 晚上8:40:292008/9/2
收件者:KML Developer Support - Google Earth Browser Plugin
Example webpage has a commented version of the function too ;)

TinyGrasshopper

未讀,
2008年9月2日 晚上10:54:332008/9/2
收件者: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

未讀,
2008年9月4日 凌晨1:35:292008/9/4
收件者: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

未讀,
2008年9月5日 清晨6:26:152008/9/5
收件者: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

未讀,
2008年9月7日 上午9:14:192008/9/7
收件者:KML Developer Support - Google Earth Browser Plugin
Thanks TinyGrasshopper
it's really work thanks alot.
回覆所有人
回覆作者
轉寄
0 則新訊息