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
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Configuration; using System.Data; using System.Globalization; using System.Text; using System.Web.Mvc; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.MvcEdition; namespace ThinkGeo.MapSuite.SiteSelection { public class DefaultController : Controller { // // GET: /Default/ public ActionResult Index() { // Initialize the Map Map map = InitializeMap(); // Load all the categories and its related sub categories Collection<string> categories = GetSupportedPoiCategories(map); ViewData["PoiCategories"] = categories; ViewData["PoiSubCategories"] = GetSpecifiedSubCategories(categories[2], map); // Give a place where intialize the first search ViewData["StartPoint"] = new PointShape(-10776838.0796536, 3912346.50475619).GetWellKnownText(); return View(map); } [MapActionFilter] public string GetSpecifiedSubCategories(Map map, GeoCollection<object> args) { Collection<string> subCategories = GetSpecifiedSubCategories(args[0].ToString(), map); return JsonSerializer.Serialize(subCategories); } [MapActionFilter] public bool CheckTrackPointIsValid(Map map, GeoCollection<object> args) { // Get the tracked point PointShape trackedPoint = PointShape.CreateShapeFromWellKnownData(args[0].ToString()) as PointShape; // Get the boundary shape ShapeFileFeatureLayer restrictedLayer = map.DynamicOverlay.Layers["restricted"] as ShapeFileFeatureLayer; restrictedLayer.Open(); Collection<Feature> features = restrictedLayer.QueryTools.GetFeaturesContaining(trackedPoint, ReturningColumnsType.NoColumns); restrictedLayer.Close(); if (features.Count <= 0) // Drawn feature is out of the supported area (out of Frisco TX.) { return false; } else { return true; } } [MapActionFilter] public void ClearAllSearchResult(Map map, GeoCollection<object> args) { // clear service area and markers InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)map.DynamicOverlay.Layers["serviceArea"]; serviceAreaLayer.InternalFeatures.Clear(); map.MarkerOverlay.FeatureSource.InternalFeatures.Clear(); // Clear POI markers on map. map.EditOverlay.FeatureSource.InternalFeatures.Clear(); InMemoryMarkerOverlay markerOverlay = map.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; markerOverlay.FeatureSource.InternalFeatures.Clear(); map.DynamicOverlay.Redraw(); } [MapActionFilter] public PartialViewResult SearchSimilarSites(Map map, GeoCollection<object> args) { // Create accessible area analyst instance string routeStreetFilePathName = Server.MapPath(ConfigurationManager.AppSettings["StreetShapeFilePathName"]); AreaAnalystConfiguration areaAnalystConfiguration = new AreaAnalystConfiguration(routeStreetFilePathName, args); // Create the accessible service area and add it to the map ViewData["serviceAreaExtent"] = CreateServiceAreas(map, areaAnalystConfiguration); // Refresh scalebar unit system RefreshScaleBarUnitSystem(map, areaAnalystConfiguration); // Display tracked start point DisplayCandidateSite(areaAnalystConfiguration.SearchPoint, map); // Get and display all Pois in searched service area Collection<Feature> accessiblePois = GetAllAccessiblePois(map, areaAnalystConfiguration); DisplyQueriedPoiOnMap(accessiblePois, map, areaAnalystConfiguration); // Display result into table DataTable poiDispalyTable = InternalHelper.GetQueryResultDefination(); foreach (Feature feature in accessiblePois) { DataRow row = poiDispalyTable.NewRow(); row["WKT"] = feature.GetWellKnownText(); row["Name"] = feature.ColumnValues["Name"]; poiDispalyTable.Rows.Add(row); } return PartialView("SimilarSites", poiDispalyTable); } private RectangleShape CreateServiceAreas(Map map, AreaAnalystConfiguration areaAnalystConfiguration) { AccessibleAreaAnalyst accessibleAreaAnalyst = areaAnalystConfiguration.GetAccessibleAreaAnalyst(); BaseShape calculatedServiceArea = accessibleAreaAnalyst.CreateAccessibleArea(); InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)map.DynamicOverlay.Layers["serviceArea"]; serviceAreaLayer.Open(); serviceAreaLayer.InternalFeatures.Clear(); serviceAreaLayer.InternalFeatures.Add(new Feature(calculatedServiceArea)); RectangleShape boundingBox = serviceAreaLayer.GetBoundingBox(); return boundingBox; } private Collection<Feature> GetAllAccessiblePois(Map map, AreaAnalystConfiguration areaAnalystConfiguration) { // Get querying Poi layer ShapeFileFeatureLayer queriedLayer = map.DynamicOverlay.Layers[areaAnalystConfiguration.Category] as ShapeFileFeatureLayer; queriedLayer.Open(); // Get all POIs in Service Area InMemoryFeatureLayer serviceAreaLayer = (InMemoryFeatureLayer)map.DynamicOverlay.Layers["serviceArea"]; BaseShape calculatedServiceArea = serviceAreaLayer.InternalFeatures[0].GetShape(); Collection<Feature> featuresInServiceArea = queriedLayer.QueryTools.GetFeaturesWithin(calculatedServiceArea, ReturningColumnsType.AllColumns); // Filter the features by specific query. Collection<Feature> filteredQueryFeatures = FilterFeaturesByQueryConfiguration(featuresInServiceArea, areaAnalystConfiguration.Category, areaAnalystConfiguration.SubCategory); return filteredQueryFeatures; } private void DisplyQueriedPoiOnMap(Collection<Feature> features, Map map, AreaAnalystConfiguration areaAnalystConfiguration) { if (features.Count <= 0) { return; } 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>"); ShapeFileFeatureLayer queriedLayer = map.DynamicOverlay.Layers[areaAnalystConfiguration.Category] as ShapeFileFeatureLayer; InMemoryFeatureLayer highlightFeatureLayer = (InMemoryFeatureLayer)map.DynamicOverlay.Layers["highlightFeatureLayer"]; highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = queriedLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle; highlightFeatureLayer.InternalFeatures.Clear(); map.MarkerOverlay.FeatureSource.Open(); map.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)); } map.MarkerOverlay.Columns.Add(new FeatureSourceColumn(columnValue.Key)); } popupHtml.Append("</table>"); map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.ContentHtml = popupHtml.ToString(); map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; map.MarkerOverlay.FeatureSource.Clear(); foreach (Feature feature in features) { map.MarkerOverlay.FeatureSource.InternalFeatures.Add(feature); highlightFeatureLayer.InternalFeatures.Add(feature); } } private void DisplayCandidateSite(PointShape searchPoint, Map map) { InMemoryMarkerOverlay markerOverlay = map.CustomOverlays["DrawnPointOverlay"] as InMemoryMarkerOverlay; if (markerOverlay != null) { markerOverlay.FeatureSource.InternalFeatures.Clear(); markerOverlay.FeatureSource.InternalFeatures.Add(new Feature(searchPoint)); } } private void RefreshScaleBarUnitSystem(Map map, AreaAnalystConfiguration areaAnalystConfiguration) { ScaleBarAdornmentLayer adornmentLayer = map.AdornmentOverlay.Layers["ScaleBar"] as ScaleBarAdornmentLayer; switch (areaAnalystConfiguration.DistanceUnit) { case DistanceUnit.Kilometer: adornmentLayer.UnitFamily = UnitSystem.Metric; break; case DistanceUnit.Mile: adornmentLayer.UnitFamily = UnitSystem.Imperial; break; } } private Collection<string> GetSupportedPoiCategories(Map map) { Collection<string> categories = new Collection<string>(); foreach (Layer layer in map.DynamicOverlay.Layers) { if (!string.IsNullOrEmpty(layer.Name) && !layer.Name.Equals("Public Facilites") && !layer.Name.Equals("restricted")) { categories.Add(layer.Name); } } return categories; } private Collection<string> GetSpecifiedSubCategories(string categoryName, Map map) { 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 = map.DynamicOverlay.Layers[categoryName] 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 Collection<Feature> FilterFeaturesByQueryConfiguration(IEnumerable<Feature> allFeatures, string category, string subCategory) { string queriedColumn = InternalHelper.GetDbfColumnByPoiType(category); Collection<Feature> queriedPois = new Collection<Feature>(); foreach (Feature feature in allFeatures) { if (subCategory.Equals("All", StringComparison.OrdinalIgnoreCase)) { queriedPois.Add(feature); } else { // Deal with "Hotels" specifically if (category.Equals("Hotels", StringComparison.OrdinalIgnoreCase)) { int rooms = int.Parse(feature.ColumnValues[queriedColumn], CultureInfo.InvariantCulture); string[] values = subCategory.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(subCategory, StringComparison.OrdinalIgnoreCase)) { queriedPois.Add(feature); } } } return queriedPois; } private Map InitializeMap() { Map map = new Map("Map1"); map.Width = new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage); map.Height = new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage); map.MapUnit = GeographyUnit.Meter; map.MapTools.OverlaySwitcher.Enabled = true; map.MapTools.OverlaySwitcher.BaseOverlayTitle = " "; AddOverlays(map); map.CurrentExtent = new RectangleShape(-10788072.2328016, 3923530.35787306, -10769555.4090135, 3906993.24816589); map.OnClientTrackShapeFinished = "trackShapeFinished"; return map; } private void AddOverlays(Map map) { // Background Overlay WorldMapKitWmsWebOverlay worldMapKitOverlay = new WorldMapKitWmsWebOverlay("World Map Kit"); worldMapKitOverlay.Projection = WorldMapKitProjection.SphericalMercator; map.CustomOverlays.Add(worldMapKitOverlay); OpenStreetMapOverlay openStreetMapOverlay = new OpenStreetMapOverlay("Open Street Map"); map.CustomOverlays.Add(openStreetMapOverlay); BingMapsOverlay bingMapsAerialOverlay = new BingMapsOverlay("Bing Maps Aerial"); bingMapsAerialOverlay.MapType = BingMapsStyle.Aerial; map.CustomOverlays.Add(bingMapsAerialOverlay); BingMapsOverlay bingMapsRoadOverlay = new BingMapsOverlay("Bing Maps Road"); bingMapsRoadOverlay.MapType = BingMapsStyle.Road; map.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; map.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(Server.MapPath(ConfigurationManager.AppSettings["HotelsShapeFilePathName"]), ShapeFileReadWriteMode.ReadOnly); hotelsLayer.Name = Resource.Hotels; hotelsLayer.Transparency = 120f; hotelsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(Server.MapPath("~/Content/Images/Hotel.png"))); hotelsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; hotelsLayer.FeatureSource.Projection = proj4; map.DynamicOverlay.Layers.Add(hotelsLayer.Name, hotelsLayer); ShapeFileFeatureLayer medicalFacilitesLayer = new ShapeFileFeatureLayer(Server.MapPath(ConfigurationManager.AppSettings["MedicalFacilitiesShapeFilePathName"]), ShapeFileReadWriteMode.ReadOnly); medicalFacilitesLayer.Name = Resource.MedicalFacilites; medicalFacilitesLayer.Transparency = 120f; medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(Server.MapPath("~/Content/Images/DrugStore.png"))); medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; medicalFacilitesLayer.FeatureSource.Projection = proj4; map.DynamicOverlay.Layers.Add(medicalFacilitesLayer.Name, medicalFacilitesLayer); ShapeFileFeatureLayer publicFacilitesLayer = new ShapeFileFeatureLayer(Server.MapPath(ConfigurationManager.AppSettings["PublicFacilitiesShapeFilePathName"]), ShapeFileReadWriteMode.ReadOnly); publicFacilitesLayer.Name = Resource.PublicFacilites; publicFacilitesLayer.Transparency = 120f; publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(Server.MapPath("~/Content/Images/public_facility.png"))); publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; publicFacilitesLayer.FeatureSource.Projection = proj4; map.DynamicOverlay.Layers.Add(publicFacilitesLayer.Name, publicFacilitesLayer); ShapeFileFeatureLayer restaurantsLayer = new ShapeFileFeatureLayer(Server.MapPath(ConfigurationManager.AppSettings["RestaurantsShapeFilePathName"]), ShapeFileReadWriteMode.ReadOnly); restaurantsLayer.Name = Resource.Restaurants; restaurantsLayer.Transparency = 120f; restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(Server.MapPath("~/Content/Images/restaurant.png"))); restaurantsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; restaurantsLayer.FeatureSource.Projection = proj4; map.DynamicOverlay.Layers.Add(restaurantsLayer.Name, restaurantsLayer); ShapeFileFeatureLayer schoolsLayer = new ShapeFileFeatureLayer(Server.MapPath(ConfigurationManager.AppSettings["SchoolsShapeFilePathName"]), ShapeFileReadWriteMode.ReadOnly); schoolsLayer.Name = Resource.Schools; schoolsLayer.Transparency = 120f; schoolsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(Server.MapPath("~/Content/Images/school.png"))); schoolsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; schoolsLayer.FeatureSource.Projection = proj4; map.DynamicOverlay.Layers.Add(schoolsLayer.Name, schoolsLayer); map.DynamicOverlay.IsVisibleInOverlaySwitcher = false; InMemoryFeatureLayer highlightFeatureLayer = new InMemoryFeatureLayer(); highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; map.DynamicOverlay.Layers.Add("highlightFeatureLayer", highlightFeatureLayer); // Restrict area Overlay ShapeFileFeatureLayer restrictedLayer = new ShapeFileFeatureLayer(Server.MapPath(ConfigurationManager.AppSettings["RestrictedShapeFilePathName"]), 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; map.DynamicOverlay.Layers.Add("restricted", restrictedLayer); // Marker Overlay map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = new WebImage("/Content/Images/selectedHalo.png") { ImageOffsetX = -16, ImageOffsetY = -16 }; map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderWidth = 1; map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.BorderColor = GeoColor.StandardColors.Gray; map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.Popup.AutoSize = true; map.MarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; map.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("/Content/Images/drawPoint.png") { ImageOffsetX = -16, ImageOffsetY = -32 }; markerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; map.CustomOverlays.Add(markerOverlay); // Legend Layer LegendAdornmentLayer legendlayer = new LegendAdornmentLayer { Height = 135, Location = AdornmentLocation.LowerRight }; map.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; map.AdornmentOverlay.Layers.Add("ScaleBar", scaleBarAdormentLayer); map.AdornmentOverlay.IsVisibleInOverlaySwitcher = false; } } }
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 } }
$(document).ready(function () { initializePageElements(); // Bind events to track shape buttons $("#divTrackMode img").bind("click", function (e) { var command = this.alt; switch (command) { case "PanMap": Map1.setDrawMode('Normal'); break;6 case "DrawPoint": Map1.setDrawMode('Point'); break; case "ClearAll": Map1.ajaxCallAction('Default', 'ClearAllSearchResult', null, function (result) { $("#divSimilarSites").empty(); // Redraw the corresponding layers Map1.getDynamicOverlay().redraw(true); Map1.getLayer("DrawnPointOverlay").redraw(true); Map1.getMarkerOverlay().redraw(true); Map1.getLayersByName("DrawnPointOverlay")[0].redraw(true); }); break; default: break; } }) // attach event to make sure sub-category is updated based on category $("#ddlCategory").bind("change", function (e) { var selectedCategory = $('#ddlCategory').find('option:selected').val(); Map1.ajaxCallAction('Default', 'GetSpecifiedSubCategories', { "category": selectedCategory }, function (result) { if (result.get_responseData() != "") { // Reload the subcategories based on selected category var jsonData = $.parseJSON(result.get_responseData()); $("#ddlCategorySubtype").empty(); $(jsonData).each(function (index, optionText) { $("#ddlCategorySubtype").append($('<option />').attr('value', optionText).text(optionText)); }); // Research the pertential POIs with new configurations searchSimilarSites(); } }); }); $("#ddlCategorySubtype").bind("change", function (e) { searchSimilarSites(); }); // apply configurations $("#btnApply").bind("click", function (e) { searchSimilarSites(); }) // do a default search $("#btnApply").trigger("click"); }); function zoomToPoi(wkt) { var bbox = OpenLayers.Geometry.fromWKT(wkt).getBounds(); Map1.zoomToExtent(bbox, false); } // Apply configurations and do the search var searchSimilarSites = function () { var selectedCategory = $('#ddlCategory').find('option:selected').val(); var selectedSubType = $('#ddlCategorySubtype').find('option:selected').val().replace(">=", ">~"); var searchMode = $("input[name='serviceArea']:checked").val(); var trackPoint = $("#trackPoint").val(); var args = { "category": selectedCategory, "subCategory": selectedSubType, "searchMode": searchMode, "searchPoint": trackPoint }; if (searchMode == "ServiceArea") { args["driveTime"] = $("#tbxServiceArea").val(); } else { args["bufferDistance"] = $("#tbxDistance").val(); args["distanceUnit"] = $("#sltDistanceUnit").val(); } Map1.ajaxCallAction('Default', 'SearchSimilarSites', args, function (result) { // Display query result into table $("#divSimilarSites").empty().html(result.get_responseData()); // Redraw the corresponding layers Map1.getDynamicOverlay().redraw(true); Map1.getLayer("DrawnPointOverlay").redraw(true); Map1.getMarkerOverlay().redraw(true); Map1.getLayer("DrawnPointOverlay").redraw(true); }); } function trackShapeFinished(e) { var trackedPoint = $.parseJSON(e.features)[0].wkt Map1.ajaxCallAction("Default", "CheckTrackPointIsValid", { "startPoint": trackedPoint }, function (e) { if (e.get_responseData() == "True") { $("#trackPoint").val(trackedPoint); searchSimilarSites(); // Clear tracked points Map1.getEditOverlay().destroyFeatures(Map1.getEditOverlay().features); } else { $("#dlgErrorMessage").dialog("open"); $(".ui-dialog-titlebar").hide(); // Hide dialog header bar // Clear tracked points Map1.getEditOverlay().destroyFeatures(Map1.getEditOverlay().features); } }) } 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 initializePageElements() { var resizeElementHeight = function () { 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"); var mapDivH = contentDivH - $("#resultContainer").height(); $("#mapContainer").height(mapDivH + "px"); // refresh the map. Map1.updateSize(); } window.onload = resizeElementHeight(); $(window).resize(resizeElementHeight); // Bind toggle button events $("#toggle img").bind("click", function () { if ($("#leftContainer").is(':visible')) { $(this).attr("src", "Content/Images/expand.gif"); $("#map-content").css("width", "100%"); $("#toggle").css("left", "0%"); $("#leftContainer").hide(); } else { $("#leftContainer").show(); $(this).attr("src", "Content/Images/collapse.gif") $("#map-content").css("width", "80%"); $("#toggle").css("left", "20%"); } resizeElementHeight(); }); // set the toggle style for group buttons $("#divTrackMode img").bind("click", function () { var btnImgs = $("#divTrackMode img"); for (var i = 0; i < btnImgs.length; i++) { $(btnImgs[i]).attr("class", "imgButton"); } $(this).attr("class", "active imgButton"); }); // 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(); } }); // Set "restaurant" selected by default $('#ddlCategory option')[2].selected = true; $("#dlgErrorMessage").dialog({ autoOpen: false, modal: true, buttons: { Ok: function () { $(this).dialog("close"); } } }); };