-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #175 from SalesforceLabs/feature/LocationMapLWC
New LWC Component for Map
- Loading branch information
Showing
6 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
force-app/main/default/lwc/lightningLocationMap/__tests__/lightningLocationMap.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createElement } from 'lwc'; | ||
import LightningLocationMap from 'c/lightningLocationMap'; | ||
|
||
describe('c-lightning-location-map', () => { | ||
afterEach(() => { | ||
// The jsdom instance is shared across test cases in a single file so reset the DOM | ||
while (document.body.firstChild) { | ||
document.body.removeChild(document.body.firstChild); | ||
} | ||
}); | ||
|
||
it('TODO: test case generated by CLI command, please fill in test logic', () => { | ||
// Arrange | ||
const element = createElement('c-lightning-location-map', { | ||
is: LightningLocationMap | ||
}); | ||
|
||
// Act | ||
document.body.appendChild(element); | ||
|
||
// Assert | ||
// const div = element.shadowRoot.querySelector('div'); | ||
expect(1).toBe(1); | ||
}); | ||
}); |
21 changes: 21 additions & 0 deletions
21
force-app/main/default/lwc/lightningLocationMap/lightningLocationMap.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<template> | ||
<lightning-card icon-name="action:map" title={mapTitle}> | ||
<lightning-input | ||
type="toggle" | ||
label="Enable/Disable List view" | ||
name="lvToggle" | ||
checked={checked} | ||
onchange={handleToggleChange}> | ||
</lightning-input> | ||
|
||
<template if:true={mapMarkers.length}> | ||
<lightning-map | ||
map-markers={mapMarkers} | ||
zoom-level={zoomLevel} | ||
markers-title={markersTitle} | ||
show-footer={showFooter} | ||
list-view={listView}> | ||
</lightning-map> | ||
</template> | ||
</lightning-card> | ||
</template> |
45 changes: 45 additions & 0 deletions
45
force-app/main/default/lwc/lightningLocationMap/lightningLocationMap.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { LightningElement, api, wire, track } from 'lwc'; | ||
import getLocation from '@salesforce/apex/LocationController.getLocation'; | ||
|
||
export default class LightningLocationMap extends LightningElement { | ||
@api obj; | ||
@api latField; | ||
@api longField; | ||
@api nameField; | ||
@api descTextField; | ||
@api descDateField; | ||
@api zoomLevel = 16; | ||
@api markersTitle = 'Animal Locations'; | ||
@api showFooter = false; | ||
@api mapTitle = 'Animal Locations'; | ||
@track mapMarkers = []; | ||
@track listView = 'hidden'; | ||
@track checked = false; | ||
|
||
connectedCallback() { | ||
this.initLocation(); | ||
} | ||
|
||
initLocation() { | ||
getLocation({ | ||
varObj: this.obj, | ||
varLat: this.latField, | ||
varLong: this.longField, | ||
varName: this.nameField, | ||
varDescText: this.descTextField, | ||
varDescDate: this.descDateField | ||
}) | ||
.then(result => { | ||
console.log('result:', result); | ||
this.mapMarkers = result; | ||
}) | ||
.catch(error => { | ||
console.error('Error:', error); | ||
}); | ||
} | ||
|
||
handleToggleChange(event) { | ||
this.checked = event.target.checked; | ||
this.listView = this.checked ? 'visible' : 'hidden'; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
force-app/main/default/lwc/lightningLocationMap/lightningLocationMap.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata"> | ||
<apiVersion>61.0</apiVersion> | ||
<isExposed>true</isExposed> | ||
<masterLabel>Locations on Map</masterLabel> | ||
<description>Displays Geolocation on a Map for a User specified Object and Fields</description> | ||
<targets> | ||
<target>lightning__AppPage</target> | ||
</targets> | ||
<targetConfigs> | ||
<targetConfig targets="lightning__AppPage"> | ||
<property name="obj" type="String" label="Object"/> | ||
<property name="latField" type="String" label="Latitude Field"/> | ||
<property name="longField" type="String" label="Longitude Field"/> | ||
<property name="nameField" type="String" label="Name Field"/> | ||
<property name="descTextField" type="String" label="Description Field (Text)"/> | ||
<property name="descDateField" type="String" label="Description Field (Date)"/> | ||
<property name="mapTitle" type="String" label="Map Title"/> | ||
</targetConfig> | ||
</targetConfigs> | ||
</LightningComponentBundle> |