商信互联
本主题描述如何在根据“使用栅格地图”教程创建的应用程序中使用JavaScript代码直接访问dxMap小部件。如果您需要自定义未映射到“模型编辑器”中IModelMapSettings或IModelMobileMapSettings节点的属性的窗口小部件选项,则可能需要执行此操作。在此示例中,使用人类可读地址(而非数字坐标)自定义指定在小部件中心显示的位置的中心选项。在其autoAdjust选项也发生了变化。
面向ASP.NET的控制器
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Maps.Web;
// ...
public class WebMapCenterController : ViewController {
public WebMapCenterController() {
TargetObjectType = typeof(IMapsMarker);
TargetViewType = ViewType.ListView;
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
WebMapsListEditor mapsListEditor = ((ListView)View).Editor as WebMapsListEditor;
if (mapsListEditor != null) {
mapsListEditor.MapViewer.ClientSideEvents.Customize = @"
function(sender, map) {
map.option('center', 'Brooklyn Bridge, New York, NY');
map.option('autoAdjust', false);
}";
}
}
}
Imports Microsoft.VisualBasic
Imports DevExpress.Persistent.Base
Imports DevExpress.ExpressApp.Maps.Web
' ...
Public Class WebMapCenterController
Inherits ViewController
Public Sub New()
TargetObjectType = GetType(IMapsMarker)
TargetViewType = ViewType.ListView
End Sub
Protected Overrides Sub OnViewControlsCreated()
MyBase.OnViewControlsCreated()
Dim mapsListEditor As WebMapsListEditor = TryCast(CType(View, ListView).Editor, WebMapsListEditor)
If mapsListEditor IsNot Nothing Then
mapsListEditor.MapViewer.ClientSideEvents.Customize = _
"function(sender, map) {" & ControlChars.CrLf & _
" map.option('center', 'Brooklyn Bridge, New York, NY');" & ControlChars.CrLf & _
" map.option('autoAdjust', false);" & ControlChars.CrLf & _
"}"
End If
End Sub
End Class
结果显示在下图中。
面向移动的控制器
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Maps.Mobile;
using DevExpress.ExpressApp.Maps.Mobile.Editors;
//...
public class MobileMapCenterController : ViewController<ListView> {
public MobileMapCenterController() {
TargetViewId = "MapsMarker_ListView";
}
protected override void OnViewControlsCreated() {
base.OnViewControlsCreated();
MobileMapsListEditor mobileMapsListEditor = View.Editor as MobileMapsListEditor;
if (mobileMapsListEditor != null) {
Map map = mobileMapsListEditor.Control as Map;
map.OnCustomize = @"
(function(map) {
map.option('center', 'Brooklyn Bridge,New York,NY');
map.option('autoAdjust', 'false');
})";
}
}
}
Imports Microsoft.VisualBasic
Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Maps.Mobile
Imports DevExpress.ExpressApp.Maps.Mobile.Editors
'...
Public Class MobileMapCenterController
Inherits ViewController(Of ListView)
Public Sub New()
TargetViewId = "MapsMarker_ListView"
End Sub
Protected Overrides Sub OnViewControlsCreated()
MyBase.OnViewControlsCreated()
Dim mobileMapsListEditor As MobileMapsListEditor = TryCast(View.Editor, MobileMapsListEditor)
If mobileMapsListEditor IsNot Nothing Then
Dim map As Map = TryCast(mobileMapsListEditor.Control, Map)
map.OnCustomize = "" & ControlChars.CrLf & _
" (function(map) {" & ControlChars.CrLf & _
" map.option('center', 'Brooklyn Bridge,New York,NY');" & ControlChars.CrLf & _
" map.option('autoAdjust', 'false');" & ControlChars.CrLf & _
" })"
End If
End Sub
End Class
结果显示在下图中。