Class
WebMapViewer
Description
A control for viewing maps loaded via a map provider like Google. It is initially centered at the position specified by Latitude, Longitude.
Properties
Name |
Type |
Read-Only |
Shared |
---|---|---|---|
✓ |
|||
✓ |
|||
✓ |
|||
✓ |
|||
Methods
Name |
Parameters |
Returns |
Shared |
---|---|---|---|
Location As WebMapLocation |
|||
locations() As WebMapLocation |
|||
ParamArray locations() As WebMapLocation |
|||
route As MapRoute |
|||
transportType As MapRoute.TransportTypes = MapRoute.TransportTypes.Car |
|||
Script As String |
|||
location As WebMapLocation, fly As Boolean = False |
|||
index As Integer |
|||
Location As WebMapLocation |
|||
index As Integer |
|||
transportType As MapRoute.TransportTypes = MapRoute.TransportTypes.Car |
|||
Query As String |
|||
Events
Name |
Parameters |
Returns |
---|---|---|
hitItem As WebMenuItem |
||
location As WebMapLocation |
||
zoomLevel As Integer |
Enumerations
WebMapViewer.MapTypes
MapTypes
Specifies the type of map to be displayed. For example, roadmap versus satellite.
Enum |
Description |
---|---|
RoadMap |
Shows roads and points of interest. This type is good for showing locations and directions. |
Satellite |
Shows satellite photos rather than roads and locations. |
WebMapViewer.Modes
Modes
Specifies the mode in which the map will work. For example, showing a location versus showing directions.
Enum |
Description |
---|---|
Place |
Displays a map pin at a particular place or address, such as a landmark, business, geographic feature, or town. |
Directions |
Displays the path between two or more specified points on the map, as well as the distance and travel time. |
Search |
Displays results for a search across the visible map region. It's recommended that a location for the search be defined, either by including a location in the search term (record+stores+in+Seattle) or by including a center and zoom parameter to bound the search. |
View |
Returns a map with no markers or directions. |
StreetView |
Provides a viewer that renders the resulting panorama as a sphere with a camera at its center. You can manipulate the camera to control the zoom and the orientation of the camera. |
WebMapViewer.Renderers
Renderers
Specifies the map rendering provider that will render the maps.
Enum |
Description |
---|---|
GoogleMapsEmbed |
Google's map renderer. |
MapLibre |
An open-source map renderer. |
Property descriptions
WebMapViewer.AllowFullScreen
AllowFullScreen As Boolean
When True provides a widget that allows the user to toggle between the map view consuming the designated space on the page versus consuming the entire browser window.
WebMapViewer.APIKey
APIKey As String
Specifies the APIKey to use with Google Maps.
Google Maps requires an API Key. Visit the Google Maps API Key page to get your own API Key.
Always set your API key, usually in the Opening event:
Me.APIKey = "<YourGoogleMapsAPIKey>"
WebMapViewer.ContextualMenu
ContextualMenu As WebMenuItem
If you assign a WebMenuItem to the control, it will be displayed when the user right-clicks the control.
On a WebPage, you can disable/remove the default contextual menu by an empty WebMenuItem class object to this property.
This code populates a contextual menu in the Shown event of the control.
Var menu As New WebMenuItem
menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu
The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text
Case "One"
MessageBox("One")
Case "Two"
MessageBox("Two")
Case "Three"
MessageBox("Three")
End Select
WebMapViewer.ControlID
ControlID As String
Identifies the control on a per session basis.
This property is read-only.
WebMapViewer.Enabled
Enabled As Boolean
When True the WebControl is drawn enabled and responds to user action. When False, the control appears as disabled and does not respond to user actions.
In the case of WebTimer, when set to False this disables and stops the WebTimer. When set to True, it starts the WebTimer.
Disable a button when a check box value changes:
If AllowSaveCheckBox.Value Then
SaveButton.Enabled = True
Else
AllowSaveButton.Enabled = False
End If
WebMapViewer.Height
Height As Integer
The height (in pixels) of the control.
WebMapViewer.Indicator
Indicator As Indicators
The color scheme for the control.
WebMapViewer.Latitude
Latitude As Double
Sets or Gets the latitude of the center of the map being displayed. Because you would normally want to set both the latitude and longitude, you must also call the UpdateBrowser method to send the changes to the browser.
Set the map to a specific latitude and longitude:
MapViewer1.Latitude = 38.8977
MapViewer1.Longitude = -77.0366
MapViewer1.Update
WebMapViewer.Left
Left As Integer
The position of the left side of the WebUIControl in pixels, relative to the web page.
WebMapViewer.LockBottom
LockBottom As Boolean
Determines whether the bottom edge of the control should stay at a set distance from the bottom edge of the parent control, if there is one, or the owning web page.
WebMapViewer.LockHorizontal
LockHorizontal As Boolean
LockHorizontal overrides LockLeft and LockRight. It allows you to proportionally lock a control's position to the center of its parent control (or web page).
For example, if you place a control in the center of the page and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebMapViewer.LockLeft
LockLeft As Boolean
Determines whether the left edge of the control should stay at a set distance from the left edge of the parent control, if there is one, or the owning web page.
WebMapViewer.LockRight
LockRight As Boolean
Determines whether the right edge of the control should stay at a set distance from the right edge of the parent control, if there is one, or the owning web page.
WebMapViewer.LockTop
LockTop As Boolean
Determines whether the top edge of the control should stay at a set distance from the top edge of the parent control, if there is one, or the owning web page.
WebMapViewer.LockVertical
LockVertical As Boolean
LockVertical overrides LockTop and LockBottom. It allows you to proportionally lock a control's position to keep it centered within the parent control or web page.
For example, if you place a control in the center of the page, and sets both LockHorizontal and LockVertical, the control will stay in the center of the page.
WebMapViewer.Longitude
Longitude As Double
Sets or Gets the longitude of the center of the map being displayed. Because you would normally want to set both the latitude and longitude, you must also call the UpdateBrowser method to send the changes to the browser.
Set the map to a specific latitude and longitude:
MapViewer1.Latitude = 38.8977
MapViewer1.Longitude = -77.0366
MapViewer1.Update
WebMapViewer.MapType
MapType As MapTypes
Sets or gets the type of map being displayed.
Change the map type to a road map:
Me.MapType = WebMapViewer.MapTypes.RoadMap
WebMapViewer.Mode
Mode As Modes
Sets or gets the mode of the map being displayed.
Change the map type to street view:
Me.Mode = WebMapViewer.Modes.StreetView
WebMapViewer.ModeData
ModeData As String
The data required for the Mode when it's set to Place or Search.
WebMapViewer.Name
Name As String
The name of the control.
This property is read-only.
WebMapViewer.PanelIndex
PanelIndex As Integer
If the control has been placed on a WebTabPanel or WebPagePanel control, this is the panel (page/tab) that the control is on. If the control is not on a panel, it returns -1.
The first panel is numbered zero. If the control has been placed on a panel of a WebTabPanel or WebPagePanel control, it returns the panel number. If the control is not on a WebPagePanel or WebTabPanel, it returns -1. If you change the PanelIndex to a nonexistent panel, the control will disappear until you give it a PanelIndex value that corresponds to a panel that exists.
If you are looking to change the currently selected panel (page/tab), use SelectedPanelIndex.
This code displays the panel index of the control that is on the page.
MessageBox(Me.SelectedPanelIndex.ToString)
WebMapViewer.Page
Page As WebPage
Identifies the web page that contains the control.
This property is read-only.
WebMapViewer.Parent
Parent As WebView
Used to get the control's parent control or page. If the parent control is a WebContainer, then it returns the WebContainer. If it is on a WebPage, it returns the WebPage.
This property is read-only.
WebMapViewer.Renderer
Renderer As Renderers
Indicates which map service provider will be used to render the map.
WebMapViewer.RouteDrawingColor
RouteDrawingColor As ColorGroup
The color of the route on the map.
WebMapViewer.RoutePenSize
RoutePenSize As Integer
The thickness of the line that indicates the route on the map.
WebMapViewer.StyleURL
StyleURL As String
Returns a URL from the map providing pointing to the location of a style file.
Style files are JSON documents that follow the MapLibre Style Spec.
The easiest way to create a customized map is to register in one of the providers that supports this format. These providers will give you a style URL that you can use with your map:
By default, Xojo uses OpenStreetMap raster tiles which should be OK for development or small web applications.
You are not limited to using third party providers anymore. In projects where privacy is important or when you don not want to be worried about monthly limits or prices, you can use software installed on premises to serve your own map vector tiles.
Martin is Open Source, but you can also use a commercial solution like MapTiler Server.
WebMapViewer.TabIndex
TabIndex As Integer
The WebMapViewer's control's position in the Tab Order. The control with a TabIndex of 0 is the first WebUIControl to get the focus when the page opens in the browser.
This example sets the control's TabIndex.
Me.TabIndex = 2
WebMapViewer.Tooltip
Tooltip As WebToolTip
Text of a message displayed as a tooltip.
The tip is displayed when the user places the mouse on the control and leaves it there.
This code in the Shown event of a Button sets the tooltip:
Me.Tooltip = "Save changes"
WebMapViewer.Top
Top As Integer
The top of the control in local coordinates relative to the web page.
WebMapViewer.Visible
Visible As Boolean
If True, the control is drawn. If False, it's not.
Hide a control based on a checkbox setting:
If ShowEmailCheckbox.Value Then
EmailField.Visible = True
Else
EmailField.Visible = False
End If
WebMapViewer.Width
Width As Integer
The width (in pixels) of the web control.
This code in the Shown event handler increases the size of the control:
Me.Width = Me.Width + 50
WebMapViewer.Zoom
Zoom As Integer
Sets or gets the zoom level of the map being displayed.
Typically the Zoom is a value from 1 (minimum zoom) to 20 (maximum zoom).
Zoom in the current map location to the maximum zoom, which is typically street-level:
Me.Zoom = 20
Method descriptions
WebMapViewer.AddLocation
AddLocation(Location As WebMapLocation)
Adds a WebMapLocation object to the map, indicated by a pin.
Add a location to the map:
Var location As New WebMapLocation("Fenway Park, Boston, MA")
WebMapViewer1.AddLocation(location)
AddLocation(ParamArray locations() As WebMapLocation)
Adds the locations objects to the map, indicated by pins.
AddLocation(locations() As WebMapLocation)
Adds the array of location objects to the map, indicated by pins.
WebMapViewer.Close
Close
Removes the control from the page.
WebMapViewer.CSSClasses
CSSClasses
Returns the instance of WebCSSClasses for this control allowing you to add CSS classes to and remove CSS classes from the control.
WebMapViewer.DrawRoute
DrawRoute(route As MapRoute)
Draws the route on the map.
DrawRoute(transportType As MapRoute.TransportTypes = MapRoute.TransportTypes.Car)
Draws the route based upon locations that have been added with AddLocation.
WebMapViewer.ExecuteJavaScript
ExecuteJavaScript(Script As String)
Executes the JavaScript passed. The JavaScript passed can call a JavaScript function in a WebPageSource control.
The Xojo web framework uses EcmaScript 6 which is more strict than previous versions of JavaScript. For more details, see the EcmaScript 6 documentation.
This code in the Pressed event of a Button displays an alert using JavaScript:
Me.ExecuteJavaScript("alert('Hello!');")
This code will select the text in a WebTextField (or WebTextArea):
WebTextField1.ExecuteJavascript("document.getElementById('" + _
WebTextField1.ControlID + "_inner').select();")
WebMapViewer.Route
Route(transportType As MapRoute.TransportTypes = MapRoute.TransportTypes.Car)
Returns a route based upon the locations added with AddLocation.
WebMapViewer.GoToLocation
GoToLocation(location As WebMapLocation, fly As Boolean = False)
Centers the map on the passed WebMapLocation.
Centers the map on the specific location:
Var location As New WebMapLocation("Fenway Park, Boston, MA")
MapViewer1.GoToLocation(location)
WebMapViewer.GotoURL
GotoURL(Url As String, inNewWindow As Boolean = False)
Opens the passed URL in place of the current web page or downloads a file. If InNewWindow is True, the browser is asked to open the URL in a new window.
If the browser has popup windows disabled and InNewWindow is True, the method silently fails and the page is not shown.
If InNewWindow is False, the running web app is replaced with the specified URL. If you want to display an external web site within your web app, use the WebHTMLViewer control.
Display a web site in a new popup window:
Me.GotoURL("http://www.wikipedia.org", True)
WebMapViewer.LastLocationIndex
LastLocationIndex As Integer
The index of the last location.
WebMapViewer.LocationAt
LocationAt(index As Integer) As WebMapLocation
The map location at the index passed.
WebMapViewer.LocationCount
LocationCount As Integer
The number of locations on the map that were added with the AddLocation method.
WebMapViewer.RemoveAllLocations
RemoveAllLocations
Removes all locations from the map that were added with the AddLocation method.
WebMapViewer.RemoveLocation
RemoveLocation(Location As WebMapLocation)
Removes a WebMapLocation object from the map. If the location is visible on the map, the icon is also removed.
If Location is a property of the web page for a location that has been previously added, you can remove it:
If Location Is Not Nil Then
MapViewer1.RemoveLocation(location)
End If
WebMapViewer.RemoveLocationAt
RemoveLocationAt(index As Integer)
Removes the location (added with the AddLocation method) at the index passed from the map.
WebMapViewer.RemoveRoute
RemoveRoute
Removes the route from the map.
WebMapViewer.Search
Search(Query As String)
Performs a maps query based upon the query passed.
WebMapViewer.SetFocus
SetFocus
Sets the focus to the Control.
This code checks for a required value when a button is pressed:
If UserNameField.Text.IsEmpty Then
MessageBox("Please enter your UserName.")
UserNameField.SetFocus
Return
End If
WebMapViewer.Style
Style As WebStyle
Returns the WebStyle for the control.
Style(Assigns style As WebStyle)
Assigns the style to the control.
In this example, in any event of the control, set the text to bold:
Var style As New WebStyle
style.Bold = True
Me.Style = style
WebMapViewer.UpdateBrowser
UpdateBrowser
Forces the current values of the control to be sent to the browser.
This method is useful when you are computing values in a loop and wish to update the browser immediately rather than wait until the current method ends.
This code iterates through a RowSet of database rows, updates a ProgressBar and then forces the updated ProgressBar to be sent to the browser via UpdateBrowser.
ProgressBar1.MaximumValue = SalesData.RowCount
For Each row As DatabaseRow in SalesData
AnalyzeSales(row)
ProgressBar1.Value = ProgressBar1.Value + 1
ProgressBar1.UpdateBrowser
Next
Event descriptions
WebMapViewer.CenterChanged
CenterChanged(latitude As Double, longitude As Double)
The map has been recentered.
WebMapViewer.Closed
Closed
The control has been removed from the browser either because the page has closed or the control's Close method was called.
WebMapViewer.ContextualMenuSelected
ContextualMenuSelected(hitItem As WebMenuItem)
Called when a contextual menu item is selected. This selected item is contained in hitItem.
This code populates a contextual menu in the Opening event of a WebToolbar:
Var menu As New WebMenuItem
menu.AddMenuItem("One")
menu.AddMenuItem("Two")
menu.AddMenuItem("Three")
Me.ContextualMenu = menu
The menu selection is then handled by the ContextualMenuSelected event when the user right-clicks on the control. For example, it can be of the form:
Select Case hitItem.Text
Case "One"
MessageBox("One")
Case "Two"
MessageBox("Two")
Case "Three"
MessageBox("Three")
End Select
WebMapViewer.DoublePressed
DoublePressed(latitude As Double, longitude As Double)
The user double-clicked or double-tapped a location on the map.
WebMapViewer.Hidden
Hidden
The control is about to become no longer visible. This could be because the page is being closed, is being replaced as the foreground page by another page or because the control or a parent control's Visible property has been set to False.
Note
This event is equivalent to the DesktopWindow.Deactivated event in a desktop app.
WebMapViewer.LocationSelected
LocationSelected(location As WebMapLocation)
The location passed has been selected by the user.
WebMapViewer.Opening
Opening
The control has been created and the page is opening but has not been sent to the browser yet.
The Opening event handler can be used to initialize non-visual properties and settings for controls.
In most cases, you should use the Shown event to initialize controls.
WebMapViewer.Pressed
Pressed(latitude As Double, longitude as Double)
A location on the map at the latitude and longitude passed as been tapped or clicked.
WebMapViewer.Shown
Shown
The control has appeared on the currently displayed page. This could be because its parent page just finished loading, its parent page has come to the foreground or the control is now visible having been previously invisible because it or its parent control's Visible property has been set to True.
Use the Shown event for initializing your controls or doing anything that would interact with other controls or user interface elements on the web page instead of the Opening event.
Note
This event is the web equivalent to the DesktopWindow.Activated event.
This code in the Shown event of a WebListBox adds 2 rows with 3 columns:
Me.RemoveAllRows
Me.AddRow("Row 1", "Bob", "Roberts")
Me.AddRow("Row 2", "Barb", "Reynolds")
This example sets the text of a label:
If Session.LoggedIn Then
Me.Text = "Welcome!"
Else
Me.Text = "Welcome, " + Session.UserName
End If
WebMapViewer.ZoomChanged
ZoomChanged(zoomLevel As Integer)
The level of map magnification (zoom) has changed.
Notes
Warning
As of June 2018, Google Maps requires an API Key. You will need to set the APIKey property to your API Key in order for WebMapViewer to display any maps.
The WebMapViewer control is based on Google maps. As such, has the same strengths and limitations of Google Maps.
If errors occur during initialization of the WebMapViewer and you are running in debug mode, the error messages will appear in the IDE Messages pane.
Google maps api key
As of June 2018, Google Maps requires an API Key. Visit the Google Maps docs for more information on usage:
Google Maps Platform User Guide
The mapviewer user interface
When you add a WebMapViewer control to a WebPage, it comes with widgets to manipulate the zoom, the type, and the location. The zoom level is adjusted via the Slider control on the left and you can change the location by dragging with the hand (top-left). The type of map is changed by clicking the segmented control on the top-right corner. When you change the type (for example, from Map to Satellite), a check box appears below the Segmented Control to toggle that view type. If Map is selected, a Terrain checkbox appears to show or hide terrain features; if Satellite is selected, a checkbox appears to show or hide labels.
Sample code
Create and display a location on the map:
Var location As New WebMapLocation("Fenway Park, Boston, MA")
MapViewer1.GoToLocation(location)
Display a location entered by the user (in the LocationField TextField) on the map:
MapViewer1.Search(LocationField.Text)
Compatibility
Web projects on all supported operating systems.
See also
WebUIControl parent class; WebMapLocation class.