Skip to content

Commit 01c0712

Browse files
committed
Added category marker images example, fixed loading setting
1 parent 0cc3e5a commit 01c0712

File tree

8 files changed

+264
-52
lines changed

8 files changed

+264
-52
lines changed

dist/category-markers-example.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Map Example - Category Markers</title>
5+
<meta charset="UTF-8">
6+
<link rel="stylesheet" type="text/css" href="css/storelocator.css" />
7+
</head>
8+
9+
<body>
10+
11+
<div class="bh-sl-container">
12+
<div id="page-header">
13+
<h1>Using Chipotle as an Example</h1>
14+
<p>I used locations around Minneapolis and the southwest suburbs. So, for example, Edina, Plymouth, Eden Prarie, etc. would be good for testing the functionality.
15+
You can use just the city as the address - ex: Edina, MN.</p>
16+
</div>
17+
18+
<div class="bh-sl-form-container">
19+
<form id="bh-sl-user-location" method="post" action="#">
20+
<div class="form-input">
21+
<label for="bh-sl-address">Enter Address or Zip Code:</label>
22+
<input type="text" id="bh-sl-address" name="bh-sl-address" />
23+
</div>
24+
25+
<button id="bh-sl-submit" type="submit">Submit</button>
26+
</form>
27+
</div>
28+
29+
<div id="map-container" class="bh-sl-map-container">
30+
<div class="bh-sl-loc-list">
31+
<ul class="list"></ul>
32+
</div>
33+
<div id="bh-sl-map" class="bh-sl-map"></div>
34+
</div>
35+
</div>
36+
37+
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
38+
<script src="js/handlebars.min.js"></script>
39+
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
40+
<script src="js/jquery.storelocator.js"></script>
41+
<script>
42+
$(function() {
43+
$('#map-container').storeLocator({
44+
catMarkers : {
45+
'Restaurant' : ['img/red-marker.svg', 32, 32],
46+
'Cafe' : ['img/blue-marker.svg', 32, 32]
47+
}
48+
});
49+
});
50+
</script>
51+
52+
</body>
53+
</html>

dist/data/locations.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<marker name="Chipotle Golden Valley" lat="44.983935" lng="-93.380542" category="Restaurant" address="515 Winnetka Ave. N" address2="" city="Golden Valley" state="MN" postal="55427" country="US" phone="763-544-2530" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" />
77
<marker name="Chipotle Hopkins" lat="44.924363" lng="-93.410158" category="Cafe" address="786 Mainstreet" address2="" city="Hopkins" state="MN" postal="55343" country="US" phone="952-935-0044" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="Margaritas" />
88
<marker name="Chipotle Minneapolis" lat="44.973557" lng="-93.275111" category="Restaurant" address="1040 Nicollet Ave" address2="" city="Minneapolis" state="MN" postal="55403" country="US" phone="612-659-7955" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="Margaritas" />
9-
<marker name="Chipotle Minneapolis" lat="44.97774" lng="-93.270909" category="Restaurant" address="50 South 6th" address2="" city="Minneapolis" state="MN" postal="55402" country="US" phone="612-333-0434" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" />
9+
<marker name="Chipotle Minneapolis" lat="44.97774" lng="-93.270909" category="Restaurant, Cafe" address="50 South 6th" address2="" city="Minneapolis" state="MN" postal="55402" country="US" phone="612-333-0434" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" />
1010
<marker name="Chipotle Edina" lat="44.879826" lng="-93.321280" category="Restaurant" address="6801 York Avenue South" address2="" city="Edina" state="MN" postal="55435" country="US" phone="952-926-6651" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" />
1111
<marker name="Chipotle Minnetonka" lat="44.970495" lng="-93.437430" category="Restaurant" address="12509 Wayzata Blvd" address2="" city="Minnetonka" state="MN" postal="55305" country="US" phone="952-252-4900" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="Margaritas" />
1212
<marker name="Chipotle Minneapolis" lat="44.972808" lng="-93.247153" category="Restaurant" address="229 Cedar Ave S" address2="" city="Minneapolis" state="MN" postal="55454" country="US" phone="612-659-7830" email="info@chipotle.com" web="http://www.chipotle.com" hours1="Mon-Sun 11am-10pm" hours2="" hours3="" featured="" features="" />

dist/img/blue-marker.svg

Lines changed: 9 additions & 0 deletions
Loading

dist/img/red-marker.svg

Lines changed: 9 additions & 0 deletions
Loading

dist/js/jquery.storelocator.js

Lines changed: 95 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-09-21
1+
/*! jQuery Google Maps Store Locator - v1.4.9 - 2014-10-05
22
* http://www.bjornblog.com/web/jquery-store-locator-plugin
33
* Copyright (c) 2014 Bjorn Holine; Licensed MIT */
44

@@ -19,7 +19,7 @@
1919
var featuredset = [], locationset = [], normalset = [], markers = [];
2020
var filters = {}, locationData = {}, GeoCodeCalc = {}, mappingObj = {};
2121

22-
// Create the defaults once. Do not change these settings in this file - settings should be overridden in the plugin call
22+
// Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call
2323
var defaults = {
2424
'mapID' : 'bh-sl-map',
2525
'locationList' : 'bh-sl-loc-list',
@@ -33,6 +33,7 @@
3333
},
3434
'markerImg' : null,
3535
'markerDim' : null,
36+
'catMarkers' : null,
3637
'lengthUnit' : 'm',
3738
'storeLimit' : 26,
3839
'distanceAlert' : 60,
@@ -59,7 +60,7 @@
5960
'maxDistanceID' : 'bh-sl-maxdistance',
6061
'fullMapStart' : false,
6162
'noForm' : false,
62-
'loading' : false, //TODO: Add loading back
63+
'loading' : false,
6364
'loadingContainer' : 'bh-sl-loading',
6465
'featuredLocations' : false,
6566
'pagination' : false,
@@ -354,15 +355,26 @@
354355

355356
/**
356357
* AJAX data request
358+
*
359+
* @param lat (number)
360+
* @param lng (number)
361+
* @param address (string)
362+
* @returns {*}
357363
*/
358364
getData: function (lat, lng, address) {
365+
var _this = this;
359366
var d = $.Deferred();
360367

361368
// Before send callback
362369
if (this.settings.callbackBeforeSend) {
363370
this.settings.callbackBeforeSend.call(this);
364371
}
365372

373+
//Loading
374+
if(this.settings.loading === true){
375+
$('.' + this.settings.formContainer).append('<div class="' + this.settings.loadingContainer +'"><\/div>');
376+
}
377+
366378
// AJAX request
367379
$.ajax({
368380
type : 'GET',
@@ -377,6 +389,11 @@
377389
jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.jsonpCallback : null)
378390
}).done(function (p) {
379391
d.resolve(p);
392+
393+
//Loading remove
394+
if(_this.settings.loading === true){
395+
$('.' + _this.settings.formContainer + ' .' + _this.settings.loadingContainer).remove();
396+
}
380397
}).fail(d.reject);
381398
return d.promise();
382399
},
@@ -705,29 +722,82 @@
705722
$('.bh-sl-pagination-container .bh-sl-pagination').append(pagesOutput);
706723
},
707724

725+
/**
726+
* Marker image setup
727+
*
728+
* @param markerUrl (string) path to marker image
729+
* @param markerWidth (number} width of mearker
730+
* @param markerHeight (number) height of marker
731+
* @returns {object} Google Maps icon object
732+
*/
733+
markerImage: function (markerUrl, markerWidth, markerHeight) {
734+
var markerImg;
735+
736+
// User defined marker dimensions
737+
if(typeof markerWidth !== 'undefined' && typeof markerHeight !== 'undefined') {
738+
markerImg = {
739+
url: markerUrl,
740+
size: new google.maps.Size(markerWidth, markerHeight)
741+
};
742+
}
743+
// Default marker dimensions: 32px x 32px
744+
else {
745+
markerImg = {
746+
url: markerUrl,
747+
size: new google.maps.Size(32, 32)
748+
};
749+
}
750+
751+
return markerImg;
752+
},
753+
708754
/**
709755
* Map marker setup
710756
*
711-
* @param point
712-
* @param name
713-
* @param address
714-
* @param letter
757+
* @param point {object} LatLng of current location
758+
* @param name (string) location name
759+
* @param address (string) location address
760+
* @param letter (string) optional letter used for front-end identification and correlation between list and points
761+
* @param category (string) location category/categories
715762
* @returns {google.maps.Marker}
716763
*/
717-
createMarker: function (point, name, address, letter, map) {
764+
createMarker: function (point, name, address, letter, map, category) {
718765
var marker, markerImg, letterMarkerImg;
719-
720-
if(this.settings.markerImg !== null) {
721-
if(this.settings.markerDim !== null) {
722-
markerImg = new google.maps.MarkerImage(this.settings.markerImg, null, null, null, new google.maps.Size(this.settings.markerDim.width,this.settings.markerDim.height));
766+
var categories = [];
767+
768+
// Remove any spaces from category value
769+
if(category.length) {
770+
category = category.replace(/\s+/g, '');
771+
}
772+
773+
// Custom multi-marker image override (different markers for different categories
774+
if(this.settings.catMarkers !== null) {
775+
// Multiple categories
776+
if(category.indexOf(',') !== -1) {
777+
// Break the category variable into an array if there are multiple categories for the location
778+
categories = category.split(',');
779+
// With multiple categories the color will be determined by the last matched category in the data
780+
for(var i = 0; i < categories.length; i++) {
781+
if(categories[i] in this.settings.catMarkers) {
782+
markerImg = this.markerImage(this.settings.catMarkers[categories[i]][0], this.settings.catMarkers[categories[i]][1], this.settings.catMarkers[categories[i]][2]);
783+
}
784+
}
723785
}
786+
// Single category
724787
else {
725-
markerImg = new google.maps.MarkerImage(this.settings.markerImg, null, null, null, new google.maps.Size(32,32));
788+
if(category in this.settings.catMarkers) {
789+
markerImg = this.markerImage(this.settings.catMarkers[category][0], this.settings.catMarkers[category][1], this.settings.catMarkers[category][2]);
790+
}
726791
}
727792
}
793+
794+
// Custom single marker image override
795+
if(this.settings.markerImg !== null) {
796+
markerImg = this.markerImage(this.settings.markerImg, this.settings.markerDim.width, this.settings.markerDim.height);
797+
}
728798

729799
// Create the default markers
730-
if (this.settings.storeLimit === -1 || this.settings.storeLimit > 26) {
800+
if (this.settings.storeLimit === -1 || this.settings.storeLimit > 26 || this.settings.catMarkers !== null) {
731801
marker = new google.maps.Marker({
732802
position : point,
733803
map : map,
@@ -737,7 +807,9 @@
737807
}
738808
else {
739809
// Letter markers image
740-
letterMarkerImg = new google.maps.MarkerImage('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');
810+
letterMarkerImg = {
811+
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'
812+
};
741813

742814
// Letter markers
743815
marker = new google.maps.Marker({
@@ -755,8 +827,8 @@
755827
* Define the location data for the templates
756828
*
757829
* @param currentMarker {object} Google Maps marker
758-
* @param storeStart {number} optional first location on the current page
759-
* @param page {number} optional current page
830+
* @param storeStart (number) optional first location on the current page
831+
* @param page (number) optional current page
760832
* @returns {{location: *[]}}
761833
*/
762834
defineLocationData: function (currentMarker, storeStart, page) {
@@ -1423,15 +1495,12 @@
14231495
}
14241496
else{
14251497
if(_this.settings.originMarkerImg !== null) {
1426-
if(_this.settings.originMarkerDim !== null) {
1427-
originImg = new google.maps.MarkerImage(_this.settings.originMarkerImg, null, null, null, new google.maps.Size(_this.settings.originMarkerDim.width,_this.settings.originMarkerDim.height));
1428-
}
1429-
else {
1430-
originImg = new google.maps.MarkerImage(_this.settings.originMarkerImg);
1431-
}
1498+
originImg = this.markerImage(_this.settings.originMarkerImg, _this.settings.originMarkerDim.width, _this.settings.originMarkerDim.height);
14321499
}
14331500
else {
1434-
originImg = new google.maps.MarkerImage('https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png');
1501+
originImg = {
1502+
url: 'https://mt.googleapis.com/vt/icon/name=icons/spotlight/spotlight-waypoint-a.png'
1503+
};
14351504
}
14361505

14371506
marker = new google.maps.Marker({
@@ -1475,8 +1544,9 @@
14751544
letter = String.fromCharCode('A'.charCodeAt(0) + y);
14761545
}
14771546

1547+
14781548
var point = new google.maps.LatLng(locationset[y].lat, locationset[y].lng);
1479-
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, map);
1549+
marker = _this.createMarker(point, locationset[y].name, locationset[y].address, letter, map, locationset[y].category);
14801550
marker.set('id', y);
14811551
markers[y] = marker;
14821552
if ((_this.settings.fullMapStart === true && firstRun === true) || (_this.settings.mapSettings.zoom === 0) || (typeof origin === 'undefined')) {

dist/js/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
@@ -9,6 +9,7 @@
99
| mapSettings | { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP } | Google maps settings object. |
1010
| markerImg | null | Replacement marker image used for all locations |
1111
| markerDim | null | Replacement marker dimensions object - ex value: { height: 20, width: 20 } |
12+
| catMarkers | null | Multiple replacement marker images based on categories object. Value should be array with image path followed by dimensions - ex value: catMarkers : {'Restaurant' : ['img/red-marker.svg', 32, 32]}
1213
| lengthUnit | 'm' | The unit of length. Default is m for miles, change to km for kilometers. |
1314
| storeLimit | 26 | The number of closest locations displayed at one time. Set to -1 for unlimited. |
1415
| distanceAlert | 60 | Displays alert if there are no locations with 60 m/km of the user's location. Set to -1 to disable. |

0 commit comments

Comments
 (0)