Skip to content

Commit 722bece

Browse files
committed
Added callbackCreateMarker
1 parent 6d6e9f3 commit 722bece

File tree

7 files changed

+93
-40
lines changed

7 files changed

+93
-40
lines changed

callbacks.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ $('#bh-sl-map-container').storeLocator({
3535
| [callbackCloseDirections](callbacks/callback-closedirections.md) | Close directions callback |
3636
| [callbackNoResults](callbacks/callback-noresults.md) | No results callback |
3737
| [callbackJsonp](callbacks/callback-jsonp.md) | JSONP callback |
38+
| [callbackCreateMarker](callbacks/callback-createmarker.md) | Create marker override callback |
3839
| [callbackSuccess](callbacks/callback-success.md) | Success callback |
3940
| [callbackMapSet](callbacks/callback-mapset.md) | Map set callback |
4041
| [callbackModalOpen](callbacks/callback-modalopen.md) | Modal open callback |

callbacks/callback-createmarker.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# callbackCreateMarker
2+
3+
## Description
4+
5+
Allows map markers to be overridden with a custom marker. Please refer to the
6+
[Google MarkerOptions documentation](https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions)
7+
to review the available marker object properties. A marker object must be returned for this callback to function
8+
correctly. A basic example of overriding the markers with a single image URL is below.
9+
10+
## Parameters
11+
12+
| Name | Type | Description |
13+
|---|---|---|
14+
| map | object | Google Map object |
15+
| point | object | LatLng of current location |
16+
| letter | string | Optional letter used for front-end identification and correlation between list and points |
17+
| category | string | Location category/categories |
18+
19+
## Example
20+
21+
```javascript
22+
$('#bh-sl-map-container').storeLocator({
23+
callbackCreateMarker: function(map, point, letter, category) {
24+
25+
return new google.maps.Marker({
26+
position : point,
27+
map : map,
28+
icon : 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png',
29+
draggable: false
30+
});
31+
32+
}
33+
});
34+
```

dist/assets/js/plugins/storeLocator/jquery.storelocator.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
'callbackModalReady' : null,
101101
'callbackModalClose' : null,
102102
'callbackJsonp' : null,
103+
'callbackCreateMarker' : null,
103104
'callbackPageChange' : null,
104105
'callbackDirectionsRequest': null,
105106
'callbackCloseDirections' : null,
@@ -1043,28 +1044,35 @@
10431044
}
10441045
}
10451046

1046-
// Create the default markers
1047-
if (this.settings.disableAlphaMarkers === true || this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null || this.settings.markerImg !== null || (this.settings.fullMapStart === true && firstRun === true && (isNaN(this.settings.fullMapStartListLimit) || this.settings.fullMapStartListLimit > 26 || this.settings.fullMapStartListLimit === -1))) {
1048-
marker = new google.maps.Marker({
1049-
position : point,
1050-
map : map,
1051-
draggable: false,
1052-
icon: markerImg // Reverts to default marker if nothing is passed
1053-
});
1047+
// Marker setup
1048+
if (this.settings.callbackCreateMarker) {
1049+
// Marker override callback
1050+
marker = this.settings.callbackCreateMarker.call(this, map, point, letter, category);
10541051
}
10551052
else {
1056-
// Letter markers image
1057-
letterMarkerImg = {
1058-
url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=' + letter + '&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48'
1059-
};
1053+
// Create the default markers
1054+
if (this.settings.disableAlphaMarkers === true || this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null || this.settings.markerImg !== null || (this.settings.fullMapStart === true && firstRun === true && (isNaN(this.settings.fullMapStartListLimit) || this.settings.fullMapStartListLimit > 26 || this.settings.fullMapStartListLimit === -1))) {
1055+
marker = new google.maps.Marker({
1056+
position : point,
1057+
map : map,
1058+
draggable: false,
1059+
icon: markerImg // Reverts to default marker if nothing is passed
1060+
});
1061+
}
1062+
else {
1063+
// Letter markers image
1064+
letterMarkerImg = {
1065+
url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=' + letter + '&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48'
1066+
};
10601067

1061-
// Letter markers
1062-
marker = new google.maps.Marker({
1063-
position : point,
1064-
map : map,
1065-
icon : letterMarkerImg,
1066-
draggable: false
1067-
});
1068+
// Letter markers
1069+
marker = new google.maps.Marker({
1070+
position : point,
1071+
map : map,
1072+
icon : letterMarkerImg,
1073+
draggable: false
1074+
});
1075+
}
10681076
}
10691077

10701078
return marker;

dist/assets/js/plugins/storeLocator/jquery.storelocator.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

options.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
| callbackModalReady | null | Callback that fires when the content of the modal is generated. |
7878
| callbackModalClose | null | Callback that fires when a modal closes. |
7979
| callbackJsonp | null | Callback that can specify the callback function name of a JSONP request. |
80+
| callbackCreateMarker | null | Callback that will override the markers. This must return the marker object. |
8081
| callbackPageChange | null | Callback that fires when the page changes if pagination is enabled. |
8182
| callbackDirectionsRequest | null | Callback that fires upon a directions request when using the inline directions option. |
8283
| callbackCloseDirections | null | Callback that fires when the directions panel closes. |

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ filtering.
3737

3838
### Version 2.6.3
3939

40+
* Added callbackCreateMarker for custom marker overrides.
4041
* Added [InfoBubble](https://github.com/googlemaps/js-info-bubble) support and example file.
4142
* Added location results total count if HTML element with .bh-sl-total-results class exists.
4243
* Added markerAlphaColor setting to change the marker letter color.

src/js/jquery.storelocator.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
'callbackModalReady' : null,
9898
'callbackModalClose' : null,
9999
'callbackJsonp' : null,
100+
'callbackCreateMarker' : null,
100101
'callbackPageChange' : null,
101102
'callbackDirectionsRequest': null,
102103
'callbackCloseDirections' : null,
@@ -1040,28 +1041,35 @@
10401041
}
10411042
}
10421043

1043-
// Create the default markers
1044-
if (this.settings.disableAlphaMarkers === true || this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null || this.settings.markerImg !== null || (this.settings.fullMapStart === true && firstRun === true && (isNaN(this.settings.fullMapStartListLimit) || this.settings.fullMapStartListLimit > 26 || this.settings.fullMapStartListLimit === -1))) {
1045-
marker = new google.maps.Marker({
1046-
position : point,
1047-
map : map,
1048-
draggable: false,
1049-
icon: markerImg // Reverts to default marker if nothing is passed
1050-
});
1044+
// Marker setup
1045+
if (this.settings.callbackCreateMarker) {
1046+
// Marker override callback
1047+
marker = this.settings.callbackCreateMarker.call(this, map, point, letter, category);
10511048
}
10521049
else {
1053-
// Letter markers image
1054-
letterMarkerImg = {
1055-
url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=' + letter + '&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48'
1056-
};
1050+
// Create the default markers
1051+
if (this.settings.disableAlphaMarkers === true || this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null || this.settings.markerImg !== null || (this.settings.fullMapStart === true && firstRun === true && (isNaN(this.settings.fullMapStartListLimit) || this.settings.fullMapStartListLimit > 26 || this.settings.fullMapStartListLimit === -1))) {
1052+
marker = new google.maps.Marker({
1053+
position : point,
1054+
map : map,
1055+
draggable: false,
1056+
icon: markerImg // Reverts to default marker if nothing is passed
1057+
});
1058+
}
1059+
else {
1060+
// Letter markers image
1061+
letterMarkerImg = {
1062+
url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-b.png&text=' + letter + '&psize=16&font=fonts/Roboto-Regular.ttf&color=ff333333&ax=44&ay=48'
1063+
};
10571064

1058-
// Letter markers
1059-
marker = new google.maps.Marker({
1060-
position : point,
1061-
map : map,
1062-
icon : letterMarkerImg,
1063-
draggable: false
1064-
});
1065+
// Letter markers
1066+
marker = new google.maps.Marker({
1067+
position : point,
1068+
map : map,
1069+
icon : letterMarkerImg,
1070+
draggable: false
1071+
});
1072+
}
10651073
}
10661074

10671075
return marker;

0 commit comments

Comments
 (0)