ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ThinkGeo.MapSuite.SiteSelection.Default" %> <%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %> <!DOCTYPE html> <html xml:en-us"> <head runat="server"> <title>Site Selection</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge"> <link href="Images/MapSuite.ico" rel="shortcut icon" type="Images/x-icon" /> <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" /> <link href="Styles/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="Scripts/modernizr-2.5.3.js"></script> <script src="Scripts/jquery-1.10.2.js" type="text/javascript"></script> </head> <body> <form id="Form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <div id="container"> <div id="header"> <div id="left-header"> <span id="header-mapsuite">Map Suite</span> <span id="header-title">Site Selection</span> </div> </div> <div id="content-container"> <div id="leftContainer"> <div id="leftContent"> <h4> Highlight points of this type:</h4> <asp:UpdatePanel runat="server"> <ContentTemplate> <div class="divBorder"> <asp:DropDownList ID="ddlCategory" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddlCategory_SelectedIndexChanged"> </asp:DropDownList> <asp:DropDownList ID="ddlCategorySubtype" AutoPostBack="True" runat="server" OnSelectedIndexChanged="ddlCategorySubtype_SelectedIndexChanged"> </asp:DropDownList> </div> </ContentTemplate> </asp:UpdatePanel> <h4> Place center pin on the map to highlight points of interest within a specified area around where you clicked: </h4> <div id="divTrackMode" class="divBorder"> <asp:ImageButton ID="btnNormal" runat="server" ToolTip="Switch current map to pan mode." ImageUrl="~/Images/pan.png" CommandArgument="PanMap" CssClass="active" OnCommand="TrackShapesCommand" /> <asp:ImageButton ID="btnDrawPoint" runat="server" ToolTip="Place the center pin on the map." ImageUrl="~/Images/drawPoint.png" CommandArgument="DrawPoint" OnCommand="TrackShapesCommand" /> <asp:ImageButton ID="btnClearAll" runat="server" ToolTip="Reset your selection." CommandArgument="ClearAll" OnCommand="TrackShapesCommand" ImageUrl="~/Images/clear.png" /> </div> <h4> Area Type:</h4> <div class="divBorder"> <div> <asp:RadioButton ID="rbtServiceArea" runat="server" Text=" Service Area" Checked="true" GroupName="ServiceArea" /> <div id="divService"> Service Area in <asp:TextBox runat="server" ID="tbxServiceArea" Width="40px">5</asp:TextBox> minutes Driving </div> </div> <div> <asp:RadioButton ID="rbtBufferArea" runat="server" Text=" Buffered Area" GroupName="ServiceArea" /> <div id="divBuffer" hidden="hidden"> Buffered Distance: <asp:TextBox runat="server" ID="tbxDistance" Width="40px">2</asp:TextBox> <asp:DropDownList ID="ddlDistanceUnit" runat="server"> <asp:ListItem Text="Mile"></asp:ListItem> <asp:ListItem Text="Kilometer"></asp:ListItem> </asp:DropDownList> </div> </div> <div> <asp:Button ID="btnApply" CssClass="right-float" Width="76px" runat="server" Text="Apply" OnClick="BtnApplyClick"></asp:Button> </div> </div> <div class="blueBanner"> Potential Similar Sites </div> <asp:UpdatePanel ID="queryResultUpdatePanel" runat="server"> <ContentTemplate> <asp:Repeater ID="repeaterQueryResult" runat="server" OnItemCommand="repeaterQueryResult_ItemCommand"> <HeaderTemplate> <table id="resultTable"> <tr> <td class="header"> </td> <td class="header"> Name </td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td style="width: 30px"> <asp:ImageButton ID="find" runat="server" ImageUrl="/Images/find.png" CommandArgument='<%# Eval("Wkt") %>' /> </td> <td> <%# Eval("Name") %> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </asp:Repeater> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddlCategory" /> <asp:AsyncPostBackTrigger ControlID="ddlCategorySubtype" /> <asp:AsyncPostBackTrigger ControlID="Map1" /> <asp:AsyncPostBackTrigger ControlID="btnApply" /> </Triggers> </asp:UpdatePanel> </div> </div> <div id="toggle"> <img alt="collapse" src="Images/collapse.gif" /> </div> <asp:UpdatePanel ID="mapContentPanel" runat="server"> <ContentTemplate> <div id="map-content"> <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%" OnTrackShapeFinished="Map1_TrackShapeFinished"> </cc1:Map> </div> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnNormal" /> <asp:AsyncPostBackTrigger ControlID="btnDrawPoint" /> <asp:AsyncPostBackTrigger ControlID="btnClearAll" /> <asp:AsyncPostBackTrigger ControlID="btnApply" /> </Triggers> </asp:UpdatePanel> <div id="dlgErrorMessage" title="Warning Message"> <p> Please note that this sample map is only able to analyze service areas within the Frisco, TX city limits, which are indicated by a dashed red line. Click inside that boundary for best results.</p> </div> </div> <div id="footer"> <span id="spanMouseCoordinate"></span> </div> <script type="text/javascript" src="Scripts/ready-functions.js"></script> <script src="Scripts/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script> </div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Data; using System.Globalization; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; namespace ThinkGeo.MapSuite.SiteSelection { public partial class Default : Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { // Initialize map Map1.MapUnit = GeographyUnit.Meter; Map1.MapTools.OverlaySwitcher.Enabled = true; Map1.MapTools.OverlaySwitcher.BaseOverlayTitle = " "; AddOverlays(); Map1.CurrentExtent = new RectangleShape(-10788072.2328016, 3923530.35787306, -10769555.4090135, 3906993.24816589); // Initialize dropdownlist InitializePoiCategories(); // Do a default search based on the initial candidate site BtnApplyClick(null, null); } } protected void BtnApplyClick(object sender, EventArgs e) { DisplayServiceAreas(); DisplayQueriedPois(); RefreshScaleBarUnitSystem(); } protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e) { ddlCategorySubtype.DataSource = GetCategorySubtypes(ddlCategory.SelectedValue); ddlCategorySubtype.DataBind(); ddlCategorySubtype.SelectedIndex = 0; DisplayQueriedPois(); Map1.DynamicOverlay.Redraw(); } protected void ddlCategorySubtype_SelectedIndexChanged(object sender, EventArgs e) { DisplayQueriedPois(); } protected void Map1_TrackShapeFinished(object sender, EventArgs e) { if (Map1.EditOverlay.Features.Count > 0) { PointShape drawnPoint = Map1.EditOverlay.Features[0].GetShape() as PointShape; ShapeFileFeatureLayer restrictedLayer = Map1.DynamicOverlay.Layers["restricted"] as ShapeFileFeatureLayer; restrictedLayer.Open(); Collection<Feature> features = restrictedLayer.QueryTools.GetFeaturesContaining(drawnPoint, ReturningColumnsType.NoColumns); restrictedLayer.Close(); if (features.Count <= 0) // Drawn feature is out of the supported area (out of Frisco TX.) { // Show warning information when the drawn point locate out of restricted layer. ScriptManager.RegisterStartupScript(mapContentPanel, mapContentPanel.GetType(), "Warning", @"$('#dlgErrorMessage').dialog('open');$('.ui-dialog-titlebar').hide();", true); } else { // Draw tracked Point DisplayCandidateSite(drawnPoint); // Draw the result DisplayServiceAreas(); DisplayQueriedPois(); Map1.DynamicOverlay.Redraw(); } Map1.EditOverlay.Features.Clear(); } } protected void repeaterQueryResult_ItemCommand(object source, RepeaterCommandEventArgs e) { ImageButton zoomToImageButton = e.CommandSource as ImageButton; if (zoomToImageButton != null) { string wkt = zoomToImageButton.CommandArgument; BaseShape shape = BaseShape.CreateShapeFromWellKnownData(wkt); Map1.ZoomTo(shape.GetCenterPoint(), new ZoomLevelSet().ZoomLevel20.Scale); } } protected void TrackShapesCommand(object sender, CommandEventArgs e) { switch (e.CommandArgument.ToString()) { case "DrawPoint": Map1.EditOverlay.TrackMode = TrackMode.Point; break; case "ClearAll": // clear service area and markers InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["serviceArea"]; serviceAreaLayer.InternalFeatures.Clear(); Map1.MarkerOverlay.FeatureSource.InternalFeatures.Clear(); // Clear result table repeaterQueryResult.Visible = false; repeaterQueryResult.DataSource = InternalHelper.GetQueryResultDefination(); repeaterQueryResult.DataBind(); // Clear POI markers on map. Map1.EditOverlay.FeatureSource.InternalFeatures.Clear(); InMemoryMarkerOverlay markerOverlay = Map1.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; markerOverlay.FeatureSource.InternalFeatures.Clear(); Map1.DynamicOverlay.Redraw(); break; default: Map1.EditOverlay.TrackMode = TrackMode.None; break; } } private void InitializePoiCategories() { Collection<string> categories = new Collection<string>(); foreach (Layer layer in Map1.DynamicOverlay.Layers) { if (!string.IsNullOrEmpty(layer.Name) && !layer.Name.Equals("Public Facilites") && !layer.Name.Equals("restricted")) { categories.Add(layer.Name); } } ddlCategory.DataSource = categories; ddlCategory.DataBind(); ddlCategory.SelectedIndex = 2; ddlCategorySubtype.DataSource = GetCategorySubtypes(ddlCategory.Items[2].Value); ddlCategorySubtype.DataBind(); ddlCategorySubtype.SelectedIndex = 0; } private void RefreshScaleBarUnitSystem() { ScaleBarAdornmentLayer adornmentLayer = Map1.AdornmentOverlay.Layers["ScaleBar"] as ScaleBarAdornmentLayer; DistanceUnit unit = (DistanceUnit)Enum.Parse(typeof(DistanceUnit), ddlDistanceUnit.SelectedValue); switch (unit) { case DistanceUnit.Kilometer: adornmentLayer.UnitFamily = UnitSystem.Metric; break; case DistanceUnit.Mile: adornmentLayer.UnitFamily = UnitSystem.Imperial; break; } } private Collection<string> GetCategorySubtypes(string categoryName) { Collection<string> subtypes = new Collection<string> { "All" }; if (categoryName.Equals("Hotels", StringComparison.OrdinalIgnoreCase)) { subtypes.Add("1 ~ 100"); subtypes.Add("100 ~ 150"); subtypes.Add("150 ~ 200"); subtypes.Add("200 ~ 300"); subtypes.Add("300 ~ 400"); subtypes.Add("400 ~ 500"); subtypes.Add(">= 500"); } else { string searchedColumnName = InternalHelper.GetDbfColumnByPoiType(categoryName); ShapeFileFeatureLayer queryLayer = Map1.DynamicOverlay.Layers[ddlCategory.SelectedValue] as ShapeFileFeatureLayer; queryLayer.Open(); Collection<DistinctColumnValue> columnValues = queryLayer.FeatureSource.GetDistinctColumnValues(searchedColumnName); foreach (DistinctColumnValue value in columnValues) { if (!subtypes.Contains(value.ColumnValue) && !string.IsNullOrEmpty(value.ColumnValue)) { subtypes.Add(value.ColumnValue); } } } return subtypes; } private void DisplayCandidateSite(PointShape drawPoint) { InMemoryMarkerOverlay markerOverlay = Map1.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; if (markerOverlay != null) { markerOverlay.FeatureSource.InternalFeatures.Clear(); markerOverlay.FeatureSource.InternalFeatures.Add(new Feature(drawPoint)); } } private void DisplayServiceAreas() { InMemoryMarkerOverlay markerOverlay = Map1.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; PointShape startLocation = markerOverlay.FeatureSource.InternalFeatures[0].GetShape() as PointShape; AccessibleAreaAnalyst analysis; if (rbtServiceArea.Checked) { analysis = new RouteAccessibleAreaAnalyst(startLocation, Map1.MapUnit) { StreetShapeFilePathName = MapPath("~/App_Data/Street.shp"), DrivingTimeInMinutes = int.Parse(tbxServiceArea.Text, CultureInfo.InvariantCulture) }; } else { analysis = new BufferAccessibleAreaAnalyst(startLocation, Map1.MapUnit) { Distance = double.Parse(tbxDistance.Text), DistanceUnit = (DistanceUnit)Enum.Parse(typeof(DistanceUnit), ddlDistanceUnit.SelectedValue) }; } BaseShape calculatedServiceArea = analysis.CreateAccessibleArea(); InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["serviceArea"]; serviceAreaLayer.InternalFeatures.Clear(); serviceAreaLayer.Open(); serviceAreaLayer.InternalFeatures.Add(new Feature(calculatedServiceArea)); Map1.CurrentExtent = serviceAreaLayer.GetBoundingBox(); } private void DisplayQueriedPois() { // Get querying Poi layer ShapeFileFeatureLayer queriedLayer = Map1.DynamicOverlay.Layers[ddlCategory.SelectedValue] as ShapeFileFeatureLayer; queriedLayer.Open(); // Get all POIs in Service Area InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["serviceArea"]; BaseShape calculatedServiceArea = serviceAreaLayer.InternalFeatures[0].GetShape(); Collection<Feature> featuresInServiceArea = queriedLayer.QueryTools.GetFeaturesWithin(calculatedServiceArea, ReturningColumnsType.AllColumns); InMemoryFeatureLayer highlightFeatureLayer = (InMemoryFeatureLayer)Map1.DynamicOverlay.Layers["highlightFeatureLayer"]; highlightFeatureLayer.InternalFeatures.Clear(); highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = queriedLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; // Filter the features by specific query. Collection<Feature> filteredQueryFeatures = FilterFeaturesByQueryConfiguration(featuresInServiceArea); // Prepare the queried result table DataTable queriedResult = InternalHelper.GetQueryResultDefination(); if (filteredQueryFeatures.Count > 0) { foreach (Feature feature in filteredQueryFeatures) { DataRow row = queriedResult.NewRow(); row["WKT"] = feature.GetWellKnownText(); row["Name"] = feature.ColumnValues["Name"]; queriedResult.Rows.Add(row); highlightFeatureLayer.InternalFeatures.Add(feature); } DisplyQueriedPoiOnMap(filteredQueryFeatures); } else { DataRow row = queriedResult.NewRow(); row["Name"] = "No results found."; queriedResult.Rows.Add(row); } repeaterQueryResult.Visible = true; repeaterQueryResult.DataSource = queriedResult; repeaterQueryResult.DataBind(); } private void DisplyQueriedPoiOnMap(Collection<Feature> features) { StringBuilder popupHtml = new StringBuilder("<table>"); popupHtml.Append("<tr><td colspan='2' class='popupTitle'>[#NAME#]</td></tr>"); popupHtml.Append("<tr class='popupText'><td>ADDR:</td><td>[#ADDRESS#]</td></tr>"); popupHtml.Append("<tr><td colspan='2'><div class='hrLine'></div></td></tr>"); Map1.MarkerOverlay.FeatureSource.Open(); Map1.MarkerOverlay.Columns.Clear(); foreach (var columnValue in features[0].ColumnValues) { if (!columnValue.Key.Equals("NAME", StringComparison.OrdinalIgnoreCase) && !columnValue.Key.Equals("ADDRESS", StringComparison.OrdinalIgnoreCase)) { popupHtml.Append(string.Format("<tr class='vehicleTxt'><td>{0} : </td><td>[#{0}#]</td></tr>", columnValue.Key)); } Map1.MarkerOverlay.Columns.Add(new FeatureSourceColumn(columnValue.Key)); } popupHtml.Append("</table>"); Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = popupHtml.ToString(); Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.MarkerOverlay.FeatureSource.Clear(); foreach (Feature feature in features) { Map1.MarkerOverlay.FeatureSource.InternalFeatures.Add(feature); } } private Collection<Feature> FilterFeaturesByQueryConfiguration(IEnumerable<Feature> allFeatures) { string poiCatagroy = ddlCategory.SelectedValue.Trim(); string buildType = ddlCategorySubtype.SelectedValue.Trim(); string queriedColumn = InternalHelper.GetDbfColumnByPoiType(poiCatagroy); Collection<Feature> queriedPois = new Collection<Feature>(); foreach (Feature feature in allFeatures) { if (buildType.Equals("All", StringComparison.OrdinalIgnoreCase)) { queriedPois.Add(feature); } else { // Deal with "Hotels" specifically if (poiCatagroy.Equals("Hotels", StringComparison.OrdinalIgnoreCase)) { int rooms = int.Parse(feature.ColumnValues[queriedColumn], CultureInfo.InvariantCulture); string[] values = buildType.Split('~'); if (values.Length >= 2) { if (int.Parse(values[0], CultureInfo.InvariantCulture) <= rooms && int.Parse(values[1], CultureInfo.InvariantCulture) >= rooms) { queriedPois.Add(feature); } } else if (values.Length == 1) { int maxValue = int.Parse(values[0].TrimStart(new[] { '>', '=', ' ' }), CultureInfo.InvariantCulture); if (rooms > maxValue) { queriedPois.Add(feature); } } } else if (feature.ColumnValues[queriedColumn].Equals(buildType, StringComparison.OrdinalIgnoreCase)) { queriedPois.Add(feature); } } } return queriedPois; } private void AddOverlays() { // Background Overlay WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay("World Map Kit"); worldMapKitOverlay.Projection = WorldMapKitProjection.SphericalMercator; Map1.CustomOverlays.Add(worldMapKitOverlay); OpenStreetMapOverlay openStreetMapOverlay = new OpenStreetMapOverlay("Open Street Map"); Map1.CustomOverlays.Add(openStreetMapOverlay); BingMapsOverlay bingMapsAerialOverlay = new BingMapsOverlay("Bing Maps Aerial"); bingMapsAerialOverlay.MapType = BingMapsStyle.Aerial; Map1.CustomOverlays.Add(bingMapsAerialOverlay); BingMapsOverlay bingMapsRoadOverlay = new BingMapsOverlay("Bing Maps Road"); bingMapsRoadOverlay.MapType = BingMapsStyle.Road; Map1.CustomOverlays.Add(bingMapsRoadOverlay); // Queried Service Overlay InMemoryFeatureLayer serviceAreaLayer = new InMemoryFeatureLayer(); GeoColor serviceAreaGeoColor = new GeoColor(120, GeoColor.FromHtml("#1749c9")); serviceAreaLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(serviceAreaGeoColor, GeoColor.FromHtml("#fefec1"), 2, LineDashStyle.Solid); serviceAreaLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.DynamicOverlay.Layers.Add("serviceArea", serviceAreaLayer); // POI Overlay Proj4Projection proj4 = new Proj4Projection(); proj4.InternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString(); proj4.ExternalProjectionParametersString = Proj4Projection.GetSphericalMercatorParametersString(); proj4.Open(); ShapeFileFeatureLayer hotelsLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/POIs/Hotels.shp"), ShapeFileReadWriteMode.ReadOnly); hotelsLayer.Name = Resource.Hotels; hotelsLayer.Transparency = 120f; hotelsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(MapPath("~/Images/Hotel.png"))); hotelsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; hotelsLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add(hotelsLayer.Name, hotelsLayer); ShapeFileFeatureLayer medicalFacilitesLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/POIs/Medical_Facilities.shp"), ShapeFileReadWriteMode.ReadOnly); medicalFacilitesLayer.Name = Resource.MedicalFacilites; medicalFacilitesLayer.Transparency = 120f; medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(MapPath("~/Images/DrugStore.png"))); medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; medicalFacilitesLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add(medicalFacilitesLayer.Name, medicalFacilitesLayer); ShapeFileFeatureLayer publicFacilitesLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/POIs/Public_Facilities.shp"), ShapeFileReadWriteMode.ReadOnly); publicFacilitesLayer.Name = Resource.PublicFacilites; publicFacilitesLayer.Transparency = 120f; publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(MapPath("~/Images/public_facility.png"))); publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; publicFacilitesLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add(publicFacilitesLayer.Name, publicFacilitesLayer); ShapeFileFeatureLayer restaurantsLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/POIs/Restaurants.shp"), ShapeFileReadWriteMode.ReadOnly); restaurantsLayer.Name = Resource.Restaurants; restaurantsLayer.Transparency = 120f; restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(MapPath("~/Images/restaurant.png"))); restaurantsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; restaurantsLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add(restaurantsLayer.Name, restaurantsLayer); ShapeFileFeatureLayer schoolsLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/POIs/Schools.shp"), ShapeFileReadWriteMode.ReadOnly); schoolsLayer.Name = Resource.Schools; schoolsLayer.Transparency = 120f; schoolsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(MapPath("~/Images/school.png"))); schoolsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; schoolsLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add(schoolsLayer.Name, schoolsLayer); Map1.DynamicOverlay.IsVisibleInOverlaySwitcher = false; // Restrict area Overlay ShapeFileFeatureLayer restrictedLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/CityLimitPolygon.shp"), ShapeFileReadWriteMode.ReadOnly); AreaStyle extentStyle = new AreaStyle(); extentStyle.CustomAreaStyles.Add(new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Transparent)) { OutlinePen = new GeoPen(GeoColor.SimpleColors.White, 5.5f) }); extentStyle.CustomAreaStyles.Add(new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Transparent)) { OutlinePen = new GeoPen(GeoColor.SimpleColors.Red, 1.5f) { DashStyle = LineDashStyle.Dash } }); restrictedLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = extentStyle; restrictedLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; restrictedLayer.FeatureSource.Projection = proj4; Map1.DynamicOverlay.Layers.Add("restricted", restrictedLayer); InMemoryFeatureLayer highlightFeatureLayer = new InMemoryFeatureLayer(); highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.DynamicOverlay.Layers.Add("highlightFeatureLayer", highlightFeatureLayer); // Marker Overlay Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("/Images/selectedHalo.png") { ImageOffsetX = -16, ImageOffsetY = -16 }; Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderWidth = 1; Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.Gray; Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoSize = true; Map1.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.MarkerOverlay.IsVisibleInOverlaySwitcher = false; // Drawn Point InMemoryMarkerOverlay markerOverlay = new InMemoryMarkerOverlay("DrawnPointOverlay"); markerOverlay.FeatureSource.InternalFeatures.Add(new Feature(new PointShape(-10776838.0796536, 3912346.50475619))); // Add a initial point for query markerOverlay.IsVisibleInOverlaySwitcher = false; markerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("/Images/drawPoint.png") { ImageOffsetX = -16, ImageOffsetY = -32 }; markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Map1.CustomOverlays.Add(markerOverlay); // Legend Layer LegendAdornmentLayer legendlayer = new LegendAdornmentLayer { Height = 135, Location = AdornmentLocation.LowerRight }; Map1.AdornmentOverlay.Layers.Add(legendlayer); LegendItem hotelsLayeritem = new LegendItem(); hotelsLayeritem.ImageStyle = hotelsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; hotelsLayeritem.TextStyle = TextStyles.NoData1(Resource.Hotels); legendlayer.LegendItems.Add("hotels", hotelsLayeritem); LegendItem medicalFacilitesLayeritem = new LegendItem(); medicalFacilitesLayeritem.ImageStyle = medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; medicalFacilitesLayeritem.TextStyle = TextStyles.NoData1(Resource.MedicalFacilites); legendlayer.LegendItems.Add("medicalFacilites", medicalFacilitesLayeritem); LegendItem publicFacilitesLayeritem = new LegendItem(); publicFacilitesLayeritem.ImageStyle = publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; publicFacilitesLayeritem.TextStyle = TextStyles.NoData1(Resource.PublicFacilites); legendlayer.LegendItems.Add("publicFacilites", publicFacilitesLayeritem); LegendItem restaurantsLayeritem = new LegendItem(); restaurantsLayeritem.ImageStyle = restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; restaurantsLayeritem.TextStyle = TextStyles.NoData1(Resource.Restaurants); legendlayer.LegendItems.Add("restaurants", restaurantsLayeritem); LegendItem schoolsLayeritem = new LegendItem(); schoolsLayeritem.ImageStyle = schoolsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; schoolsLayeritem.TextStyle = TextStyles.NoData1(Resource.Schools); legendlayer.LegendItems.Add("schools", schoolsLayeritem); // Scale bar layer ScaleBarAdornmentLayer scaleBarAdormentLayer = new ScaleBarAdornmentLayer(); scaleBarAdormentLayer.Location = AdornmentLocation.LowerLeft; scaleBarAdormentLayer.XOffsetInPixel = 10; Map1.AdornmentOverlay.Layers.Add("ScaleBar", scaleBarAdormentLayer); Map1.AdornmentOverlay.IsVisibleInOverlaySwitcher = false; } } }
$(document).ready(function () { window.onload = resizeElementHeight(); $(window).resize(resizeElementHeight); // Bind toggle button events $("#toggle").bind("click", function () { if ($("#leftContainer").is(':visible')) { $("#collapse").attr("src", "Images/expand.gif"); $("#map-content").css("width", "99%"); $("#toggle").css("left", "5px"); $("#leftContainer").hide(); } else { $("#leftContainer").show(); $("#collapse").attr("src", "Images/collapse.gif"); $("#map-content").css("width", "80%"); $("#toggle").css("left", "20%"); } resizeElementHeight(); }); // set the toggle style for group buttons $("#divTrackMode input[type=image]").bind("click", function () { var btnImgs = $("#divTrackMode input[type=image]"); for (var i = 0; i < btnImgs.length; i++) { $(btnImgs[i]).attr("class", ""); } $(this).attr("class", "active"); }); // set the toggle effect for 2 service mode radio button $("input[name='ServiceArea']").change(function () { if ($("#divService").is(':visible')) { $("#divService").hide(); $("#divBuffer").show(); } else { $("#divService").show(); $("#divBuffer").hide(); } }); $("#dlgErrorMessage").dialog({ autoOpen: false, modal: true, buttons: { Ok: function () { $("#btnNormal").trigger("click"); $(this).dialog("close"); } } }); // Make sure the resize method take effect when doing ajax call Sys.Application.remove_load(resizeElementHeight); Sys.Application.add_load(resizeElementHeight); }); var OnMapCreated = function (map) { map.events.register("mousemove", map, function (e) { var mouseCoordinate = this.getLonLatFromPixel(new OpenLayers.Pixel(e.clientX, e.clientY)); if (mouseCoordinate) { $("#spanMouseCoordinate").text("X:" + mouseCoordinate.lon.toFixed(2) + " Y: " + mouseCoordinate.lat.toFixed(2)); } }); } function resizeElementHeight() { var documentheight = $(window).height(); var contentDivH = documentheight - $("#footer").height() - $("#header").height() - 1; $("#content-container").height(contentDivH + "px"); $("#leftContainer").height(contentDivH + "px"); $("#map-content").height(contentDivH + "px"); $("#toggle").css("line-height", contentDivH + "px"); if (contentDivH > 450) { $("#queryResultUpdatePanel").height(contentDivH - 450 + "px"); } else { $("#queryResultUpdatePanel").visible = false; } $("#mapContainer").height(contentDivH + "px"); // refresh the map. Map1.GetOpenLayersMap().updateSize(); }
using ThinkGeo.MapSuite.Core; namespace ThinkGeo.MapSuite.SiteSelection { public abstract class AccessibleAreaAnalyst { private PointShape startLocation; private GeographyUnit geographyUnit; protected AccessibleAreaAnalyst() { } protected AccessibleAreaAnalyst(PointShape startLocation) : this(startLocation, GeographyUnit.DecimalDegree) { } protected AccessibleAreaAnalyst(PointShape startLocation, GeographyUnit geographyUnit) { this.startLocation = startLocation; this.geographyUnit = geographyUnit; } public PointShape StartLocation { get { return startLocation; } set { startLocation = value; } } public GeographyUnit GeographyUnit { get { return geographyUnit; } set { geographyUnit = value; } } public BaseShape CreateAccessibleArea() { if (StartLocation == null) { return null; } else { return CreateAccessibleAreaCore(); } } protected abstract BaseShape CreateAccessibleAreaCore(); } }
using ThinkGeo.MapSuite.Core; namespace ThinkGeo.MapSuite.SiteSelection { public class BufferAccessibleAreaAnalyst : AccessibleAreaAnalyst { private double distance; private DistanceUnit distanceUnit; public BufferAccessibleAreaAnalyst() : this(2, DistanceUnit.Mile) { } public BufferAccessibleAreaAnalyst(int distance) : this(distance, DistanceUnit.Mile) { } public BufferAccessibleAreaAnalyst(PointShape startLocation, GeographyUnit geographyUnit) : this(startLocation, geographyUnit, 2, DistanceUnit.Mile) { } public BufferAccessibleAreaAnalyst(int distance, DistanceUnit distanceUnit) : this(null, GeographyUnit.Meter, distance, distanceUnit) { } public BufferAccessibleAreaAnalyst(PointShape startLocation, GeographyUnit geographyUnit, int distance, DistanceUnit distanceUnit) : base(startLocation, geographyUnit) { this.Distance = distance; this.DistanceUnit = distanceUnit; } public double Distance { get { return distance; } set { distance = value; } } public DistanceUnit DistanceUnit { get { return distanceUnit; } set { distanceUnit = value; } } protected override BaseShape CreateAccessibleAreaCore() { if (StartLocation == null) { return null; } return StartLocation.Buffer(Distance, 40, GeographyUnit, DistanceUnit); } } }
using System; using System.IO; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.Routing; namespace ThinkGeo.MapSuite.SiteSelection { public class RouteAccessibleAreaAnalyst : AccessibleAreaAnalyst { private int drivingTimeInMinutes; private string streetShapeFilePathName; public RouteAccessibleAreaAnalyst() : this(null, GeographyUnit.DecimalDegree) { } public RouteAccessibleAreaAnalyst(PointShape startLocation, GeographyUnit geographyUnit) : this(startLocation, geographyUnit, 6) { } public RouteAccessibleAreaAnalyst(PointShape startLocation, GeographyUnit geographyUnit, int drivingTimeInMinutes) : base(startLocation, geographyUnit) { this.drivingTimeInMinutes = drivingTimeInMinutes; } public string StreetShapeFilePathName { get { return streetShapeFilePathName; } set { streetShapeFilePathName = value; } } public int DrivingTimeInMinutes { get { return drivingTimeInMinutes; } set { drivingTimeInMinutes = value; } } protected override BaseShape CreateAccessibleAreaCore() { string rtgFilePathName = Path.ChangeExtension(StreetShapeFilePathName, ".rtg"); RtgRoutingSource routingSource = new RtgRoutingSource(rtgFilePathName); FeatureSource featureSource = new ShapeFileFeatureSource(StreetShapeFilePathName); RoutingEngine routingEngine = new RoutingEngine(routingSource, featureSource); if (!featureSource.IsOpen) { featureSource.Open(); } ManagedProj4Projection proj = new ManagedProj4Projection(); proj.InternalProjectionParametersString = ManagedProj4Projection.GetBingMapParametersString(); proj.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326); proj.Open(); StartLocation = proj.ConvertToExternalProjection(StartLocation) as PointShape; Feature feature = featureSource.GetFeaturesNearestTo(StartLocation, GeographyUnit, 1, ReturningColumnsType.NoColumns)[0]; PolygonShape polygonShape = routingEngine.GenerateServiceArea(feature.Id, new TimeSpan(0, DrivingTimeInMinutes, 0), 100, GeographyUnit.Feet); polygonShape = proj.ConvertToInternalProjection(polygonShape) as PolygonShape; proj.Close(); return polygonShape; } } }
using System; using System.Globalization; using ThinkGeo.MapSuite.Core; namespace ThinkGeo.MapSuite.SiteSelection { public class AreaAnalystConfiguration { private PointShape searchPoint; private string category; private string subCategory; private ServiceSearchMode serviceSearchMode; private int drivingTime; private double bufferDistance; private DistanceUnit distanceUnit; private string routeFilePathName; private GeographyUnit mapUnit; public AreaAnalystConfiguration(string routeFilePathName) : this(routeFilePathName, new GeoCollection<object>()) { } public AreaAnalystConfiguration(string routeFilePathName, GeoCollection<object> parameters) { this.MapUnit = GeographyUnit.Meter; this.routeFilePathName = routeFilePathName; this.DistanceUnit = DistanceUnit.Mile; if (parameters.Contains("category")) { this.category = parameters["category"].ToString(); } if (parameters.Contains("subCategory")) { this.subCategory = parameters["subCategory"].ToString().Replace(">~", ">="); } if (parameters.Contains("searchPoint")) { this.searchPoint = PointShape.CreateShapeFromWellKnownData(parameters["searchPoint"].ToString()) as PointShape; } if (parameters.Contains("searchMode") && parameters["searchMode"].ToString().Equals("ServiceArea", StringComparison.OrdinalIgnoreCase)) { this.serviceSearchMode = ServiceSearchMode.ServiceArea; this.drivingTime = Convert.ToInt32(parameters["driveTime"].ToString(), CultureInfo.InvariantCulture); } else { this.serviceSearchMode = ServiceSearchMode.BufferArea; this.bufferDistance = Convert.ToDouble(parameters["bufferDistance"].ToString(), CultureInfo.InvariantCulture); this.distanceUnit = GetDistanceFrom(parameters["distanceUnit"].ToString()); } } public string RouteFilePathName { get { return routeFilePathName; } set { routeFilePathName = value; } } public GeographyUnit MapUnit { get { return mapUnit; } set { mapUnit = value; } } public PointShape SearchPoint { get { return searchPoint; } set { searchPoint = value; } } public string Category { get { return category; } set { category = value; } } public string SubCategory { get { return subCategory; } set { subCategory = value; } } public ServiceSearchMode ServiceSearchMode { get { return serviceSearchMode; } set { serviceSearchMode = value; } } public DistanceUnit DistanceUnit { get { return distanceUnit; } set { distanceUnit = value; } } public AccessibleAreaAnalyst GetAccessibleAreaAnalyst() { AccessibleAreaAnalyst analyst; if (ServiceSearchMode == SiteSelection.ServiceSearchMode.ServiceArea) { analyst = new RouteAccessibleAreaAnalyst(SearchPoint, MapUnit) { StreetShapeFilePathName = RouteFilePathName, DrivingTimeInMinutes = drivingTime }; } else { analyst = new BufferAccessibleAreaAnalyst(SearchPoint, MapUnit) { Distance = bufferDistance, DistanceUnit = distanceUnit }; } return analyst; } private DistanceUnit GetDistanceFrom(string inputUnit) { DistanceUnit distanceUnit = DistanceUnit.Kilometer; switch (inputUnit.ToLowerInvariant()) { case "mile": distanceUnit = DistanceUnit.Mile; break; default: break; } return distanceUnit; } } }
namespace ThinkGeo.MapSuite.SiteSelection { public enum ServiceSearchMode { ServiceArea = 0, BufferArea = 1 } }