🗺️ FieldOfficeMap.cshtml Documentation


📚 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Razor & Layout Configuration
  4. HTML Structure
    4.1 Head Section (Meta, Styles, Scripts)
    4.2 Body Section (UI Components)
  5. CSS Styling
  6. JavaScript Functional Areas
    6.1 Map Initialization | GetMap()
    6.2 Field Office Data Fetch & Rendering
    6.3 Interactive Infobox | showInfobox()
    6.4 User Geolocation Tracking
    6.5 Pushpin Interactions & Custom Data
    6.6 Autosuggest & Search
    6.7 Directions & Spatial Data Services
    6.8 Map Type & Zoom Handling
    6.9 Utility Helpers
  7. API Endpoints Overview
  8. Sample Usage & Code Snippets
  9. UML Diagram (Mermaid)
  10. Conclusion

1. Overview & Purpose

FieldOfficeMap.cshtml is an ASP.NET Razor View that presents an interactive Bing Map to display Field Office locations. Key features include:

  • 📍 Plotting offices fetched via /Location/GetFieldLocations
  • ℹ️ Infoboxes showing address, manager, stats & links
  • 🔎 Autosuggest Search for business & addresses
  • 🚦 Traffic Layer and Bird’s-eye imagery toggle
  • 📱 Geolocation Tracking (start/stop)
  • 🛠️ Custom pushpin interactions & CRUD hooks

This view is part of the IrbyImaging application and leverages Syncfusion EJ2 components and Bing Maps v8 API.


2. Dependencies & Technologies

Category Library / API
Map Provider Bing Maps V8 JavaScript API
UI Components Syncfusion EJ2 (ejs-textbox)
Data Fetch Fetch API (/Location/GetFieldLocations)
Table & Export jQuery DataTables, jszip, pdfmake
CSS Framework Bootstrap, MetisMenu, SimpleBar, Node Waves
JavaScript Helpers jQuery, Underscore (via DataTables plugins)

3. Razor & Layout Configuration

@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@using Syncfusion.EJ2
@{
    ViewData["Title"] = "Field Offices";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • Layout: Uses global _ATSLayout.cshtml.
  • ViewData["Title"]: Sets page title to “Field Offices”.

4. HTML Structure

4.1 Head Section (Meta, Styles, Scripts)

  • Meta Tags: Charset, viewport, keywords, author.
  • FavIcon: /favicon.ico
  • Map Script Loader: Dynamically injects Bing Maps <script> with callback=GetMap.
  • Syncfusion and DataTables script references.
<script>
  (async () => {
    let script = document.createElement("script");
    let bingKey = "YOUR_BING_MAPS_KEY";
    script.src = `https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=${bingKey}`;
    document.body.appendChild(script);
  })();
</script>

4.2 Body Section (UI Components)

<body>
  <!-- 🔍 Search Box -->
  <div id="searchBoxContainer">
    Search:
    <ejs-textbox id="searchBox" placeholder="Search for new location"></ejs-textbox>
  </div>

  <!-- 🗺️ Map Container -->
  <div id="myMap"></div>

  <!-- 🚦 Directions Panels -->
  <div class="directionsContainer">
    <div id="directionsPanel"></div>
    <div id="directionsItinerary"></div>
  </div>

  <!-- 📍 Tracking Buttons -->
  <input type="button" onclick="startTracking()" value="Start Continuous Tracking" />
  <input type="button" onclick="stopTracking()" value="Stop Continuous Tracking" />
  
  <!-- 👥 Modal for Dynamic Content -->
  <div id="myModal" class="modal">...</div>
  ...
</body>

5. CSS Styling

html, body { height:100%; margin:0; padding:0; }
#myMap { width:100%; height:700px; float:right; }
#searchBoxContainer { position:relative; width:100%; }
#zoomIn, #zoomOut { 
  position:absolute; right:33px; width:30px; height:30px;
  border-radius:16px; text-align:center; font-size:25px; 
  cursor:pointer; z-index:1001; 
}
.lightZoom { background:#fff; border:1px solid #000; }
.darkZoom { background:#333; color:#fff; border:1px solid #fff; }
  • Responsive map & controls
  • Custom Zoom Buttons styles

6. JavaScript Functional Areas

6.1 Map Initialization | GetMap()

🚀 Purpose: Bootstraps the Bing Map and loads core modules.

function GetMap() {
  map = new Microsoft.Maps.Map('#myMap', {
    credentials: '<BING_MAPS_KEY>',
    mapTypeId: Microsoft.Maps.MapTypeId.aerial,
    supportedMapTypes: [ /* road, aerial, birdseye… */ ]
  });
  infobox = new Microsoft.Maps.Infobox(map.getCenter(), { visible: false });
  infobox.setMap(map);

  // Load modules: AutoSuggest, Traffic, SpatialDataService…
  Microsoft.Maps.loadModule([...], onModulesLoaded);
}
  • infobox: Reusable popup
  • loadModule: Binds autosuggest & traffic

6.2 Field Office Data Fetch & Rendering

📡 Fetches JSON from /Location/GetFieldLocations and renders pushpins.

fetch('/Location/GetFieldLocations')
  .then(res => res.json())
  .then(locations => {
    const locs = locations.map(l => new Microsoft.Maps.Location(l.Latitude, l.Longitude));
    locations.forEach(l => {
      const pin = new Microsoft.Maps.Pushpin(new Microsoft.Maps.Location(l.Latitude,l.Longitude));
      Microsoft.Maps.Events.addHandler(pin,'click', ()=> showInfobox(pin,l));
      map.entities.push(pin);
    });
    map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(locs) });
  });
Variable Description
locations Array of { Latitude, Longitude, … }
pin Pushpin for each Field Office
bounds Auto-zoom to fit all pins

6.3 Interactive Infobox | showInfobox()

ℹ️ Shows a styled HTML infobox with Field Office details and link:

function showInfobox(pin, data) {
  const html = `
    <div style="background:#f5f5f5; padding:10px;">
      <strong>${data.FieldOffice}</strong>
      <p><strong>Address:</strong> ${data.MailingAddress}</p>
      …
      <a href="/FieldOffices/Details/${data.FieldOfficeId}" target="_blank">View Details</a>
    </div>`;
  infobox.setOptions({
    location: pin.getLocation(),
    htmlContent: html,
    visible: true
  });
  centerInfoboxInView();
}
  • Auto-pan: Ensures infobox remains fully visible

6.4 User Geolocation Tracking

Function Purpose
startTracking() Creates userPin, calls watchPosition()
usersLocationUpdated Moves userPin, recenters map
stopTracking() Clears watch & removes pin by ID
function startTracking() {
  userPin = new Microsoft.Maps.Pushpin(map.getCenter(), { visible:false });
  map.entities.push(userPin);
  watchId = navigator.geolocation.watchPosition(usersLocationUpdated);
}

6.5 Pushpin Interactions & Custom Data

  • mapClicked(e): Place new pushpin, show inputForm to capture metadata
  • saveData(): Attach metadata (title/description) to currentPushpin
  • pushpinClicked(e): Show infobox for user-added pushpins
function suggestionSelected(result) {
  map.entities.clear();
  const pin = new Microsoft.Maps.Pushpin(result.location);
  map.entities.push(pin);
  map.setView({ bounds: result.bestView });
}
  • Uses AutosuggestManager with businessSuggestions:true
  • Binds to #searchBox

6.7 Directions & Spatial Data Services

Note: Commented out in this view but scaffolding remains for future use.

// directionsManager = new Microsoft.Maps.Directions.DirectionsManager(map);
// directionsManager.setRenderOptions({ itineraryContainer: '#directionsItinerary' });
  • directionsUpdated(e): Query “nearRoute” SpatialDataService for POIs

6.8 Map Type & Zoom Handling

Handles mouse wheel to switch between aerial & bird’s-eye:

Microsoft.Maps.Events.addHandler(map,'mousewheel', e => {
  // If at birdseye & zoom-out → aerial
  if(map.getMapTypeId()===Microsoft.Maps.MapTypeId.birdseye && e.wheelDelta<0){…}
});

switchToBirdseye(): Verifies availability before toggling.

6.9 Utility Helpers

Function Description
removePinById(id) Filters & removes Pushpin with matching metadata.id
getRouteMode(req) Maps Directions.RouteMode to SDS mode string
getRouteOptimization Maps RouteOptimization to SDS optimize string
highlight(id, evt) Flash UI element to indicate event firing

7. API Endpoints Overview

  • /Location/GetFieldLocations

    • Method: GET
    • Returns: JSON array of Field Office objects
    • Fields: FieldOffice, Latitude, Longitude, Manager, JobCount, EmployeeCount, AssetsCount, FieldOfficeId, …
  • /FieldOffices/Details/{id}

    • Renders details page in new tab

8. Sample Usage & Code Snippets

Embedding the Map

@section Scripts {
  <script src="https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=YOUR_KEY" async defer></script>
}
<div id="myMap"></div>

Adding a Custom Pushpin

mapClicked({ location: new Microsoft.Maps.Location(34.05,-118.25) });
document.getElementById('titleTbx').value = "My Pushpin";
document.getElementById('descriptionTbx').value = "Downtown LA";
saveData();

9. UML Diagram (Mermaid)

flowchart LR
    A[Page Load] --> B[GetMap()]
    B --> C[Load Modules]
    C --> D[fetch FieldLocations]
    D --> E[Create Pushpins]
    E --> F[map.entities.push(pin)]
    E -.-> G[Infobox Setup]
    B --> H[AutoSuggestManager]
    B --> I[TrafficManager.show()]
    B --> J[Geolocation.watchPosition]
    click G "showInfobox()" "Display infobox"

10. Conclusion

This FieldOfficeMap.cshtml view delivers a feature-rich interactive map to visualize and interact with Field Office data. From dynamic data loading, Rich infoboxes, search/autosuggest, to real-time geolocation tracking, it provides an extensible foundation. Future enhancements may include Directions routing, deeper Spatial Data Services integration, and CRUD operations for pushpins.

Feel free to adapt the code snippets, replace the Bing Maps Key, and integrate additional APIs as needed! 🚀


Happy Mapping! 🗺️✨