====== Source Code OsmWorldMapKitRenderingCoverageReporter.zip ======
====Program.cs====
using System;
using System.Windows.Forms;
namespace WorldMapKitLayerUtility
{
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}
====MainForm.cs====
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using ThinkGeo.MapSuite.Core;
namespace WorldMapKitLayerUtility
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void btnBrowseDllFilePath_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "OsmWorldMapKitLayer.dll | OsmWorldMapKitLayer.dll";
if (dialog.ShowDialog() == DialogResult.OK)
{
txtBoxDllFilePath.Text = dialog.FileName;
}
}
private void btnBrowseCSVFilePath_Click(object sender, EventArgs e)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "CSV Files (*.csv)|*.csv";
if (dialog.ShowDialog() == DialogResult.OK)
{
txtBoxCSVFilePath.Text = dialog.FileName;
}
}
private void btnGenerateCSV_Click(object sender, EventArgs e)
{
string dllFilePath = txtBoxDllFilePath.Text;
string csvFilePath = txtBoxCSVFilePath.Text;
if (Path.GetFileName(dllFilePath) == "OsmWorldMapKitLayer.dll" && File.Exists(dllFilePath) && Path.GetExtension(csvFilePath) == ".csv")
{
try
{
ExportFeatureLayerTable(dllFilePath, csvFilePath);
MessageBox.Show("Exported to " + csvFilePath, "Success", MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
}
}
else
{
MessageBox.Show("Invalid filepath(s)!", "Error", MessageBoxButtons.OK);
}
}
private void btnCancel_Click(object sender, EventArgs e)
{
Close();
}
private void ExportFeatureLayerTable(string dllFilePath, string outputFilePath)
{
Dictionary> featureLayerTable = GetAllFeatureLayersCore(GetLayersFromAssembly(dllFilePath));
FileStream outputStream = new FileStream(outputFilePath, FileMode.Create);
StreamWriter fileWriter = new StreamWriter(outputStream);
//set up first line of feature layer names
fileWriter.Write(",");
for (int i = 1; i <= 20; i++)
{
fileWriter.Write("ZL" + i + ",");
}
fileWriter.WriteLine("");
foreach (FeatureLayer featureLayer in featureLayerTable[0])
{
fileWriter.Write(featureLayer.Name);
for (int j = 1; j <= 20; j++)
{
if (featureLayerTable[j].Contains(featureLayer))
fileWriter.Write(",X");
else
fileWriter.Write(",");
}
fileWriter.WriteLine("");
}
fileWriter.Close();
outputStream.Close();
}
private Collection GetLayersFromAssembly(string dllFilePath)
{
Assembly osmWorldMapKitLayerDll = Assembly.LoadFile(dllFilePath);
Type osmWorldMapKitLayer = osmWorldMapKitLayerDll.GetType("ThinkGeo.MapSuite.Core.OsmWorldMapKitLayer");
Type osmWorldMapKitDatabaseType = osmWorldMapKitLayerDll.GetType("ThinkGeo.MapSuite.Core.OsmWorldMapKitDatabaseType");
object osmWorldMapKitLayerInstance = Activator.CreateInstance(osmWorldMapKitLayer, null);
MethodInfo methodInfo = osmWorldMapKitLayer.GetMethod("Open");
methodInfo.Invoke(osmWorldMapKitLayerInstance, null);
PropertyInfo layersInfo = osmWorldMapKitLayer.GetProperty("Layers");
var osmWorldMapKitLayers = layersInfo.GetValue(osmWorldMapKitLayerInstance, null);
return (Collection)osmWorldMapKitLayers;
}
private bool CheckIfDefaultStyleSet(ZoomLevel zoomLevel)
{
bool defaultStyleSet = true;
ZoomLevel defaultZoomLevel = new ZoomLevel();
if (!(zoomLevel.DefaultAreaStyle == defaultZoomLevel.DefaultAreaStyle))
defaultStyleSet = false;
else if (!(zoomLevel.DefaultLineStyle == defaultZoomLevel.DefaultLineStyle))
defaultStyleSet = false;
else if (!(zoomLevel.DefaultPointStyle == defaultZoomLevel.DefaultPointStyle))
defaultStyleSet = false;
else if (!(zoomLevel.DefaultTextStyle == defaultZoomLevel.DefaultTextStyle))
defaultStyleSet = false;
return defaultStyleSet;
}
private Dictionary> GetAllFeatureLayersCore(Collection featureLayers)
{
Dictionary> featureLayersInAllZoomLevels = new Dictionary>();
for (int i = 0; i <= 20; i++)
{
featureLayersInAllZoomLevels.Add(i, new Collection());
}
foreach (FeatureLayer layer in featureLayers)
{
featureLayersInAllZoomLevels[0].Add(layer);
Collection layerZoomLevels = layer.ZoomLevelSet.GetZoomLevels();
for (int i = 1; i <= 20; i++)
{
ZoomLevel zoomLevel = layerZoomLevels[i - 1];
if (!(zoomLevel.CustomStyles.Count == 0 || CheckIfDefaultStyleSet(zoomLevel)))
{
if ((int)zoomLevel.ApplyUntilZoomLevel == 0)
{
if (!featureLayersInAllZoomLevels[i].Contains(layer))
featureLayersInAllZoomLevels[i].Add(layer);
}
else
{
for (int j = i; j <= (int)zoomLevel.ApplyUntilZoomLevel; j++)
{
if (!featureLayersInAllZoomLevels[j].Contains(layer))
featureLayersInAllZoomLevels[j].Add(layer);
}
}
}
}
}
return featureLayersInAllZoomLevels;
}
private void btnViewRenderingCoverage_Click(object sender, EventArgs e)
{
string dllFilePath = txtBoxDllFilePath.Text;
dataGridRenderingCoverage.Rows.Clear();
dataGridRenderingCoverage.Columns.Clear();
if (Path.GetFileName(dllFilePath) == "OsmWorldMapKitLayer.dll" && File.Exists(dllFilePath))
{
Dictionary> featureLayerTable = GetAllFeatureLayersCore(GetLayersFromAssembly(dllFilePath));
dataGridRenderingCoverage.Columns.Add("", "");
dataGridRenderingCoverage.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
for (int i = 1; i <= 20; i++)
{
dataGridRenderingCoverage.Columns.Add("ZL" + i, "ZL" + i);
dataGridRenderingCoverage.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
}
dataGridRenderingCoverage.Rows.Add(featureLayerTable[0].Count);
for (int i = 0; i < featureLayerTable[0].Count; i++)
{
dataGridRenderingCoverage.Rows[i].Cells[0].Value = featureLayerTable[0][i].Name;
}
for (int i = 1; i <= 20; i++)
{
for (int j = 0; j < featureLayerTable[0].Count; j++)
{
if (featureLayerTable[i].Contains(featureLayerTable[0][j]))
{
dataGridRenderingCoverage.Rows[j].Cells[i].Value = "X";
}
}
}
}
}
}
}
====MainForm.Designer.cs====
namespace WorldMapKitLayerUtility
{
partial class MainForm
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.txtBoxDllFilePath = new System.Windows.Forms.TextBox();
this.btnGenerateCSV = new System.Windows.Forms.Button();
this.btnBrowseDllFilePath = new System.Windows.Forms.Button();
this.btnBrowseCSVFilePath = new System.Windows.Forms.Button();
this.txtBoxCSVFilePath = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.dataGridRenderingCoverage = new System.Windows.Forms.DataGridView();
this.btnViewRenderingCoverage = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridRenderingCoverage)).BeginInit();
this.SuspendLayout();
//
// txtBoxDllFilePath
//
this.txtBoxDllFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtBoxDllFilePath.Location = new System.Drawing.Point(219, 14);
this.txtBoxDllFilePath.Name = "txtBoxDllFilePath";
this.txtBoxDllFilePath.Size = new System.Drawing.Size(366, 20);
this.txtBoxDllFilePath.TabIndex = 0;
//
// btnGenerateCSV
//
this.btnGenerateCSV.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnGenerateCSV.Location = new System.Drawing.Point(644, 579);
this.btnGenerateCSV.Name = "btnGenerateCSV";
this.btnGenerateCSV.Size = new System.Drawing.Size(101, 36);
this.btnGenerateCSV.TabIndex = 2;
this.btnGenerateCSV.Text = "Generate CSV";
this.btnGenerateCSV.UseVisualStyleBackColor = true;
this.btnGenerateCSV.Click += new System.EventHandler(this.btnGenerateCSV_Click);
//
// btnBrowseDllFilePath
//
this.btnBrowseDllFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnBrowseDllFilePath.Location = new System.Drawing.Point(591, 12);
this.btnBrowseDllFilePath.Name = "btnBrowseDllFilePath";
this.btnBrowseDllFilePath.Size = new System.Drawing.Size(84, 23);
this.btnBrowseDllFilePath.TabIndex = 3;
this.btnBrowseDllFilePath.Text = "Browse...";
this.btnBrowseDllFilePath.UseVisualStyleBackColor = true;
this.btnBrowseDllFilePath.Click += new System.EventHandler(this.btnBrowseDllFilePath_Click);
//
// btnBrowseCSVFilePath
//
this.btnBrowseCSVFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnBrowseCSVFilePath.Location = new System.Drawing.Point(532, 588);
this.btnBrowseCSVFilePath.Name = "btnBrowseCSVFilePath";
this.btnBrowseCSVFilePath.Size = new System.Drawing.Size(84, 23);
this.btnBrowseCSVFilePath.TabIndex = 5;
this.btnBrowseCSVFilePath.Text = "Browse...";
this.btnBrowseCSVFilePath.UseVisualStyleBackColor = true;
this.btnBrowseCSVFilePath.Click += new System.EventHandler(this.btnBrowseCSVFilePath_Click);
//
// txtBoxCSVFilePath
//
this.txtBoxCSVFilePath.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtBoxCSVFilePath.Location = new System.Drawing.Point(179, 591);
this.txtBoxCSVFilePath.Name = "txtBoxCSVFilePath";
this.txtBoxCSVFilePath.Size = new System.Drawing.Size(347, 20);
this.txtBoxCSVFilePath.TabIndex = 4;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(9, 17);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(204, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Select OSMWorldMapKitLayer.dll filepath:";
//
// label2
//
this.label2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(9, 595);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(166, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Select filepath to save .csv file to:";
//
// btnCancel
//
this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnCancel.Location = new System.Drawing.Point(751, 579);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(101, 36);
this.btnCancel.TabIndex = 8;
this.btnCancel.Text = "Close";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// dataGridRenderingCoverage
//
this.dataGridRenderingCoverage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridRenderingCoverage.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft;
dataGridViewCellStyle1.BackColor = System.Drawing.SystemColors.Window;
dataGridViewCellStyle1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
dataGridViewCellStyle1.ForeColor = System.Drawing.SystemColors.ControlText;
dataGridViewCellStyle1.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle1.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle1.WrapMode = System.Windows.Forms.DataGridViewTriState.False;
this.dataGridRenderingCoverage.DefaultCellStyle = dataGridViewCellStyle1;
this.dataGridRenderingCoverage.Location = new System.Drawing.Point(12, 63);
this.dataGridRenderingCoverage.Name = "dataGridRenderingCoverage";
this.dataGridRenderingCoverage.Size = new System.Drawing.Size(840, 510);
this.dataGridRenderingCoverage.TabIndex = 9;
//
// btnViewRenderingCoverage
//
this.btnViewRenderingCoverage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.btnViewRenderingCoverage.Location = new System.Drawing.Point(702, 8);
this.btnViewRenderingCoverage.Name = "btnViewRenderingCoverage";
this.btnViewRenderingCoverage.Size = new System.Drawing.Size(150, 45);
this.btnViewRenderingCoverage.TabIndex = 10;
this.btnViewRenderingCoverage.Text = "View Rendering Coverage";
this.btnViewRenderingCoverage.UseVisualStyleBackColor = true;
this.btnViewRenderingCoverage.Click += new System.EventHandler(this.btnViewRenderingCoverage_Click);
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(864, 621);
this.Controls.Add(this.btnViewRenderingCoverage);
this.Controls.Add(this.dataGridRenderingCoverage);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnBrowseCSVFilePath);
this.Controls.Add(this.txtBoxCSVFilePath);
this.Controls.Add(this.btnBrowseDllFilePath);
this.Controls.Add(this.btnGenerateCSV);
this.Controls.Add(this.txtBoxDllFilePath);
this.MaximizeBox = false;
this.Name = "MainForm";
this.Text = "OsmWorldMapKit Layer Utility";
((System.ComponentModel.ISupportInitialize)(this.dataGridRenderingCoverage)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox txtBoxDllFilePath;
private System.Windows.Forms.Button btnGenerateCSV;
private System.Windows.Forms.Button btnBrowseDllFilePath;
private System.Windows.Forms.Button btnBrowseCSVFilePath;
private System.Windows.Forms.TextBox txtBoxCSVFilePath;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.DataGridView dataGridRenderingCoverage;
private System.Windows.Forms.Button btnViewRenderingCoverage;
}
}