. In this example we will create a
class to add tooltips for the map shapes, showing the Area, Population and Population Density for each map region.
[C#]
using
System;
using
System.Drawing;
using
System.Globalization;
using
System.IO;
using
System.Windows.Forms;
using
Nevron.Diagram;
using
Nevron.Diagram.Maps;
using
Nevron.GraphicsCore;
...
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender, EventArgs e)
{
view.ViewLayout = ViewLayout.Fit;
document.Style.FillStyle =
new
NColorFillStyle(Color.FromArgb(204, 255, 204));
document.Style.StrokeStyle =
new
NStrokeStyle(
new
NLength(0.75f, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119));
document.RoutingManager.Enabled =
false
;
document.BridgeManager.Enabled =
false
;
document.Bounds =
new
NRectangleF(0, 0, 2700, 2700);
document.BackgroundStyle.FillStyle =
new
NColorFillStyle(Color.White);
// create the map
NEsriMap m_Map =
new
NEsriMap();
// create the COUNTRIES shape file
NEsriShapefile countries = m_Map.Add(SHAPEFILE_NAME);
countries.NameColumn =
"GMI_ADMIN"
;
countries.TextColumn =
"ADMIN_NAME"
;
// read the map data
m_Map.Read();
// create a feature created callback
m_Map.ShapeImporter.FeatureCreatedCallback =
new
NFeatureCallback();
// create a fill rule
NMapFillRuleRange fillRule =
new
NMapFillRuleRange(countries,
"POP_ADMIN"
, Color.Green, Color.White, 9);
fillRule.DataGrouping = DataGrouping.Optimal;
m_Map.FillRules.Add(fillRule);
// import the map data
m_Map.Import(document, document.Bounds);
// make the Map layer the active layer so that the user can select the map shapes
string
layerName = Path.GetFileNameWithoutExtension(SHAPEFILE_NAME);
NLayer mapLayer = (NLayer)document.Layers.GetChildByName(layerName);
document.ActiveLayerUniqueId = mapLayer.UniqueId;
// size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding);
}
// select the map shape file
private
const
string
SHAPEFILE_NAME = @
"C:\Maps\japan.shp"
;
}
class
NFeatureCallback : NFeatureCreatedCallback
{
#region INFeatureCreatedCallback Members
public
override
bool
OnPolygonCreated(NDiagramElement element, NGisFeature feature)
{
NShape shape = element
as
NShape;
if
(shape ==
null
)
return
true
;
string
name = feature.Attributes[
"ADMIN_NAME"
].ToString();
float
population = Single.Parse(feature.Attributes[
"POP_ADMIN"
].ToString(), CultureInfo.InvariantCulture);
float
area = Single.Parse(feature.Attributes[
"SQKM_ADMIN"
].ToString(), CultureInfo.InvariantCulture);
// add a tooltip to the map shapes
NInteractivityStyle interactivityStyle =
new
NInteractivityStyle(
string
.Format(
"{1}{0}======================{0}Area: {2:N} km2{0}Population: {3:N0} people{0}Pop. Density: {4:N} people/km2"
,
Environment.NewLine, name, area, population, population / area));
shape.Style.InteractivityStyle = interactivityStyle;
return
true
;
}
public
override
bool
OnMultiPolygonCreated(NDiagramElement element, NGisFeature feature)
{
return
OnPolygonCreated(element, feature);
}
#endregion
}
[VB.NET]
Imports
System
Imports
System.Drawing
Imports
System.Globalization
Imports
System.IO
Imports
System.Windows.Forms
Imports
Nevron.Diagram
Imports
Nevron.Diagram.Maps
Imports
Nevron.GraphicsCore
...
Public
Class
Form1
Private
Sub
Form1_Load(
ByVal
sender
As
System.
Object
,
ByVal
e
As
System.EventArgs)
Handles
MyBase
.Load
view.ViewLayout = ViewLayout.Fit
document.Style.FillStyle =
New
NColorFillStyle(Color.FromArgb(204, 255, 204))
document.Style.StrokeStyle =
New
NStrokeStyle(
New
NLength(0.75F, NGraphicsUnit.Point), Color.FromArgb(119, 119, 119))
document.RoutingManager.Enabled =
False
document.BridgeManager.Enabled =
False
document.Bounds =
New
NRectangleF(0, 0, 2700, 2700)
document.BackgroundStyle.FillStyle =
New
NColorFillStyle(Color.White)
' create the map
Dim
m_Map
As
New
NEsriMap()
' create the COUNTRIES shape file
Dim
countries
As
NEsriShapefile = m_Map.Add(SHAPEFILE_NAME)
countries.NameColumn =
"GMI_ADMIN"
countries.TextColumn =
"ADMIN_NAME"
' read the map data
m_Map.Read()
' create a feature created callback
m_Map.ShapeImporter.FeatureCreatedCallback =
New
NFeatureCallback()
' create a fill rule
Dim
fillRule
As
New
NMapFillRuleRange(countries,
"POP_ADMIN"
, Color.Green, Color.White, 9)
fillRule.DataGrouping = DataGrouping.Optimal
m_Map.FillRules.Add(fillRule)
' import the map data
m_Map.Import(document, document.Bounds)
' make the Map layer the active layer so that the user can select the map shapes
Dim
layerName
As
String
= Path.GetFileNameWithoutExtension(SHAPEFILE_NAME)
Dim
mapLayer
As
NLayer =
DirectCast
(document.Layers.GetChildByName(layerName), NLayer)
document.ActiveLayerUniqueId = mapLayer.UniqueId
' size to visible shapes
document.SizeToContent(document.AutoBoundsMinSize, document.AutoBoundsPadding)
End
Sub
' select the map shape file
Private
Const
SHAPEFILE_NAME
As
String
=
"C:\Maps\japan.shp"
End
Class
Class
NFeatureCallback
Inherits
NFeatureCreatedCallback
#Region "INFeatureCreatedCallback Members"
Public
Overrides
Function
OnPolygonCreated(
ByVal
element
As
NDiagramElement,
ByVal
feature
As
NGisFeature)
As
Boolean
Dim
shape
As
NShape = TryCast(element, NShape)
If
shape
Is
Nothing
Then
Return
True
End
If
Dim
name
As
String
= feature.Attributes(
"ADMIN_NAME"
).ToString()
Dim
population
As
Single
= [
Single
].Parse(feature.Attributes(
"POP_ADMIN"
).ToString(), CultureInfo.InvariantCulture)
Dim
area
As
Single
= [
Single
].Parse(feature.Attributes(
"SQKM_ADMIN"
).ToString(), CultureInfo.InvariantCulture)
' add a tooltip to the map shapes
Dim
interactivityStyle
As
New
NInteractivityStyle(
String
.Format(
"{1}{0}======================{0}Area: {2:N} km2{0}Population: {3:N0} people{0}Pop. Density: {4:N} people/km2"
, Environment.NewLine, name, area, population, population / area))
shape.Style.InteractivityStyle = interactivityStyle
Return
True
End
Function
Public
Overrides
Function
OnMultiPolygonCreated(
ByVal
element
As
NDiagramElement,
ByVal
feature
As
NGisFeature)
As
Boolean
Return
OnPolygonCreated(element, feature)
End
Function
#End Region
End
Class
For more details, take a look at the
.NET Vision Help Documentation
Diagram for .NET >> User’s Guide >> Maps