A layer that shows the search results as text markers on a map. If markers collide, markers will reduce in size and hide text to prevent text collision. When the layer is zoomed in/out or panned past the buffer pixel value, search results will be updated.
L.mapquest.key = 'KEY';
let map = L.mapquest.map('basic-searchLayer-map', {
center: [34.0522, -118.2437],
layers: L.mapquest.tileLayer('map'),
zoom: 15
});
L.mapquest.search().place({
category: 'sic:581228F52',
sort: 'relevance',
bbox: map.getBounds(),
pageSize: 50
}, createBasicSearchLayer);
function createBasicSearchLayer(err, response) {
map.addLayer(L.mapquest.searchLayer({
searchResponse: response
}));
}
The buffer, in pixels, that is used to calculate when to make a new search request when the map is panned by the user.
The margin, in pixels, that is used when calculating if markers collide with each other.
An object containing any of the following key value options: icon, iconOptions, and popupEnabled.
icon: A string that specifies the type of icon to be rendered. Default is 'via'.
iconOptions: An object containing any of the following key value options: primaryColor, secondaryColor, size.
primaryColor: The string hex code primary color of the marker.
secondaryColor: The string hex code secondary color of the marker.
size: The size of the marker as a string: 'sm', 'md', or 'lg'. Default is 'lg'.
popupEnabled: A boolean that specifies if a popup is enabled when hovering on markers in the search layer. Default is true.
A response object from the L.mapquest.search.place() call. This is data that is used by the layer to render the search results.
A boolean that determines if new search requests are made when the map is panned or zoomed in/out.
Returns the search response object that is assigned to the layer.
Sets the search response object of the layer. This will cause the layer to redraw with new search results.
A search_results_changed
event is fired when search results are updated on the layer either through map movement or the setSearchResponse function.
The response object is returned.
searchLayer.on('search_results_changed', function(eventResponse) {
console.log(eventResponse);
});
A search_marker_clicked
event is fired when a search marker is clicked. The search result is returned inside of the event object.
searchLayer.on('search_marker_clicked', function(eventResponse) {
console.log(eventResponse);
});
L.mapquest.key = 'KEY';
let map = L.mapquest.map('circle-searchLayer-map', {
center: [34.0522, -118.2437],
layers: L.mapquest.tileLayer('map'),
zoom: 15
});
L.circle([34.0522, -118.2437], {radius: 1609.34}).addTo(map);
L.mapquest.search().place({
q: 'hotels',
sort: 'relevance',
circle: {
center: new L.LatLng(34.0522, -118.2437),
radius: 1609.34
},
pageSize: 50
}, createSearchLayer);
function createSearchLayer(err, response) {
map.addLayer(L.mapquest.searchLayer({
searchResponse: response,
updateResultsOnMapMove: false
}));
}