How publicmap/electionmap works
Main Components
• User Interface (UI): Represented by the index.html that loads in the browser.
• Client‑side Javascript Modules: The various JS files (like ECILookup.js, add-marker.js, add-map-layers.js, addMapControls.js, locate-user.js, map-layer-config.js, query-layer-features.js, show-data-at-point.js, and the bundled file in js/dist) act as dedicated modules handling map initialization, querying the Mapbox API, dynamic control additions (e.g., layers and markers), and user interaction.
• External Services:
– Mapbox GL JS: The mapping engine that renders the basemap, constituency boundaries, and interactive layers.
– Mapbox Tile API: The external API call (as described in README) that provides constituency details via tile queries.
– OpenStreetMap: The source for street-level basemap details.
– Datameet Maps: The source for constituency shapefiles that are hosted on Mapbox.
Relationships and Interactions
• The User accesses the application via a browser that loads index.html.
• index.html references the bundled JavaScript (either directly from js/index.js during development or the compiled file in js/dist after a build).
• The main JavaScript (controller) coordinates the behavior of various modules:
• For example, ECILookup.js manages API calls to the Mapbox tile query URL for constituency data.
• -map-layers.js, add-marker.js, and addMapControls.js handle the addition of visual layers, markers, and interactive controls to the Mapbox instance.
• locate-user.js likely determines the user’s location to center the map.
• query-layer-features.js and show-data-at-point.js work together to identify and display data based on map interactions.
• All these modules depend on Mapbox GL JS to render the dynamic map, which in turn integrates basemap details (from OpenStreetMap) and constituency boundaries (via data hosted from Datameet Maps on Mapbox).
• npm scripts and node modules (specified in package.json) are used to manage dependencies and compile the JavaScript source into a single (or optimized) bundle available in the js/dist folder.
Architectural Patterns and Design Principles
• Modular Design: Each JavaScript file is dedicated to a particular map-handling task, lending well to separation of concerns.
• Client-Side Rendering: The architecture relies on the browser to render the UI and map components using external APIs, without a dedicated back‑end server.
• Build/Compilation Workflow: Note the development/build separation—changes are made to individual modules and then compiled to a distribution folder for production.
• External API Integration: Clear interaction with third-party services (Mapbox and OpenStreetMap) for data and rendering.
Technologies and Frameworks
• HTML and JavaScript form the client base.
• Mapbox GL JS for map rendering.
• Mapbox API for constituency data queries.
• npm (along with Node.js) for dependency management and building the final JavaScript bundle.
• Image assets and configuration files (such as .gitignore, LICENSE, and package files) support development and deployment practices.