IMPR: Maps API improvement

This commit is contained in:
Tony Air 2020-10-26 23:07:16 +07:00
parent 548b1a508e
commit 4d61ad171e
1 changed files with 24 additions and 9 deletions

View File

@ -38,6 +38,10 @@ const MapAPI = (($) => {
config['font-family'] = $BODY.css('font-family'); config['font-family'] = $BODY.css('font-family');
if (!config['icon']) {
config['icon'] = '<i class="fas fa-map-marker-alt"></i>';
}
console.log(`${NAME}: init ${Drv.getName()}...`); console.log(`${NAME}: init ${Drv.getName()}...`);
Drv.init($el, config); Drv.init($el, config);
ui.drv = Drv; ui.drv = Drv;
@ -51,17 +55,28 @@ const MapAPI = (($) => {
} else if (config['address']) { } else if (config['address']) {
console.log(config['address']); console.log(config['address']);
console.log(`${NAME}: setting up address marker`); console.log(`${NAME}: setting up address marker`);
Drv.geocode(config['address'], (result) => { Drv.geocode(config['address'], (results) => {
console.log(result); console.log(results);
const lat = results[0].geometry.location.lat();
const lng = results[0].geometry.location.lng();
console.log(
`${NAME}: setting up single lat/lng marker lat: ${lat} lng: ${lng}`,
);
Drv.addMarker([lng, lat], config);
ui.map.setCenter({ lat: lat, lng: lng });
}); });
} else if (config['lat'] && config['lng']) { } else if (config['lat'] && config['lng']) {
console.log(`${NAME}: setting up single lat/lng marker`); const lat = config['lat'];
const lng = config['lng'];
if (!config['icon']) { console.log(
config['icon'] = '<i class="fas fa-map-marker-alt"></i>'; `${NAME}: setting up single lat/lng marker lat: ${lat} lng: ${lng}`,
} );
Drv.addMarker([config['lng'], config['lat']], config); Drv.addMarker([lng, lat], config);
} }
$el.data(DATA_KEY, ui); $el.data(DATA_KEY, ui);
@ -88,7 +103,7 @@ const MapAPI = (($) => {
static _jQueryInterface() { static _jQueryInterface() {
if (typeof W.localStorage !== 'undefined') { if (typeof W.localStorage !== 'undefined') {
return this.each(function() { return this.each(function () {
// attach functionality to el // attach functionality to el
const $el = $(this); const $el = $(this);
let data = $el.data(DATA_KEY); let data = $el.data(DATA_KEY);
@ -105,7 +120,7 @@ const MapAPI = (($) => {
// jQuery interface // jQuery interface
$.fn[NAME] = MapAPI._jQueryInterface; $.fn[NAME] = MapAPI._jQueryInterface;
$.fn[NAME].Constructor = MapAPI; $.fn[NAME].Constructor = MapAPI;
$.fn[NAME].noConflict = function() { $.fn[NAME].noConflict = function () {
$.fn[NAME] = JQUERY_NO_CONFLICT; $.fn[NAME] = JQUERY_NO_CONFLICT;
return MapAPI._jQueryInterface; return MapAPI._jQueryInterface;
}; };