📑 GeoMapping.cshtml Documentation

File: IrbyImaging/Views/AccountingImaging/GeoMapping.cshtml
Purpose: Interactive mapping & property‐lease viewer for Accounting Imaging


📋 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Models & Data Models
  5. HTML Structure
  6. JavaScript Modules & Helper Methods
  7. Map Initialization & Configuration
  8. Pushpins & Infobox Handling
  9. User Geolocation & Tracking
  10. Search & AutoSuggest
  11. Directions & Near-Route Queries
  12. UI Components: Syncfusion TreeGrid
  13. AJAX & Modal Interactions
  14. Error Handling & Logging
  15. Third-Party Integrations
  16. Sample Usage
  17. UML Diagrams
  18. Conclusion

1. Overview & Purpose

This Razor View renders an interactive Bing Map 🎯 alongside a Syncfusion TreeGrid 📊 to:

  • Plot property lease locations from an API.
  • Show lease details in a custom infobox.
  • Enable user geolocation & continuous tracking.
  • Provide business‐style autosuggestions & traffic overlay.
  • List properties with search, paging and export (Excel/PDF/CSV).

Ideal for accountants or real‐estate teams to visualize lease portfolios geographically, drill into details, and export data.


2. Key Functional Areas

  • 🗺️ Map Display & Configuration
  • 📍 Pushpin & Infobox Management
  • 📡 Geolocation & Tracking
  • 🔍 Search & Business Autosuggest
  • 🚗 Directions & Near‐Route Queries (partially commented)
  • 📋 Property List TreeGrid with pagination & export
  • 📦 AJAX Modal for dynamic detail load

3. Dependencies & Technologies

Layer Technology / Library
View Engine ASP.NET MVC Razor
Mapping API Bing Maps V8
UI Components Syncfusion EJ2 (TreeGrid, TextBox)
AJAX & JS jQuery, Fetch API
DataTables DataTables + Buttons + PDFMake/JSZip
Styling Bootstrap, Custom CSS
Utilities MetisMenu, SimpleBar, Node-Waves

4. View Models & Data Models

@model IrbyImaging.DomainClasses.GeoLocation

GeoLocation Domain Class (approximate)

Property Type Description
Latitude double GPS latitude
Longitude double GPS longitude
Address string Full property address
Landlord string Property owner name
CommencementDate DateTime Lease start date
LeasePurpose string Purpose of lease (e.g., office)
TotalCost decimal Total lease cost
LeaseCode string Internal lease reference code
RegionLead string Area lead for the region
ExpiratinDate DateTime Lease expiration
FullyExecuted bool Execution status
SubjectToEscalation bool Escalation clause flag
DocumentImageId Guid Blob/document identifier

5. HTML Structure

<!DOCTYPE html>
<html lang="en">
<head> … </head>
<body>
  <div id="searchBoxContainer">…</div>
  <div class="directionsContainer">…</div>
  <div id="myMap"></div>
  <input type="button" value="Start Continuous Tracking" onclick="startTracking()" />
  <input type="button" value="Stop Continuous Tracking" onclick="stopTracking()" />
  <div id="propertyTable" class="row">…</div>
  <div id="myModal" class="modal">…</div>
  <!-- Script imports -->
</body>
</html>
  • #searchBoxContainer: EJ2 TextBox for search
  • #myMap: Bing Map canvas (700px height)
  • #propertyTable: Syncfusion TreeGrid listing properties
  • #myModal: Bootstrap modal for property details

6. JavaScript Modules & Helper Methods

Function Purpose
GetMap() Initializes Bing Map + layers, fetches and plots locations
showInfobox(pin, data) Renders custom infobox HTML with lease details
startTracking() Begins continuous geolocation watch
usersLocationUpdated() Updates user pushpin and recenters view
stopTracking() Stops watch and removes user pin
removePinById(id) Utility to remove pushpins by metadata
mapClicked(e) User‐placed pushpin & input form display
directionsUpdated(e) Handles “near‐route” spatial queries (via SpatialDataService)
suggestionSelected() Places autosuggested business location on map
switchToBirdseye() Toggles to Bird’s Eye imagery when available
highlight() UI helper to flash event status

Note: Some direction‐related code is commented out (e.g., DirectionsManager).


7. Map Initialization & Configuration

function GetMap() {
  map = new Microsoft.Maps.Map('#myMap', {
    credentials: 'YOUR_BING_KEY',
    supportedMapTypes: [ 'road','aerial','birdseye','canvasDark', … ],
    mapTypeId: Microsoft.Maps.MapTypeId.aerial
  });

  // Create & bind a hidden Infobox
  infobox = new Microsoft.Maps.Infobox(map.getCenter(), {
    visible: false, offset: new Microsoft.Maps.Point(0,20)
  });
  infobox.setMap(map);

  // Fetch & plot all lease locations
  fetch('/Location/GetLocations')
    .then(r => r.json())
    .then(locations => plotLocations(locations));
  
  // Load traffic, autosuggest, spatial modules
  Microsoft.Maps.loadModule([...], () => { /* Autosuggest & Traffic */ });
  
  // Request user’s geolocation
  navigator.geolocation.getCurrentPosition(showUserLocation);
  
  // Mousewheel & viewchangeend handlers for Bird’s Eye toggling
  Microsoft.Maps.Events.addHandler(map,'mousewheel',mouseWheelHandler);
  Microsoft.Maps.Events.addHandler(map,'viewchangeend',viewChangeEndHandler);
}
  • Credentials: Your Bing Maps Key
  • SupportedMapTypes: Variety including birdseye & grayscale
  • Auto-fetch: /Location/GetLocations returns JSON□

8. Pushpins & Infobox Handling

Plotting Lease Locations

locations.forEach(location => {
  const loc = new Microsoft.Maps.Location(location.Latitude, location.Longitude);
  const pin = new Microsoft.Maps.Pushpin(loc);
  Microsoft.Maps.Events.addHandler(pin,'click',() => showInfobox(pin, location));
  map.entities.push(pin);
});

showInfobox(pin, locationData)

function showInfobox(pin, data) {
  infobox.setOptions({ visible: false });
  const html = `
    <div style="…">
      <strong>${data.Address}</strong><br/>
      Landlord: ${data.Landlord}<br/>
      …<br/>
      <a href="/LegalImaging/ViewDoc/${data.DocumentImageId}" target="_blank">
        🔗 View Lease Agreement
      </a>
    </div>`;
  infobox.setOptions({
    location: pin.getLocation(),
    htmlContent: html,
    visible: true
  });
  adjustMapCenterForInfobox();
}

9. User Geolocation & Tracking

  • startTracking(): Adds hidden pushpin, calls navigator.geolocation.watchPosition
  • usersLocationUpdated(position): Moves pushpin, recenters map
  • stopTracking(): Clears watch, removes user pin via removePinById('uniqueIdentifier')
function startTracking() {
  userPin = new Microsoft.Maps.Pushpin(map.getCenter(), { visible: false });
  map.entities.push(userPin);
  watchId = navigator.geolocation.watchPosition(usersLocationUpdated);
}

10. Search & AutoSuggest

var manager = new Microsoft.Maps.AutosuggestManager({
  map: map, businessSuggestions: true
});
manager.attachAutosuggest(
  '#searchBox', '#searchBoxContainer', suggestionSelected
);
  • Business Suggestions: set businessSuggestions: true
  • suggestionSelected(result): Clears map, places pin, centers on result.bestView

11. Directions & Near‐Route Queries

💡 Partially commented out in code (requires uncommenting)

  • DirectionsManager: Microsoft.Maps.Directions.DirectionsManager
  • directionsUpdated(e):
    • Fetch current route
    • Build spatialFilter: { nearRoute, travelMode, optimize }
    • Call Microsoft.Maps.SpatialDataService.QueryAPIManager.search
    • Plot results on dataLayer

12. UI Components: Syncfusion TreeGrid

<ejs-treegrid id="TreeGrid" dataSource="@ViewBag.datasource"
  childMapping="Children" allowPaging="true"
  allowExcelExport="true" allowPdfExport="true"
  allowReordering="true" allowFiltering="true">
  <e-treegrid-pagesettings pageSize="10"></e-treegrid-pagesettings>
  <e-treegrid-columns>
    <e-treegrid-column field="Landlord" headerText="Property Name" width="220"/>
    <e-treegrid-column field="Address" headerText="Property Address" width="150"/>
    <e-treegrid-column field="TypeList" headerText="View Details" template="#typetemplate" width="150"/>
    <e-treegrid-column field="BlobName" headerText="View Lease Agreement" template="#viewtemplate" width="120"/>
  </e-treegrid-columns>
</ejs-treegrid>
  • Features: Sorting, Filtering, Paging, Excel/PDF/CSV Export
  • Custom Templates:
    • #typetemplate → “View Details” AJAX link
    • #viewtemplate → Direct blob “View” link

13. AJAX & Modal Interactions

  • Detail Popup: Clicking .anchorDetail triggers GET to /AccountingImaging/myModalProperties?id={DocumentImageId}
  • Modal: Injects HTML into #myModalContent and calls $('#myModal').modal('show')
$(document).on('click','.anchorDetail',function(){
  const id = $(this).data('id');
  $.get('/AccountingImaging/myModalProperties', { id })
    .done(html => {
      $('#myModalContent').html(html);
      $('#myModal').modal('show');
    })
    .fail(() => alert('Dynamic content load failed.'));
});

14. Error Handling & Logging

  • Fetch errors: Use .catch(...) on promise (can be extended)
  • Alerts for:
    • No route found
    • Transit mode unsupported
    • AJAX load failure
  • Infobox: Close previous before opening new

Recommendation: Integrate a logging framework (e.g., Sentry, Log4Net) for production.


15. Third-Party Integrations

  • Bing Maps V8: Mapping, Pushpins, Infobox, Traffic, Autosuggest, SpatialDataService
  • Syncfusion EJ2: TreeGrid, TextBox, Buttons
  • DataTables: Excel/PDF/CSV export via Buttons + JSZip + PDFMake
  • Bootstrap: Modal & layout
  • jQuery: DOM & AJAX utilities

16. Sample Usage

  1. Controller
    public ActionResult GeoMapping() {
      ViewBag.datasource = _leaseService.GetPropertyHierarchy();
      return View(new GeoLocation());
    }
    
  2. API Endpoint /Location/GetLocations
    • Returns JSON array of GeoLocation
    • Example:
      [
        { "Latitude": 40.7128, "Longitude": -74.0060,
          "Address":"123 Broadway, NY","Landlord":"ACME Inc.",… }
      ]
      
  3. Run
    • Navigate to /AccountingImaging/GeoMapping
    • Map loads, properties plotted, grid populated

17. UML Diagrams

classDiagram
    GeoLocation <|-- GeoMappingView
    GeoMappingView : +GetMap()
    GeoMappingView : +showInfobox()
    GeoMappingView : +startTracking()
    GeoMappingView : +suggestionSelected()
    GeoMappingView : +directionsUpdated()
sequenceDiagram
    User->>Browser: Load GeoMapping view
    Browser->>GeoMapping: Calls GetMap()
    GeoMapping->>API: GET /Location/GetLocations
    API-->>GeoMapping: JSON[GeoLocation]
    GeoMapping->>Map: Plot pushpins
    User->>Map: Click pushpin
    Map->>GeoMapping: showInfobox()
    User->>TreeGrid: Search / Detail click
    TreeGrid->>Server: GET myModalProperties?id
    Server-->>Modal: HTML content

18. Conclusion

This GeoMapping.cshtml view provides a rich, interactive interface for visualizing and managing property‐lease data on a map and in a structured grid. Leveraging Bing Maps and Syncfusion EJ2, it supports:

  • Real‐time geolocation & tracking
  • Business search autosuggestions
  • Infobox detail overlays
  • Robust data export & paging

🔧 Next Steps: Extend error handling, extract common JS to modules, secure API endpoints, and consider lazy loading for performance.


Happy Mapping! 🗺️🚀