Skip to content

Commit

Permalink
Turn createHTML Into Private Function
Browse files Browse the repository at this point in the history
This is really just a helper function. There is no need for it to be
part of the map object.
  • Loading branch information
Kelderic committed Oct 11, 2016
1 parent e204ad8 commit 8d047d7
Showing 1 changed file with 103 additions and 105 deletions.
208 changes: 103 additions & 105 deletions mapstractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/* Type: Google Map Object */
/* Purpose: This object is the primary Google */
/* Map object. */
self.gMap = new google.maps.Map(self.createHTML({styles: {height:'100%'}}), params.mapOptions);
self.gMap = new google.maps.Map(_createHTML({styles: {height:'100%'}, location: self.mapWrap}), params.mapOptions);
self.gMap.mapstractor = self;

/* Variable: markerURL */
Expand Down Expand Up @@ -396,7 +396,7 @@

// CREATE THE HTML CONTROL WRAP

var searchBoxWrapElement = self.createHTML({
var searchBoxWrapElement = _createHTML({
tagName: 'div',
id: 'searchBox',
className: 'control',
Expand All @@ -414,7 +414,7 @@

// CREATE HTML ELEMENT FOR THE BUTTON

var searchSettingsButtonElement = self.createHTML({
var searchSettingsButtonElement = _createHTML({
tagName:'button',
location: searchBoxWrapElement,
innerHTML: settingsIcon
Expand All @@ -433,7 +433,7 @@

// CREATE HTML ELEMENT FOR SEARCH INPUT

var searchInputElement = self.createHTML({
var searchInputElement = _createHTML({
tagName:'input',
location: searchBoxWrapElement,
styles: {
Expand Down Expand Up @@ -515,7 +515,7 @@

// CREATE HTML ELEMENT FOR BUTTON

var searchButtonElement = self.createHTML({
var searchButtonElement = _createHTML({
tagName:'button',
location: searchBoxWrapElement,
innerHTML: magnifyingGlassIcon
Expand Down Expand Up @@ -584,7 +584,7 @@

// CREATE THE HTML CONTROL WRAP

var shareLocationWrapElement = self.createHTML({
var shareLocationWrapElement = _createHTML({
tagName: 'div',
id: 'sharelocation',
className: 'control',
Expand All @@ -593,7 +593,7 @@

// CREATE THE HTML CONTROL ELEMENTS

var shareLocationButtonElement = self.createHTML({
var shareLocationButtonElement = _createHTML({
tagName: 'button',
location: shareLocationWrapElement,
innerHTML: locationIcon
Expand Down Expand Up @@ -716,14 +716,101 @@

};

Class.prototype.createHTML = function(params) {
Class.prototype.getControlWrap = function(params) {

// STORE this AS self, SO THAT IT IS ACCESSIBLE IN SUB-FUNCTIONS AND TIMEOUTS.

var self = this;

// SETUP VARIABLES FROM PROVIDED PARAMETERS

/* Variable: location */
/* Type: String */
/* Default: 'TOP_LEFT' */
/* Purpose: This is the tagName of the element */
/* that is being created. */
var location = 'location' in params ? params.location : 'TOP_LEFT';

// FIND THE SPECIFIED CONTROL WRAPPER ELEMENT BASED ON PROVIDED LOCATION

var element = self.gMap.controls[google.maps.ControlPosition[location]].getAt(0);

// RETURN THE CONTROL WRAPPER ELEMENT

return element;

};

Class.prototype.getPlaceFromAutocompleteSuggestions = function(placefoundCallback) {

// STORE this AS self, SO THAT IT IS ACCESSIBLE IN SUB-FUNCTIONS AND TIMEOUTS.

var self = this;

// SETUP VARIABLES FROM PROVIDED PARAMETERS

/* Variable: placefoundCallback */
/* Type: function */
/* Default: N/A */
/* Purpose: This function is the callback which */
/* is called when the search finds a */
/* place successfully. */
placefoundCallback = placefoundCallback;

// CREATE A GEOCODER USING GOOGLE JS API

var geocoder = new google.maps.Geocoder();

// GET THE TEXT CONTENT TO USE TO SEARCH FOR.

var searchText;

if ( self.autoCompleteList.firstElementChild ) {

searchText = self.autoCompleteList.firstElementChild.textContent;

} else if ( self.searchInputElement.value != '' ) {

searchText = self.searchInputElement.value;

} else {

searchText = '';

}

if ( searchText ) {

// USE THE GOOGLE GEOCODER TO SEARCH FOR THE TEXT RETRIEVED ABOVE, AND FROM IT
// GET A GOOGLE PLACE CONSTRUCT. RUN THE CALLBACK FUNCTION ON THAT PLACE.

geocoder.geocode({ 'address': searchText }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var place = results[0]; place.name = place.address_components[0].long_name;
self.searchInputElement.value = place.formatted_address;
placefoundCallback(place);
} else {
console.log('Geocoding the Place from the autoComplete list failed. The status code is: ' + status);
}
});

} else {

console.log('There is nothing to search for (The searchbox and autocomplete list are both empty.');

}

};


/***************************************/
/********** PRIVATE FUNCTIONS **********/
/***************************************/

function _createHTML( params ) {

// SETUP VARIABLES FROM PROVIDED PARAMETERS

/* Variable: tagName */
/* Type: String */
/* Default: 'div' */
Expand Down Expand Up @@ -781,7 +868,7 @@
/* Default: self.mapWrap */
/* Purpose: This is an HTML element that the new */
/* created element will be appended to. */
var location = 'location' in params ? params.location : self.mapWrap;
var location = 'location' in params ? params.location : null;

// CREATE HTML ELEMENT

Expand Down Expand Up @@ -815,98 +902,7 @@

return element;

};

Class.prototype.getControlWrap = function(params) {

// STORE this AS self, SO THAT IT IS ACCESSIBLE IN SUB-FUNCTIONS AND TIMEOUTS.

var self = this;

// SETUP VARIABLES FROM PROVIDED PARAMETERS

/* Variable: location */
/* Type: String */
/* Default: 'TOP_LEFT' */
/* Purpose: This is the tagName of the element */
/* that is being created. */
var location = 'location' in params ? params.location : 'TOP_LEFT';

// FIND THE SPECIFIED CONTROL WRAPPER ELEMENT BASED ON PROVIDED LOCATION

var element = self.gMap.controls[google.maps.ControlPosition[location]].getAt(0);

// RETURN THE CONTROL WRAPPER ELEMENT

return element;

};

Class.prototype.getPlaceFromAutocompleteSuggestions = function(placefoundCallback) {

// STORE this AS self, SO THAT IT IS ACCESSIBLE IN SUB-FUNCTIONS AND TIMEOUTS.

var self = this;

// SETUP VARIABLES FROM PROVIDED PARAMETERS

/* Variable: placefoundCallback */
/* Type: function */
/* Default: N/A */
/* Purpose: This function is the callback which */
/* is called when the search finds a */
/* place successfully. */
placefoundCallback = placefoundCallback;

// CREATE A GEOCODER USING GOOGLE JS API

var geocoder = new google.maps.Geocoder();

// GET THE TEXT CONTENT TO USE TO SEARCH FOR.

var searchText;

if ( self.autoCompleteList.firstElementChild ) {

searchText = self.autoCompleteList.firstElementChild.textContent;

} else if ( self.searchInputElement.value != '' ) {

searchText = self.searchInputElement.value;

} else {

searchText = '';

}

if ( searchText ) {

// USE THE GOOGLE GEOCODER TO SEARCH FOR THE TEXT RETRIEVED ABOVE, AND FROM IT
// GET A GOOGLE PLACE CONSTRUCT. RUN THE CALLBACK FUNCTION ON THAT PLACE.

geocoder.geocode({ 'address': searchText }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var place = results[0]; place.name = place.address_components[0].long_name;
self.searchInputElement.value = place.formatted_address;
placefoundCallback(place);
} else {
console.log('Geocoding the Place from the autoComplete list failed. The status code is: ' + status);
}
});

} else {

console.log('There is nothing to search for (The searchbox and autocomplete list are both empty.');

}

};


/***************************************/
/********** PRIVATE FUNCTIONS **********/
/***************************************/
}

function _createUIWrappers(map) {

Expand All @@ -926,8 +922,9 @@
// LOOP THROUGH WRAPPER OBJECT AND CREATE WRAPPER ELEMENTS

for ( var i=0, l=wrappers.length; i<l; i++ ) {
map.gMap.controls[google.maps.ControlPosition[wrappers[i].position]].push(map.createHTML({
className: wrappers[i].class
map.gMap.controls[google.maps.ControlPosition[wrappers[i].position]].push(_createHTML({
className: wrappers[i].class,
location: map.mapWrap
}));
}

Expand All @@ -937,9 +934,10 @@

// CREATE THE WRAPPER ELEMENT AND PLACE IT ON THE MAP, THEN STORE IT IN A GLOBAL

map.overlay = map.createHTML({
map.overlay = _createHTML({
className: 'overlay loading',
innerHTML: '<svg></svg><div></div><span>Starting up...</span>'
innerHTML: '<svg></svg><div></div><span>Starting up...</span>',
location: map.mapWrap
});

}
Expand Down

0 comments on commit 8d047d7

Please sign in to comment.