加载指定地图。所有参数均为可选。
VEMap.LoadMap(VELatLong, zoom, style, fixed, mode, showSwitch, tileBuffer, mapOptions);
参数
|
参数
|
说明
|
|---|
|
VELatLong
|
一个 VELatLong 类对象,用于表示地图的中心。可选。
|
|
zoom
|
将要显示的缩放级别。有效的值范围是从 1 到 19。这是一个可选参数,其默认值为 4。
|
|
style
|
一个 VEMapStyle 枚举值,用于指定地图样式。可选。默认值为 VEMapStyle.Road。
|
|
fixed
|
一个布尔值,用于指定地图视图是否显示为用户无法更改的固定地图。这是一个可选参数,其默认值为 false。
|
|
mode
|
一个 VEMapMode 枚举值,用于指定是在二维模式下还是在三维模式下加载地图。可选。默认值为 VEMapMode.Mode2D。
|
|
showSwitch
|
一个布尔值,用于指定是否在控制板中显示地图模式开关。这是一个可选参数,其默认值为 true(显示开关)。
|
|
tileBuffer
|
加载地图时需使用多少图块缓冲区。默认值为 0(不加载额外的图块)。三维模式下将忽略该参数。
|
|
mapOptions
|
一个 VEMapOptions 类,用于指定其他要设置的地图选项。
|
在调用该方法前,您必须使用 VEMap 构造函数初始化地图对象。
如果您想要通过地图控件使用回调函数,请在调用 LoadMap 方法前设置 VEMap.onLoadMap 属性。
若要将地图“锁定”在某一位置,请在加载地图时将 fixed 参数设置为 true,或者在应用程序会话过程中禁用鼠标事件。以下代码可禁用鼠标事件。
// Attach an event handler for a mousedown event.
map.AttachEvent("onmousedown", DisableMap);
// When the mouse is used, the DisableMap function will
// get called. Returning true will disable the mousedown
// event, which disables panning.
function DisableMap()
{
return true;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://dev.ditu.live.com/mapcontrol/mapcontrol.ashx?v=6.2"></script>
<script type="text/javascript">
var map = null;
var selStyle = VEMapStyle.Aerial;
var selMode = VEMapMode.Mode2D;
var zoom = 4;
// Demonstrate LoadMap, with a UI for trying out all of the parameters.
function GetMap()
{
var latLon = new VELatLong(document.getElementById('txtLat').value, document.getElementById('txtLong').value);
if (document.getElementById('txtZoom').value > 0 && document.getElementById('txtZoom').value <= 19)
{
zoom = document.getElementById('txtZoom').value;
}
else
{
alert("Enter a value between 1 and 19.");
}
if (chkFixed.checked)
{
fixed=1;
}
else
{
fixed=0;
}
if (chkShowSwitch.checked)
{
showSwitch=1;
}
else
{
showSwitch=0;
}
map = new VEMap('myMap');
map.LoadMap(latLon, zoom, selStyle, fixed, selMode, showSwitch);
map.AttachEvent("onobliqueenter", SetObliqueRadio);
map.AttachEvent("onobliqueleave", SetObliqueRadio);
}
function SetStyle(s)
{
selStyle = s;
}
function SetMode(m)
{
if (modeRadios.mode[0].Checked)
{
selMode = VEMapMode.Mode2D;
}
else
{
selMode = VEMapMode.Mode3D;
}
}
function SetObliqueRadio(event)
{
if (event.eventName == "onobliqueenter")
{
styleRadios.style[3].disabled=null;
}
else if (event.eventName == "onobliqueleave")
{
styleRadios.style[3].disabled="disabled";
}
}
function DisposeMap()
{
if(map != null)
{
map.Dispose();
}
}
</script>
</head>
<body onload="GetMap();" onunload="DisposeMap();" style="font-family:Arial">
<div id='myMap' style="position: relative; width: 400px; height: 400px;">
</div>
<input id="btnLoad" type="button" onclick="GetMap()" value="Load A Map" />
<br />
Lat: <input id="txtLat" value="36.13371559517861" />
<br />
Lon: <input id="txtLong" value="-115.16238212585449" />
<br />
Zoom Level (1-19): <input id="txtZoom" value="9" style="width: 50px" />
<br />
Fixed: <input id="chkFixed" type="checkbox" /> (check to prevent user interaction)
<br />
Show Switch: <input id="chkShowSwitch" type="checkbox" checked="checked"/>
(show the map mode switch on the dashboard control)
<table width="400px">
<tr>
<td align="left" width="60%">
<form id="styleRadios">
Road: <input name="style" type="radio" onclick="SetStyle('r')" /> |
Aerial: <input name="style" type="radio" onclick="SetStyle('a')" checked="checked" />
<br />
Hybrid: <input name="style" type="radio" onclick="SetStyle('h')" /> |
Oblique: <input name="style" type="radio" onclick="SetStyle('o')" disabled="disabled"/>
</form>
</td>
<td align="left">
<form id="modeRadios">
2D: <input name="mode" type="radio" onclick="SetMode()" checked="checked" />
<br />
3D: <input name="mode" type="radio" onclick="SetMode()" />
</form>
</td>
</tr>
</table>
</body>
</html>
参考
VEMap.SetCenter 方法
VEMap.SetCenterAndZoom 方法
VEMap.SetMapStyle 方法
VEMap.SetMapMode 方法
概念
VEMapOptions 类