User Tools

Site Tools


source_code_webeditionsample_projectionreadingprjfile_cs_110526.zip

Source Code WebEditionSample ProjectionReadingPrjFile CS 110526.zip

Banner.ascx.cs

using System;
using System.IO;
public partial class Banner : System.Web.UI.UserControl
{
    private const string PreStart = "<body oncontextmenu='return false;'><pre name='code' class='c-sharp:nocontrols'>";
    private const string PreEnd = "</pre><link type='text/css' rel='stylesheet' href='../Resources/SyntaxHighlighter/SyntaxHighlighter.css'></link><script language='javascript' src='../Resources/SyntaxHighlighter/shCore.js'></script><script language='javascript' src='../Resources/SyntaxHighlighter/shBrushCSharp.js'></script><script language='javascript' src='../Resources/SyntaxHighlighter/shBrushXml.js'></script><script language='javascript'>dp.SyntaxHighlighter.HighlightAll('code');</script></body>";
    private const string ErrorPageUrl = "~/Source Code Not Available in Beta.html";
    protected void Page_Load(object sender, EventArgs e)
    {
        string filename = "Sample.aspx.cs";
        string htmlFileName = filename.Replace(".cs", ".htm");
        if (File.Exists(htmlFileName))
        {
            return;
        }
        string text;
        try
        {
            using (StreamReader sr = new StreamReader(Server.MapPath(filename)))
            {
                text = sr.ReadToEnd();
            }
            text = PreStart + text + PreEnd;
            using (StreamWriter sw = new StreamWriter(Server.MapPath(htmlFileName)))
            {
                sw.Write(text);
            }
        }
        catch
        {
            htmlFileName = ErrorPageUrl;
        }
        return;
    }
}

Footer.ascx.cs

using System;
public partial class Footer : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
}

Sample.aspx.cs

using System;
using System.Web.UI;
using ThinkGeo.MapSuite.Core;
using ThinkGeo.MapSuite.WebEdition;
public partial class Sample : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Set the map unit to Meters because our basemap will be projected in Spherical Mercator which uses Meters for the unit.
            Map1.MapUnit = GeographyUnit.Meter;
            Map1.MapTools.Logo.Enabled = true;
            //Create a World Map Kit overlay and set it to Spherical Mercator projection.  This is the standard projection used by Google, Bing, OSM, etc.
            WorldMapKitWmsWebOverlay worldMapKitWmsWebOverlay = new WorldMapKitWmsWebOverlay();
            worldMapKitWmsWebOverlay.Projection = WorldMapKitProjection.SphericalMercator;
            //Load the US States shapefile.  This shapefile is in Decimal Degree.  Later we will reproject it to Spherical Mercator by reading the .prj file.
            ShapeFileFeatureLayer statesLayer = new ShapeFileFeatureLayer(Server.MapPath(@"~\Data\USStates.shp"));
            statesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(new GeoPen(GeoColor.StandardColors.Green, 2));
            statesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            //reproject the statesLayer to Spherical Mercator to match the base map's projection.
            Proj4Projection proj4 = new Proj4Projection();
            string prjFileText = System.IO.File.ReadAllText(Server.MapPath(@"~\Data\USStates.prj")); //get the text of the .prj file.
            proj4.InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(prjFileText); //set the internal projection.  The new ConvertPrjToProj4 methid is the key to this process.
            proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //set the external projection.  In this case, it's Spherical Mercator (which google/bing, etc all use).
            statesLayer.FeatureSource.Projection = proj4;
            //Create the overlay for US states and add it to the map.
            LayerOverlay statesOverlay = new LayerOverlay("StateOverlay");
            statesOverlay.Layers.Add("StateLayer", statesLayer);
            statesOverlay.IsBaseOverlay = false;
            //add our overlays to the map.
            Map1.CustomOverlays.Add(worldMapKitWmsWebOverlay);
            Map1.CustomOverlays.Add(statesOverlay);
            //zoom the map to the extent of the US States.
            Map1.CurrentExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
        }
    }
}

InstructionsPanel.cs

using System;
using System.ComponentModel;
using System.IO;
using System.Web.UI.WebControls;
namespace DisplayASimpleMap
{
    // This class represents the "instructions" floating panel.
    [ToolboxItem(false)]
    public class InstructionPanel : Panel
    {
        protected override void OnPreRender(System.EventArgs e)
        {
            StreamReader reader = File.OpenText(Page.MapPath("~/Resources/InstructionsPanel/InstructionsPanel.js"));
            string script = reader.ReadToEnd();
            reader.Close();
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "PanelScript", script, true);
            base.OnPreRender(e);
        }
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            StreamReader reader = File.OpenText(Page.MapPath("~/Resources/InstructionsPanel/InstructionsPanel.htm"));
            string[] script = reader.ReadToEnd().Split(new string[] { "<!--Split-->" }, StringSplitOptions.RemoveEmptyEntries);
            reader.Close();
            writer.WriteLine(script[0].Trim());
            base.Render(writer);
            writer.WriteLine(script[1].Trim());
        }
    }
}

Sample.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sample.aspx.cs" Inherits="Sample" %>
<%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %>
<%@ Register Src="Footer.ascx" TagName="Footer" TagPrefix="uc1" %>
<%@ Register Src="Banner.ascx" TagName="Banner" TagPrefix="uc2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <link href="Resources/css.css" rel="stylesheet" type="text/css" />
    <title>Projection By Reading a Prj File - Map Suite Web Sample Application</title>
</head>
<body onresize="resizeElementHeight()">
    <form id="form1" runat="server">
    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;">
        <tr>
            <td>
                <uc2:Banner ID="Header1" runat="server" />
            </td>
        </tr>
        <tr>
            <td align="left">
                <div id="TabContainer">
                    <a id="A1" runat="server" class="tab selected" href="#" onclick="this.className='tab selected';document.getElementById('A2').className='tab';document.getElementById('maptoggle').style.display='block';document.getElementById('sourcecode').style.display='none';">
                        Map View</a> <a id="A2" runat="server" class="tab" href="#" onclick="this.className='tab selected';document.getElementById('A1').className='tab';document.getElementById('sourcecode').style.display='block';document.getElementById('maptoggle').style.display='none';">
                            Source Code</a>
                </div>
            </td>
        </tr>
        <tr>
            <td align="center">
                <div id="MapContainer">
                    <div id="maptoggle">
                        <asp:ScriptManager ID="ScriptManager1" runat="server">
                        </asp:ScriptManager>
                        <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%">
                        </cc1:Map>
                        <Instruction:InstructionPanel ID="FunctionPanel" runat="server" Width="292px">
                            This sample demonstrates new ConvertPrjToProj4 function in the Proj4Projection class.  This enables shapefiles to be reprojected based on the shapefile's .prj file.  In the past the developer had to know the proj4 string or EPSG number.  With this new function, we can determine the projection on the fly.
                        </Instruction:InstructionPanel>
                    </div>
                    <div id="sourcecode" style="display: none;">
                        <iframe height="100%" width="100%" id="sourcepage" runat="server" src="Sample.aspx.htm">
                        </iframe>
                    </div>
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <uc1:Footer ID="Footer1" runat="server" />
            </td>
        </tr>
    </table>
    </form>
</body>
<script type="text/javascript">
    function resizeElementHeight() {
        var height = 0;
        var body = window.document.body;
        if (window.innerHeight) {
            height = window.innerHeight;
        } else if (body.parentElement.clientHeight) {
            height = body.parentElement.clientHeight;
        } else if (body && body.clientHeight) {
            height = body.clientHeight;
        }
        document.getElementById('MapContainer').style.height = ((height - 170) + "px");
    }
    var alreadyrun = 0
    if (document.addEventListener)
        document.addEventListener("DOMContentLoaded", function () { alreadyrun = 1; resizeElementHeight() }, false)
    else if (document.all && !window.opera) {
        document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>')
        var contentloadtag = document.getElementById("contentloadtag")
        contentloadtag.onreadystatechange = function () {
            if (this.readyState == "complete") {
                alreadyrun = 1
                resizeElementHeight()
            }
        }
    }
    window.onload = function () {
        setTimeout("if (!alreadyrun) resizeElementHeight()", 0)
    }
</script>
</html>
source_code_webeditionsample_projectionreadingprjfile_cs_110526.zip.txt · Last modified: 2015/09/09 03:38 by admin