MapView
Wisej.NET 4.2.0+
The MapView puts a slippy map on a form: raster tiles the user can pan and zoom, markers for the places your data is about, and polygon regions shaded by a value. It is a native Wisej.NET control rather than an embedded map page, so markers are a collection you edit in C#, clicks arrive as server events, and the markers, zoom buttons and legend follow the theme.
Use it for the "where" of a business screen: depots and shipments, field technicians, stores, customers by region. Where a list of addresses is enough, a DataGridView is still the better tool; where the map needs a vendor's full feature set, host that vendor's page in an IFramePanel instead.
For a complete list of properties, methods, and events, see the API documentation.
Features
Coordinates
Every position is a GeoPoint, an immutable structure created as new GeoPoint(latitude, longitude) — latitude first, in degrees. The constructor validates both values, and its Latitude and Longitude properties read them back. GeoJSON, by contrast, lists longitude first, as its specification requires; the Regions property follows GeoJSON.
The viewport is Center, a GeoPoint, and Zoom, an integer from 0 (the whole world) to 19 (street level). The defaults are (0, 0) and 3. PanTo(point) moves the center and keeps the zoom.
Tile Providers
Provider selects where the map tiles come from:
| Value | Tiles |
|---|---|
OSM | OpenStreetMap standard tiles. The default. |
Azure | Azure Maps road tiles. Requires AzureMapsKey. |
CustomTiles | Your own XYZ server, set in TileUrlTemplate with {z}, {x} and {y} placeholders: an HTTP or HTTPS address, or a path starting with / on your own application. |
Tiles are requested by the browser, not by the server, so an AzureMapsKey is visible to anyone who opens the page. When a key has to stay secret, serve the tiles through a proxy in your application and point CustomTiles at it. Attribution adds your own credit beside the provider's.
MapStyle changes how the tiles are drawn: Light shows them as delivered, and Dark applies the theme's dark filter to the tile images only, leaving markers and regions untouched.
Markers and Clusters
Markers is a collection of MapMarker objects. A marker has a Location, a Text label, an optional Badge shown beside it, a Tone for the colour of its dot (a ChipTone: Neutral, Primary, Success, Warning or Danger), and Pulse to make it pulse. Its Tag holds any object of yours and never travels to the browser.
Markers notify the map when they change, so editing a property of a marker already in the collection updates the map with no further call. With Cluster on, the default, markers that are close together at the current zoom are drawn as a single count; clicking the count zooms in on it.
FitBounds() sets the center and zoom so that every marker is visible, with 64 pixels of padding. An overload takes the markers to fit and the padding. Call it after the control has its final size, since the zoom it picks depends on the size.
Regions
Regions takes GeoJSON text — a Feature or a FeatureCollection of Polygon or MultiPolygon geometry — and draws each feature as a shaded area. The number under the property named by ValueMember (default value) in a feature's properties picks its shade: values are split into five equal steps between the lowest and the highest, and a feature without a number gets a neutral fill. A name property becomes the region's tooltip. With ShowLegend on, a legend titled by LegendText shows the scale.
Invalid GeoJSON throws and leaves the current regions in place.
Events
| Event | Raised when | Event data |
|---|---|---|
MarkerClick | A single marker is clicked or activated from the keyboard. | MapMarkerEventArgs: Marker |
RegionClick | A region is clicked. | MapRegionEventArgs: FeatureId, Value |
MapClick | The map background is clicked without panning. | MapClickEventArgs: Location |
ViewChanged | The center or zoom changes, from code or after the user finishes panning or zooming. | MapViewEventArgs: Center, Zoom |
CenterChanged and ZoomChanged are raised as well, with plain EventArgs, so Center and Zoom can be data-bound.
How To
Show Locations from Your Data
Create one marker per record and keep the record in Tag.
foreach (var depot in depots)
{
this.mapView1.Markers.Add(new MapMarker
{
Location = new GeoPoint(depot.Latitude, depot.Longitude),
Text = depot.City,
Badge = depot.OpenOrders.ToString(),
Tone = depot.OpenOrders > 40 ? ChipTone.Warning : ChipTone.Success,
Tag = depot
});
}
this.mapView1.FitBounds();
Respond to a Marker Click
private void mapView1_MarkerClick(object sender, MapMarkerEventArgs e)
{
var depot = (Depot)e.Marker.Tag;
this.dataGridViewOrders.DataSource = this.orders.Where(o => o.DepotId == depot.Id).ToList();
// Flag the marker the user is looking at.
foreach (var marker in this.mapView1.Markers)
marker.Pulse = marker == e.Marker;
}
Shade Sales Regions
Load the GeoJSON once, name the property that carries the number, and read the clicked feature back by its id.
this.mapView1.ValueMember = "revenue";
this.mapView1.LegendText = "Revenue (k€)";
this.mapView1.Regions = File.ReadAllText(Application.MapPath("Data/regions.geojson"));
this.mapView1.RegionClick += (s, e) =>
{
this.labelRegion.Text = e.Value.HasValue
? $"{e.FeatureId}: {e.Value:N0}k€"
: $"{e.FeatureId}: no sales";
};
Use Your Own Tile Server
this.mapView1.Provider = MapProvider.CustomTiles;
this.mapView1.TileUrlTemplate = "/tiles/{z}/{x}/{y}.png";
this.mapView1.Attribution = "© Example Logistics";
this.mapView1.MapStyle = MapStyle.Dark;
Advanced
JavaScript Widget
| Item | Description |
|---|---|
| Class name | "wisej.web.MapView" |
| Theme appearance | "mapview", see Themes. Markers use "mapview-marker" (with a "soft-" state per tone), the zoom buttons "mapview-zoom" and the credit line "mapview-credit". |
| Child components | "tiles" holds the tile images. "regions" draws the regions and the legend. "credits" is the attribution line. "zoomIn" and "zoomOut" are the zoom buttons. See JavaScript. |