IMPROVEMENT: map geocodding

This commit is contained in:
Tony Air 2019-12-18 00:05:46 +07:00
parent 029b482699
commit 11c76f75d6
8 changed files with 162 additions and 48 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate", "name": "@a2nt/ss-bootstrap-ui-webpack-boilerplate",
"version": "1.3.5", "version": "1.3.7",
"author": "Tony Air <tony@twma.pro>", "author": "Tony Air <tony@twma.pro>",
"license": "MIT", "license": "MIT",
"description": "This UI Kit allows you to build Bootstrap 4 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.", "description": "This UI Kit allows you to build Bootstrap 4 webapp with some extra UI features. It's easy to extend and easy to convert HTML templates to CMS templates.",

View File

@ -39,7 +39,25 @@ const MapAPI = (($) => {
ui.map = Drv.init($el, config); ui.map = Drv.init($el, config);
$el.on(Events.MAPLOADED, (e) => { $el.on(Events.MAPLOADED, (e) => {
Drv.addGeoJson(config); if (config['geojson']) {
console.log(`${NAME}: setting up geocode data`);
Drv.addGeoJson(config);
} else if (config['address']) {
console.log(config['address']);
console.log(`${NAME}: setting up address marker`);
Drv.geocode(config['address'], (result) => {
console.log(result);
});
} else if (config['lat'] && config['lng']) {
console.log(`${NAME}: setting up single lat/lng marker`);
if (!config['icon']) {
config['icon'] = '<i class="fas fa-map-marker-alt"></i>';
}
Drv.addMarker([config['lng'], config['lat']], config);
}
console.log(`${NAME}: Map is loaded`); console.log(`${NAME}: Map is loaded`);
}); });

View File

@ -17,6 +17,7 @@ const GoogleMapsDriver = (($) => {
ui.$el = $el; ui.$el = $el;
ui.config = config; ui.config = config;
ui.markers = [];
W[`init${ui.getName()}`] = () => { W[`init${ui.getName()}`] = () => {
ui.googleApiLoaded(); ui.googleApiLoaded();
@ -27,6 +28,7 @@ const GoogleMapsDriver = (($) => {
googleApiLoaded() { googleApiLoaded() {
const ui = this; const ui = this;
const $el = ui.$el; const $el = ui.$el;
const config = ui.config; const config = ui.config;
const $mapDiv = $el.find('.mapAPI-map'); const $mapDiv = $el.find('.mapAPI-map');
@ -67,6 +69,7 @@ const GoogleMapsDriver = (($) => {
'</div>', '</div>',
}); });
ui.geocoder = new google.maps.Geocoder();
$el.trigger(Events.MAPLOADED); $el.trigger(Events.MAPLOADED);
@ -74,6 +77,7 @@ const GoogleMapsDriver = (($) => {
addMarker(crds, config) { addMarker(crds, config) {
const ui = this; const ui = this;
const pos = { const pos = {
lat: crds[1], lat: crds[1],
lng: crds[0], lng: crds[0],
@ -92,6 +96,8 @@ const GoogleMapsDriver = (($) => {
}, },
}); });
ui.markers.push(marker);
return marker; return marker;
} }
@ -134,6 +140,46 @@ const GoogleMapsDriver = (($) => {
ui.$el.trigger(Events.MAPPOPUPCLOSE); ui.$el.trigger(Events.MAPPOPUPCLOSE);
} }
geocode(addr, callback) {
const ui = this;
ui.geocoder.geocode({
'address': addr
}, (results, status) => {
if (status === 'OK') {
//results[0].geometry.location;
if (typeof callback === 'function') {
callback(results);
}
return results;
} else {
console.error(`${ui.getName()}: Geocode was not successful for the following reason: ${status}`);
}
});
}
reverseGeocode(latLng, callback) {
const ui = this;
ui.geocoder.geocode({
'location': latlng
}, (results, status) => {
if (status === 'OK') {
//results[0].formatted_address;
if (typeof callback === 'function') {
callback(results);
}
return results;
} else {
console.error(`${ui.getName()}: Reverse Geocoding was not successful for the following reason: ${status}`);
}
});
}
addGeoJson(config) { addGeoJson(config) {
const ui = this; const ui = this;
@ -181,9 +227,17 @@ const GoogleMapsDriver = (($) => {
restoreBounds() { restoreBounds() {
const ui = this; const ui = this;
ui.map.fitBounds(ui.default_bounds, { if (ui.default_bounds) {
padding: 30, ui.map.fitBounds(ui.default_bounds, {
}); //panToBounds padding: 30,
}); //panToBounds
} else {
if (ui.markers[0]) {
ui.map.setCenter(ui.markers[0].getPosition());
}
ui.restoreZoom();
}
} }
restoreZoom() { restoreZoom() {

18
src/scss/_animations.scss Executable file
View File

@ -0,0 +1,18 @@
// pulse
.pulse {
animation: pulse 0.8s linear infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(0.8);
}
100% {
transform: scale(1);
}
}

View File

@ -35,7 +35,7 @@ h1.page-header {
} }
} }
// Sidebar elements // Sidebar-like elements
&.secondary { &.secondary {
padding: ($grid-gutter-element-height / 2) 0; padding: ($grid-gutter-element-height / 2) 0;
} }
@ -43,6 +43,11 @@ h1.page-header {
.sidebar { .sidebar {
padding: ($grid-gutter-element-height / 2) 0; padding: ($grid-gutter-element-height / 2) 0;
// Sidebar elements
.element {
padding: ($grid-gutter-element-height / 2) 0;
}
} }
// remove container paddings for the slideshow // remove container paddings for the slideshow

View File

@ -1,6 +1,7 @@
/* /*
* some basic styles * some basic styles
*/ */
@import "_animations";
// don't let images be wider than the parent layer // don't let images be wider than the parent layer
div, a, span, button, i { div, a, span, button, i {
@ -312,25 +313,6 @@ button, input, optgroup, select, textarea,
} }
} }
// pulse
.pulse {
animation: pulse 0.8s linear infinite;
}
@keyframes pulse {
0% {
transform: scale(1);
}
50% {
transform: scale(0.8);
}
100% {
transform: scale(1);
}
}
.row, .row-xs { .row, .row-xs {
> [class^="col-"] > .card { > [class^="col-"] > .card {
height: 100%; height: 100%;

View File

@ -7,20 +7,42 @@
margin-bottom: 1rem; margin-bottom: 1rem;
} }
.mapboxgl-popup { .mapboxgl {
font-size: .8rem; &-popup {
z-index: 4; position: absolute;
line-height: 20px; top: 0;
} left: 0;
display: flex;
pointer-events: none;
font-size: .8rem;
z-index: 4;
line-height: 20px;
}
.mapboxgl-popup-content { &-popup-anchor-bottom,
min-width: 240px; &-popup-anchor-bottom-left,
min-height: 5rem; &-popup-anchor-bottom-right {
box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.4); flex-direction: column-reverse;
}
.mapboxgl-popup-close-button { &-popup-content {
position: relative;
pointer-events: auto;
padding: 10px 10px 15px;
border-radius: 3px;
background: $white;
min-width: 240px;
min-height: 5rem;
box-shadow: 0px 4px 10px 0px rgba(0, 0, 0, 0.4);
}
&-popup-close-button {
position: absolute;
right: 0;
top: 0;
font-size: 2rem; font-size: 2rem;
padding: .5rem; padding: .5rem;
border-top-right-radius: 3px;
&:hover, &:hover,
&:focus { &:focus {
@ -28,20 +50,33 @@
color: $white; color: $white;
} }
} }
}
.mapboxgl-marker { &-popup-tip {
width: 30px; width: 0;
height: 30px; height: 0;
font-size: 30px; border: 10px solid transparent;
cursor: pointer; z-index: 1;
text-align: center; }
color: $primary;
.marker-icon, &-popup-anchor-bottom &-popup-tip {
.fas, align-self: center;
.fab, border-bottom: none;
.far { border-top-color: #fff;
animation: pulse 0.8s linear infinite; }
&-marker {
width: 30px;
height: 30px;
font-size: 30px;
cursor: pointer;
text-align: center;
color: $primary;
.marker-icon,
.fas,
.fab,
.far {
animation: pulse 0.8s linear infinite;
}
} }
} }

View File

@ -35,6 +35,8 @@ $navbar-light-toggler-icon-bg: none !default;
// IE > 9 // IE > 9
$enable-flex: true !default; $enable-flex: true !default;
$enable-responsive-font-sizes: true !default;
@import "~bootstrap/scss/functions"; @import "~bootstrap/scss/functions";
@import "~bootstrap/scss/variables"; @import "~bootstrap/scss/variables";
@import "~bootstrap/scss/mixins"; @import "~bootstrap/scss/mixins";