Skip to content

Commit

Permalink
Merge pull request #175 from SalesforceLabs/feature/LocationMapLWC
Browse files Browse the repository at this point in the history
New LWC Component for Map
  • Loading branch information
GeekStewie authored Oct 2, 2024
2 parents 215b84e + 5e3b9fd commit 13ce7d3
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 6 deletions.
8 changes: 4 additions & 4 deletions force-app/main/default/flexipages/Capture.flexipage-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</componentInstanceProperties>
<componentInstanceProperties>
<name>descTextField</name>
<value>animalshelters__Type__c</value>
<value>animalshelters__TypeFromBreeds__c</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>latField</name>
Expand All @@ -22,7 +22,7 @@
</componentInstanceProperties>
<componentInstanceProperties>
<name>mapTitle</name>
<value>Animal Locations</value>
<value>Animal Locations Found At</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>nameField</name>
Expand All @@ -32,8 +32,8 @@
<name>obj</name>
<value>animalshelters__Animal__c</value>
</componentInstanceProperties>
<componentName>LocationMap</componentName>
<identifier>LocationMap</identifier>
<componentName>lightningLocationMap</componentName>
<identifier>animalshelters_lightningLocationMap</identifier>
</componentInstance>
</itemInstances>
<name>main</name>
Expand Down
4 changes: 2 additions & 2 deletions force-app/main/default/flexipages/Release.flexipage-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<name>obj</name>
<value>animalshelters__Movement__c</value>
</componentInstanceProperties>
<componentName>LocationMap</componentName>
<identifier>LocationMap</identifier>
<componentName>lightningLocationMap</componentName>
<identifier>animalshelters_lightningLocationMap</identifier>
</componentInstance>
</itemInstances>
<name>main</name>
Expand Down
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);
});
});
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>
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';
}
}
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>

0 comments on commit 13ce7d3

Please sign in to comment.