-
Notifications
You must be signed in to change notification settings - Fork 0
dgtek map (package description)
yarn add dgtek-map && mv node_modules/dgtek-map/dist/map.worker.js public
or
npm install dgtek-map && mv node_modules/dgtek-map/dist/map.worker.js public
import DgtekMap from 'dgtek-map'If your app starts from root folder:
window[Symbol.for('map.worker')] = new Worker('map.worker.js')If your app starts from subfolder (for example https://example.com/app/):
window[Symbol.for('map.worker')] = new Worker('/app/map.worker.js')Create container for map with id "container-for-map" and stylize it as you need:
<style>
#container-for-map {
position: relative;
width: 70%;
height: 70vh;
margin: auto;
}
</style>
<main>
<figure id="container-for-map"></figure>
</main>
<script src="initWorker.js"></script>
<script src="dist/main.js"></script>const map = new DGtekMap({
container,
center: { lat: -37.8357725, lng: 144.9738764 }
})Map container will receive events
| event type | description |
|---|---|
| Selected building is: | |
on-net |
on-net |
footprint |
in the footprint |
construction-commenced |
under construction |
coming-soon |
coming soon |
not-available |
N/A |
The array of results from the collection of buildings DB received
| event type | description |
|---|---|
building-address-list |
The list of addresses |
building-data-list |
The list of base data ({ id, address, addressComponents }) |
| event type | description |
|---|---|
get-by-id |
Get building description by id |
get-by-address |
Get building description by address |
| event type | description |
|---|---|
submit-address |
User pressed the button SUBMIT |
const events = [
'on-net',
'footprint',
'construction-commenced',
'coming-soon',
'not-available',
'building-address-list',
'building-data-list',
'submit-address',
'get-by-id',
'get-by-address'
]
const container = document.getElementById('container-for-map')
events.forEach(eventName => container.addEventListener(eventName, catchEvent))
function catchEvent (event) {
console.group('Event handler outside package')
console.log('Event type: ', event.type)
console.log('Event data:\n', event.data)
console.groupEnd('Event handler outside package')
}You should write your own code for
catchEvent
β’ change default host url
setHost (data)β’ change default api key
setApiKey (data)β’ get list of building's addresses from collection
getBuildingsList (collectionName)β’ get list of building's data from collection
getBuildingsData (collectionName)Building data:
{ id, address, addressComponents }
Collections: 'lit', 'footprint', 'build', 'soon', 'other'
β’ get list of 'on-net' buildings
getLIT ()β’ get list of 'footprint' buildings
getFootprint ()β’ get full description of building by it's id
getBuildingDataById (buildingId)β’ get full description of building by it's address
getBuildingDataByAddress (address)β’ save new building
postBuildingData (buildingData)β’ update existing building data
putBuildingData (buildingId, buildingData)π You can catch events listed above on the worker' instance directly:
events.forEach(event => window[Symbol.for('map.worker')].addEventListener(event, catchEvent))π You can send requests directly to the worker
β Search for address:
window[Symbol.for('map.worker')].postMessage({
action: 'search',
store: 'lit',
key: '81 Cecil St, South Melbourne VIC 3205, Australia'
})β Get list of addresses:
window[Symbol.for('map.worker')].postMessage({ action: 'list', key: 'build' })β Get list of addresses:
window[Symbol.for('map.worker')].postMessage({ action: 'data', key: 'soon' })