@sitech-me/mobile-route-map
v0.1.6
Published
Framework-agnostic web component: live trip route map with status card (Mapbox GL). Works in React, Angular, Vue, or plain HTML.
Maintainers
Readme
@sitech-me/mobile-route-map
A single, framework-agnostic web component (<mobile-route-map>) that renders the
live trip-tracking map + status card. Same UI, same CSS, same icons as the original
Vue component — now usable from React, Angular, Vue, or plain HTML via one npm package,
with one build output. Everything is bundled in: Mapbox GL, Moment, Socket.IO client,
Lit — nothing extra for the consuming app to install.
1. Swap in your real assets, then build
src/assets/icons/garage.png <- garage marker icon
src/assets/icons/watersourceicon.png <- water-source marker icon
src/assets/icons/watersource.png <- "completed" card icon
src/assets/icons/homeicon.png <- drop-off marker icon
src/assets/icons/tanker.png <- truck marker icon
src/assets/icons/tanker2.svg <- truck illustration on the status card
src/locales/en.json, src/locales/ar.json <- full translation stringsEverything currently in those files is a placeholder (solid colored circles / a minimal SVG box) so the build runs end-to-end. Drop your real files in at the same paths and filenames, then:
npm install
npm run buildThis produces dist/mobile-route-map.js (ESM) and dist/style.css.
2. Publish
npm login
npm publish --access public(Rename @sitech-me/mobile-route-map in package.json to your actual npm scope/org
first, and update the repository field to your GitHub URL.)
Push the source to your repo as usual — dist/ can either be committed or built by CI
on release; either is fine, just make sure npm run build runs before npm publish
(the prepublishOnly script already does this for you).
3. One required global CSS import
Mapbox GL needs its own base stylesheet (for controls, attribution, etc.) loaded
once, globally — Vite extracts it to dist/style.css at build time. Import it
once anywhere in your app's entry point:
import '@sitech-me/mobile-route-map/style.css'Everything else (the modal, status card, markers) is scoped inside the component's Shadow DOM and needs no separate import.
4. Use it — plain HTML / Vue
<script type="module">
import '@sitech-me/mobile-route-map'
</script>
<mobile-route-map id="map" mapbox-token="pk.xxx" lang="ar"></mobile-route-map>
<script type="module">
const el = document.getElementById('map')
el.tripData = { /* same shape as the old `data` prop */ }
el.fetchRoute = (tripId) => fetch(`/api/trip-route/${tripId}?type=mobile`).then(r => r.json())
el.fetchGarageEnums = () => fetch('/api/garage-enums').then(r => r.json())
el.socket = mySocketIoClientInstance // optional, for live GPS updates
el.addEventListener('close', () => console.log('closed'))
el.show()
</script>5. Use it — React
React apps can use the custom element directly (React 19+ passes props/attributes
straight through to custom elements). If you want idiomatic props/callbacks instead
of managing DOM refs and events by hand, copy examples/react/MobileRouteMap.jsx
into your React project's source — it's plain JSX, compiled by your app's own
build tool (Vite/webpack/CRA/etc.), so there's no separate package build step or
version mismatch to worry about.
import { MobileRouteMap } from './MobileRouteMap' // the file you copied in
import { useRef, useState } from 'react'
function TripMap({ trip }) {
const [open, setOpen] = useState(true)
const mapRef = useRef(null)
return (
<MobileRouteMap
ref={mapRef}
open={open}
tripData={trip}
mapboxToken="pk.xxx"
lang="ar"
fetchRoute={(tripId) => fetch(`/api/trip-route/${tripId}?type=mobile`).then(r => r.json())}
fetchGarageEnums={() => fetch('/api/garage-enums').then(r => r.json())}
onClose={() => setOpen(false)}
onBack={() => console.log('back pressed')}
/>
)
}6. Use it — Angular
Angular can talk to custom elements natively — no wrapper package needed, just allow unknown elements and set properties via a template ref.
// app.module.ts
import '@sitech-me/mobile-route-map'
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core'
@NgModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
// ...
})
export class AppModule {}<!-- trip-map.component.html -->
<mobile-route-map #map mapbox-token="pk.xxx" lang="ar"
(close)="onClose()"></mobile-route-map>// trip-map.component.ts
import { AfterViewInit, ViewChild, ElementRef, Input } from '@angular/core'
export class TripMapComponent implements AfterViewInit {
@ViewChild('map') mapRef!: ElementRef<any>
@Input() trip: any
ngAfterViewInit() {
const el = this.mapRef.nativeElement
el.tripData = this.trip
el.fetchRoute = (tripId: string) =>
fetch(`/api/trip-route/${tripId}?type=mobile`).then((r) => r.json())
el.fetchGarageEnums = () => fetch('/api/garage-enums').then((r) => r.json())
el.show()
}
}API reference
| Property / attribute | Type | Notes |
|---|---|---|
| mapbox-token | string attr | required |
| .tripData | object property | same shape as the old Vue data prop |
| lang | "ar" | "en" attr | default "ar" |
| route-endpoint | string attr | default /api/trip-route, used if .fetchRoute isn't set |
| garage-enums-endpoint | string attr | default /api/garage-enums, used if .fetchGarageEnums isn't set |
| .fetchRoute(tripId) | function property | override the default fetch call |
| .fetchGarageEnums() | function property | override the default fetch call |
| .socket | property | an already-connected socket.io-client instance, for live GPS |
| .show() | method | open the modal |
| .close() | method | close the modal |
| .applyTripStatusUpdate(update) | method | call when your app's own store/socket gets a trip-status push (replaces the old Vuex watcher) |
| close / back / toggle-stats | events | CustomEvent, bubbling |
What changed vs. the original Vue component
- BootstrapVue
<b-modal>→ a plain overlay div, driven by.show()/.close(). - Vuex
state.update_trip_statuswatcher → publicapplyTripStatusUpdate()method you call from wherever your app now receives that push. - The hard-coded
TripRouteService/enums/GET_GARAGE_ENUMSstore call → configurablefetchRoute/fetchGarageEnums(default to plainfetchagainstroute-endpoint/garage-enums-endpoint, override with your real API client). socketsingleton import → an optional.socketproperty you pass in.this.$t(...)→ a small built-inen.json/ar.jsondictionary — extend these with your full translation set.- Everything else — Mapbox logic, coordinate-normalization/GPS-snapping/Directions-API fallback, marker/status-card structure, all CSS — is a straight 1:1 port.
Known constraint
Mapbox GL renders its canvas into the Shadow DOM container; this works in all modern browsers but if you see any rendering quirks in a specific target browser, they're almost always solvable by adjusting the container sizing — flag it and it can be tuned per-project.
