Skip to content

Support for exponential values on range radius input, and use of "gestureHandling" #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/angularLocationpicker.jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! jquery-locationpicker - v0.1.16 - 2017-10-02 */
/*! jquery-locationpicker - v0.1.16 - 2018-12-25 */
"use strict";

angular.module("angular-jquery-locationpicker", []).constant("angularJQueryLocationpickerDefaultValue", {
Expand Down
2 changes: 1 addition & 1 deletion dist/angularLocationpicker.jquery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 49 additions & 6 deletions dist/locationpicker.jquery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! jquery-locationpicker - v0.1.16 - 2017-10-02 */
/*! jquery-locationpicker - v0.1.16 - 2018-12-25 */
(function($) {
function GMapContext(domElement, options) {
var _map = new google.maps.Map(domElement, options);
Expand All @@ -10,6 +10,7 @@
draggable: options.markerDraggable,
icon: options.markerIcon !== undefined ? options.markerIcon : undefined
});
var _updating = false;
return {
map: _map,
marker: _marker,
Expand All @@ -30,7 +31,8 @@
},
settings: options.settings,
domContainer: domElement,
geodecoder: new google.maps.Geocoder()
geodecoder: new google.maps.Geocoder(),
updating: _updating
};
}
var GmUtility = {
Expand Down Expand Up @@ -142,7 +144,11 @@
inputBinding.longitudeInput.val(currentLocation.longitude).change();
}
if (inputBinding.radiusInput) {
inputBinding.radiusInput.val(gmapContext.radius).change();
if (inputBinding.rangeValueMapping) {
inputBinding.radiusInput.val(logPosition(gmapContext.radius, inputBinding)).change();
} else {
inputBinding.radiusInput.val(gmapContext.radius).change();
}
}
if (inputBinding.locationNameInput) {
inputBinding.locationNameInput.val(gmapContext.locationName).change();
Expand All @@ -152,7 +158,12 @@
if (inputBinding) {
if (inputBinding.radiusInput) {
inputBinding.radiusInput.on("change", function(e) {
var radiusInputValue = $(this).val();
var radiusInputValue;
if (inputBinding.rangeValueMapping) {
radiusInputValue = logValue($(this).val(), inputBinding);
} else {
radiusInputValue = $(this).val();
}
if (!e.originalEvent || isNaN(radiusInputValue)) {
return;
}
Expand Down Expand Up @@ -245,11 +256,32 @@
gmapContext.settings.location.latitude = latNew;
gmapContext.settings.location.longitude = lngNew;
gmapContext.radius = radiusNew;
if ("gestureHandling" in settings) gmapContext.map.setOptions({
draggable: settings.gestureHandling
});
GmUtility.setPosition(gmapContext, new google.maps.LatLng(gmapContext.settings.location.latitude, gmapContext.settings.location.longitude), function(context) {
setupInputListenersInput(gmapContext.settings.inputBinding, gmapContext);
context.settings.oninitialized($target);
});
}
function logValue(position, inputBinding) {
var minRange = inputBinding.rangeValueMapping.minRange;
var maxRange = inputBinding.rangeValueMapping.maxRange;
var minRadius = Math.log(inputBinding.rangeValueMapping.minRadius);
var maxRadius = Math.log(inputBinding.rangeValueMapping.maxRadius);
var scale = (maxRadius - minRadius) / (maxRange - minRange);
var result = Math.exp(minRadius + scale * (position - minRange));
return result;
}
function logPosition(value, inputBinding) {
var minRange = inputBinding.rangeValueMapping.minRange;
var maxRange = inputBinding.rangeValueMapping.maxRange;
var minRadius = Math.log(inputBinding.rangeValueMapping.minRadius);
var maxRadius = Math.log(inputBinding.rangeValueMapping.maxRadius);
var scale = (maxRadius - minRadius) / (maxRange - minRange);
var result = (Math.log(value) - minRadius) / scale + minRange;
return result < 0 ? 0 : result;
}
$.fn.locationpicker = function(options, params) {
if (typeof options == "string") {
var _targetDomElement = this.get(0);
Expand Down Expand Up @@ -322,12 +354,14 @@
disableDoubleClickZoom: false,
scrollwheel: settings.scrollwheel,
streetViewControl: false,
fullscreenControl: settings.fullscreenControl,
radius: settings.radius,
locationName: settings.locationName,
settings: settings,
autocompleteOptions: settings.autocompleteOptions,
addressFormat: settings.addressFormat,
draggable: settings.draggable,
gestureHandling: settings.gestureHandling,
clickableIcons: settings.clickableIcons,
markerIcon: settings.markerIcon,
markerDraggable: settings.markerDraggable,
markerVisible: settings.markerVisible
Expand All @@ -338,6 +372,7 @@
var currentLocation = GmUtility.locationFromLatLng(gmapContext.location);
updateInputValues(gmapContext.settings.inputBinding, gmapContext);
context.settings.onchanged.apply(gmapContext.domContainer, [ currentLocation, context.radius, true ]);
gmapContext.updating = false;
});
}
if (settings.markerInCenter) {
Expand All @@ -348,6 +383,11 @@
}
});
gmapContext.map.addListener("idle", function() {
if (gmapContext.updating) {
return;
} else {
gmapContext.updating = true;
}
if (!gmapContext.marker.dragging) {
displayMarkerWithSelectedArea();
}
Expand Down Expand Up @@ -382,14 +422,17 @@
latitudeInput: null,
longitudeInput: null,
radiusInput: null,
rangeValueMapping: null,
locationNameInput: null
},
enableAutocomplete: false,
enableAutocompleteBlur: false,
autocompleteOptions: null,
addressFormat: "postal_code",
fullscreenControl: false,
enableReverseGeocode: true,
draggable: true,
gestureHandling: "auto",
clickableIcons: false,
onchanged: function(currentLocation, radius, isMarkerDropped) {},
onlocationnotfound: function(locationName) {},
oninitialized: function(component) {},
Expand Down
4 changes: 2 additions & 2 deletions dist/locationpicker.jquery.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/locationpicker.jquery.min.js.map

Large diffs are not rendered by default.

92 changes: 92 additions & 0 deletions examples/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,98 @@ <h3>Advanced usage of geo decoder features</h3>
</script>
</div>

<h3>Using a range input with logarithmic values</h3>

<p>The following example illustrates how to use a "range" input to select the radius. Using logarithmic values is more intuitive in this case.</p>
<pre>
$('#us6').locationpicker({
location: {latitude: 46.15242437752303, longitude: 2.7470703125},
radius: 300,
inputBinding: {
latitudeInput: $('#us6-lat'),
longitudeInput: $('#us6-lon'),
radiusInput: $('#us6-radius'),
rangeValueMapping: {
//if rangeValueMapping is used, all the following fields are mandatory
minRange: 0, //minimum value of the range input
maxRange: 100, //maximum value of the range input
minRadius: 100, //minumim radius: 100m
maxRadius: 1000 //maximum radius: 1000m (1km)
},
locationNameInput: $('#us6-address')
},
enableAutocomplete: true,
gestureHandling: 'auto',
onchanged: function (currentLocation, radius, isMarkerDropped) {
$('#us6-radius-output').html('Range value: ' + $('#us6-radius').val() + '<br />Radius: ' + Math.round(radius * 100) / 100);
}
</pre>
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-1 control-label">Location:</label>

<div class="col-sm-5">
<input type="text" class="form-control" id="us6-address" />
</div>
</div>
<div class="form-group">
<label class="col-sm-1 control-label">Radius:</label>

<div class="col-sm-2">
<input type="range" class="form-control" id="us6-radius" min="0" max="100" />
</div>

<div class="col-sm-2" id="us6-radius-output">

</div>
</div>
<div id="us6" style="width: 550px; height: 400px;"></div>
<div class="clearfix">&nbsp;</div>
<div class="m-t-small">
<label class="p-r-small col-sm-1 control-label">Lat.:</label>

<div class="col-sm-2">
<input type="text" class="form-control" style="width: 110px" id="us6-lat" />
</div>
<label class="p-r-small col-sm-1 control-label">Long.:</label>

<div class="col-sm-2">
<input type="text" class="form-control" style="width: 110px" id="us6-lon" />
</div>
</div>
<div class="clearfix"></div>
<script>
$('#us6').locationpicker({
location: {
latitude: 46.15242437752303,
longitude: 2.7470703125
},
radius: 300,
inputBinding: {
latitudeInput: $('#us6-lat'),
longitudeInput: $('#us6-lon'),
rangeValueMapping: {
//if rangeValueMapping is used, all the following fields are mandatory
minRange: 0, //minimum value of the range input
maxRange: 100, //maximum value of the range input
minRadius: 100, //minumim radius: 100m
maxRadius: 1000 //maximum radius: 1000m (1km)
},
radiusInput: $('#us6-radius'),
locationNameInput: $('#us6-address')
},
enableAutocomplete: true,
gestureHandling: 'auto',
onchanged: function (currentLocation, radius, isMarkerDropped) {
$('#us6-radius-output').html('Range value: ' + $('#us6-radius').val() + '<br />Radius: ' + Math.round(radius * 100) / 100);
}
});
</script>
</div>




<div>
<h2 class="page-header" id="credits">Credits</h2> Dmitry Berezovsky, Logicify (<a href="http://logicify.com/" target="_blank">http://logicify.com/</a>)
</div>
Expand Down
Loading