圖徵繪圖範圍計算

圖徵繪圖範圍計算

依據圖徵範圍計算螢幕縮放比例尺及位置,使各圖徵皆顯示於手持裝置螢幕中,圖徵繪圖範圍計算程式範例說明如下:

public class MainActivity extends Activity {

RelativeLayout AddMapView;

TGOnlineMap _MapView = null;

private static final int SCROLL_BY_PX = 100;

 

private static final TGLatLng boundPt1 = new TGLatLng(24.642, 121.134);  //設定點坐標1

private static final TGLatLng boundPt2 = new TGLatLng(24.610, 121.296);  //設定點坐標2

private static final TGLatLng boundPt3 = new TGLatLng(24.575, 121.181);  //設定點坐標3

private static final TGLatLng KL = new TGLatLng(25.197796,121.614532);

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

AddMapView = (RelativeLayout)findViewById(R.id.AddMapView);

try {

_MapView = new TGOnlineMap(this);

 

_MapView.setBackgroundColor(Color.rgb(165,191,221));

AddMapView.addView(_MapView);

 

_MapView.addMarker(new TGMarkerOptions()

.position(boundPt1)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

_MapView.addMarker(new TGMarkerOptions()

.position(boundPt2)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

_MapView.addMarker(new TGMarkerOptions()

.position(boundPt3)

.draggable(false)

.icon(TGBitmapDescriptorFactory.fromResource(R.drawable.ic_launcher)));

} catch (TGRuntimeRemoteException e) {

e.printStackTrace();

}

}

 

public void onBounds(View view) {

TGLatLngBounds bounds = new TGLatLngBounds.Builder()

.include(boundPt1)  //點資料1

.include(boundPt2)  //點資料2

.include(boundPt3)  //點資料3

.build();

_MapView.moveViewer(TGViewerUpdateFactory.LatLngBounds(bounds, 5));

//圖窗依指定經緯度邊界調整,置於螢幕中心,並縮放至可能之最大縮放層級。

}

}

回到上方