
ReactiveGoogleMap creates a data-driven map UI component using Google Maps. It is the key component for building map based experiences.
Example uses:
- showing a map of user checkins by city and topics for powering discovery based experiences.
- displaying restaurants filtered by a nearby distance query on a map.
Usage
Basic Usage
<ReactiveGoogleMap componentId="MapUI" dataField="location" title="Venue Location Map" />Usage With All Props
<ReactiveGoogleMap
componentId="MapUI"
dataField="location"
title="Venue Location Map"
size={10}
defaultZoom={13}
defaultCenter={{ lat: 37.74, lng: -122.45 }}
showMapStyles={true}
defaultMapStyle="Standard"
showMarkerClusters={true}
showSearchAsMove={true}
searchAsMove={true}
onPopoverClick={this.onPopoverClick}
// 'react' defines when and how the map component should update
react={{
and: 'CitySensor',
}}
// map events
renderItem={this.renderItem}
// less useful props
autoCenter={true}
/>Props
- componentId
Stringunique identifier of the component, can be referenced in other components'reactprop. - dataField
StringDB data field to be connected to the component's UI view, usually of a geopoint (i.e. location) data type and used for rendering the markers on the map. - size
Number[optional] number of results to show in the map view, can be a number in the range [1, 1000]. Defaults to 10. - defaultZoom
Number[optional] preset map's zoom level, accepts integer values between [0, 20]. 0 is the minimum zoom level, where you can see the entire globe. 20 is the maximum zoom level. Defaults to 13. - defaultCenter
Object[optional] preset map's center position by specifying an object with validlatandlngvalues. This prop, when set, will cause the component to run a geo-distance query with a distance of 10mi (Refer:defaultRadiusandunitprop to configure the distance). - center
Object[optional] set map's center position by specifying an object with validlatandlngvalues. This prop, when set, will cause the component to run a geo-distance query with a distance of 10mi (Refer:defaultRadiusandunitprop to configure the distance). - defaultRadius
Number[optional] used as distance value for the geo-distance query whendefaultCenterorcenteris set. It accepts all positive integers. - unit
String[optional] unit for distance measurement, usesmi(for miles) by default. Distance units can be specified from the following:
- showMapStyles
Boolean[optional] whether to show map styles dropdown picker in the map UI. Defaults totrue. - defaultMapStyle
String[optional] preset a map style for the map UI. Available options include "Standard", "Blue Essence", "Blue Water", "Flat Map", "Light Monochrome", "Midnight Commander", "Unsaturated Browns". - showMarkers
Boolean[optional] whether to show the markers on the map, defaults totrue. Sometimes, it doesn't make sense to display markers (when building a heatmap or weather map or a directions navigation map) - defaultPin
String[optional] URL of the default marker pin image to be shown. It comes with a default image. Should only be set if you wish to use a custom marker. - showMarkerClusters
Boolean[optional] whether to aggregate and form a cluster of nearby markers. Defaults totrue.
Note
It requires
showMarkersprop enabled.
- showSearchAsMove
Boolean[optional] whether to show the Search As I Move checkbox in the UI. Defaults totrue. - searchAsMove
Boolean[optional] whether to set the Search As I Move checkbox. Defaults tofalse. - onPopoverClick
function[optional] a function that takes one argument for getting a marker's data and returns an HTML markup to be displayed in the popover box. - autoClosePopover
Boolean[optional] automatically closes the exisiting open popovers whenonPopoverClickgets fired. Defaults tofalse. - react
Objectspecify dependent components to reactively update GeoDistanceDropdown's options. Read more about it here.- key
Stringone ofand,or,notdefines the combining clause.- and clause implies that the results will be filtered by matches from all of the associated component states.
- or clause implies that the results will be filtered by matches from at least one of the associated component states.
- not clause implies that the results will be filtered by an inverse match of the associated component states.
- value
String or Array or ObjectStringis used for specifying a single component by itscomponentId.Arrayis used for specifying multiple components by theircomponentId.Objectis used for nesting other key clauses.
- key
- autoCenter
Boolean[optional] whether to auto center the map based on the geometric center of all the location markers. Defaults tofalse. - className
StringCSS class to be injected on the component container. - style
ObjectCSS style object to be applied to theReactiveGoogleMapcomponent. - renderItem
functionevent fired when one or more markers are indexed, updated or removed from the map. It takes an object with the following formats (label,icon,custom):
// To render the given text in the marker
renderItem={result => ({
label: result.title,
})}
// To render a marker image
renderItem={result => ({
icon: 'https://i.imgur.com/NHR2tYL.png',
})}
// To render a custom markup (as label) in the marker position
renderItem={result => ({
custom: (<div>{result.mag}</div>),
})}-
render
functionan alternative callback function torenderItem, where user can define how to render the view based on all the data changes.
It accepts an object with these properties:loading:booleanindicates that the query is still in progresserror:objectAn object containing the error infodata:arrayAn array of results obtained from combiningpromotedresults along with thehits.aggregationDataarrayAn array of aggregations buckets. Each bucket would have atop_hitsproperty if you're using Elasticsearch top hits aggregations indefaultQueryprop.promotedData:arrayAn array of promoted results obtained from the applied query. Read More
Note:
dataandpromotedDataresults has a property called_click_idwhich can be used with triggerClickAnalytics to register the click analytics info.customDataobjectCustom data set in the query rule when appbase.io is used as backend. Read MorerawDataobjectAn object of raw response as-is from elasticsearch query.resultStats:objectAn object with the following properties which can be helpful to render custom stats:numberOfResults:numberTotal number of results foundnumberOfPages:numberTotal number of pages found based on current page sizecurrentPage:numberCurrent page number for which data is being renderedtime:numberTime taken to find total results (in ms)displayedResults:numberNumber of results displayed in current viewhidden:numberTotal number of hidden results foundpromoted:numberTotal number of promoted results found
loadMore:functionA callback function to be called to load the next page of results into the view. The callback function is only applicable in the case of infinite loading view (i.e.infiniteScrollprop set totrue).triggerClickAnalytics:functionA function which can be called to register a click analytics. Read More
render={(props) => { const { data, // parased hits loading, error, promotedData, customData, rawData, resultStats: { numberOfResults numberOfPages currentPage displayedResults time hidden promoted }, loadMore // func to load more results triggerClickAnalytics // to trigger click analytics setPage, renderMap // allow users to render the map component at any place renderPagination // allows to render pagination component after displaying results } = props; return( <> {data.map(hit => <pre onClick={() => triggerClickAnalytics(hit._click_id)}>{JSON.stringify(hit)}</pre>)} {renderMap()} </pre> ) }Or you can also use render function as children
<ReactiveGoogleMap // ...other props > { ({ loading, error, data, promotedData, rawData, resultStats, handleLoadMore, triggerClickAnalytics }) => ( // return UI to be rendered ) } </ReactiveGoogleMap> -
renderError
String or JSX or Function[optional] can be used to render an error message in case of any error.
renderError={(error) => (
<div>
Something went wrong!<br/>Error details<br/>{error}
</div>
)
}- onError
Function[optional] gets triggered in case of an error and provides theerrorobject, which can be used for debugging or giving feedback to the user if needed. - onData
Function[optional] gets triggered after data changes, which returns an object with these properties:data,promotedData,customData,rawData&resultStats.
Demo
Styles
ReactiveGoogleMap component supports innerClass prop with the following keys:
titleinputlistcheckboxContainercheckboxlabelselecticoncountbuttonpaginationactive