Skip to content
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

Add tile layer to options #228

Merged
merged 5 commits into from
Jan 2, 2020
Merged
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
23 changes: 13 additions & 10 deletions dist/Leaflet.BlurredLocation.js

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

72 changes: 72 additions & 0 deletions examples/bluish.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>

<title>Leaflet.BlurredLocation</title>

<script src="https://maps.googleapis.com/maps/api/js?libraries=places&language=en&key=AIzaSyAOLUQngEmJv0_zcG1xkGq-CXIPpLQY8iQ"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="../node_modules/leaflet/dist/leaflet.css" rel="stylesheet">
<script src="../node_modules/jquery/dist/jquery.min.js"></script>
<script src="../node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="../dist/Leaflet.BlurredLocation.js"></script>

</head>

<body>

<!-- START OF EXAMPLE -->
<div class="container" >
<div class="row" >
<div class="col-md-6">
<h3 class="font-size-small">Drag map to select location </h3>
<hr>
<br />
<div id="map" class="leaflet-map" style="width: 600px; height: 400px;"></div>
<br/>
<h3 class="font-size-small">In Text</h3><br/>
<input id="placenameDisplay" type="text" class="form-control"><br/>
</div>

<div class="col-md-5 col-md-offset-1">
<label class="h2 font-size-big">&nbsp;&nbsp;Add location to your content</label>
<br/>
<hr>
<h4 class="font-size-small">Option 1 : By Placename</h4>
</br>
<input id="placenameInput" type="text" class="form-control"><br/>
<h4 class="font-size-small">Option 2 : By dragging the map</h4></br>
<h4 class="font-size-small">Option 3 : By giving co-ordinates</h4></br>
<div class="col-md-6">
<input id="lat" type="text" class="form-control" placeholder="Latitude"><br/>
</div>
<div class="col-md-6">
<input id="lng" type="text" class="form-control" placeholder="Longitude"><br/>
</div>
</div>
</div>
</div>
<!-- END OF EXAMPLE -->
<script>
options = {}

// We can add Interface Options as follows:
InterfaceOptions = {};
InterfaceOptions.latId = 'lat';
InterfaceOptions.lngId = 'lng';

options.InterfaceOptions = InterfaceOptions;
var token = "pk.eyJ1Ijoianl3YXJyZW4iLCJhIjoiVzVZcGg3NCJ9.BJ6ArUPuTs1JT9Ssu3K8ig";


var token = "pk.eyJ1Ijoianl3YXJyZW4iLCJhIjoiVzVZcGg3NCJ9.BJ6ArUPuTs1JT9Ssu3K8ig";
// options.tileLayerUrl = options.tileLayerUrl || 'https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png';
options.tileLayerUrl = 'https://api.mapbox.com/styles/v1/mapbox/outdoors-v11/tiles/{z}/{x}/{y}?access_token=' + token;
var blurredLocation = new BlurredLocation(options);
blurredLocation.panMapToGeocodedLocation("placenameInput");
blurredLocation.gridSystem.removeGrid();
blurredLocation.disableCenterShade();

</script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "leaflet-blurred-location",
"version": "1.4.1",
"version": "1.5.1",
"description": "",
"main": "Gruntfile.js",
"scripts": {
Expand Down
24 changes: 13 additions & 11 deletions src/blurredLocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ BlurredLocation = function BlurredLocation(options) {

options.Interface = options.Interface || require('./ui/Interface.js');

options.Geocoding = options.Geocoding || require('./core/Geocoding.js')
options.Geocoding = options.Geocoding || require('./core/Geocoding.js');

options.tileLayerUrl = options.tileLayerUrl || 'https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png';

var gridSystemOptions = options.gridSystemOptions || {};
gridSystemOptions.map = options.map;
Expand Down Expand Up @@ -55,7 +57,7 @@ BlurredLocation = function BlurredLocation(options) {

var Interface = options.Interface(InterfaceOptions);

var tileLayer = L.tileLayer("https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png").addTo(options.map);
var tileLayer = L.tileLayer(options.tileLayerUrl).addTo(options.map);

options.map.options.scrollWheelZoom = "center";
options.map.options.touchZoom = "center";
Expand Down Expand Up @@ -96,7 +98,7 @@ BlurredLocation = function BlurredLocation(options) {
function getZoom() {
return options.map.getZoom();
}

function getZoomFromCoordinates(lat, lon) {
return getZoomByPrecision(getPrecisionFromCoordinates(lat, lon));
}
Expand Down Expand Up @@ -201,15 +203,15 @@ BlurredLocation = function BlurredLocation(options) {
}

function getTileLayer(){
return tileLayer ;
return tileLayer ;
}

function drawCenterRectangle(bounds) {
var precision = getPrecision();
var interval = Math.pow(0.1, precision);
if (!bounds[1][0] || !bounds[1][1]) {
var ind = 0;
if (!bounds[1][1]) ind = 1;
if (!bounds[1][1]) ind = 1;
if (getFullLat() < 0) { bounds[0][ind] = -1*interval; bounds[1][ind] = 0; }
else { bounds[1][ind] = 1*interval; }
}
Expand All @@ -225,14 +227,14 @@ BlurredLocation = function BlurredLocation(options) {
if(isBlurred()) {
drawCenterRectangle(bounds);
disableCenterMarker();
enableCenterShade() ;
enableCenterShade() ;
}
else{
enableCenterMarker();
disableCenterShade();
}
$("#"+InterfaceOptions.latId).val(getLat()) ;
$("#"+InterfaceOptions.lngId).val(getLon()) ;
$("#"+InterfaceOptions.lngId).val(getLon()) ;
}

function setZoomByPrecision(precision) {
Expand Down Expand Up @@ -279,12 +281,12 @@ BlurredLocation = function BlurredLocation(options) {

function getDistanceMetrics() {
var haversine = require('haversine-distance');

var add = Math.pow(10,-getPrecision())

var sw = { latitude: getLat(), longitude: getLon() }
var ne = { latitude: getLat() + add, longitude: getLon() + add }

distance = haversine(sw, ne)/1000;
return truncateToPrecision(distance, 2)
}
Expand Down Expand Up @@ -318,7 +320,7 @@ BlurredLocation = function BlurredLocation(options) {
options.map.off('move', method);
}
}

toggleScales(addScaleToListener, options.scaleDisplay, options.AddScaleDisplay);
toggleScales(displayBlurryScale, options.blurryScale, options.AddBlurryScale);

Expand Down Expand Up @@ -366,4 +368,4 @@ BlurredLocation = function BlurredLocation(options) {
}
}

exports.BlurredLocation = BlurredLocation;
exports.BlurredLocation = BlurredLocation;