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

Size spec added and new template added using BlurredLocation object #7

Merged
merged 32 commits into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f6921cb
new example using object added
mridulnagpal May 24, 2017
d7696ad
size spec added
mridulnagpal May 24, 2017
d7a4617
small tweaks
mridulnagpal May 24, 2017
b78d5ea
README updated
mridulnagpal May 24, 2017
c29e827
README updated
mridulnagpal May 24, 2017
138b289
Update README.md
mridulnagpal May 24, 2017
d05e6ef
Update README.md
mridulnagpal May 24, 2017
ab651be
Update README.md
mridulnagpal May 24, 2017
f70fc71
README updated
mridulnagpal May 25, 2017
42c8f43
README updated
mridulnagpal May 25, 2017
0124158
README updated
mridulnagpal May 25, 2017
b7b9ac7
Size removed
mridulnagpal May 25, 2017
1a486dc
options added
mridulnagpal May 26, 2017
b62fa04
object.js changed
mridulnagpal Jun 5, 2017
51d742c
merge conflict
mridulnagpal Jun 5, 2017
4c0c13a
addgrid working
mridulnagpal Jun 5, 2017
32cb2fb
README updated
mridulnagpal Jun 5, 2017
363190f
tweaks
mridulnagpal Jun 5, 2017
8bfa37c
changes in Gruntfile
mridulnagpal Jun 13, 2017
0af7deb
js file updated
mridulnagpal Jun 13, 2017
655845e
renaming examples
mridulnagpal Jun 13, 2017
f1d554e
Test passing
mridulnagpal Jun 15, 2017
81efadc
Structuring the library
mridulnagpal Jun 15, 2017
e345dca
Restructuring dist/built.js
mridulnagpal Jun 15, 2017
0c49afb
Renaming and using geocode function inside of panMapToGeocodedLocation()
mridulnagpal Jun 15, 2017
54cb90e
Removing redundancies
mridulnagpal Jun 15, 2017
1bbab6b
Renaming function
mridulnagpal Jun 15, 2017
c289926
Little tweaks to clean code
mridulnagpal Jun 15, 2017
f5fd39a
tweaks
mridulnagpal Jun 15, 2017
9b3507f
tweaks
mridulnagpal Jun 15, 2017
d51c63c
Making global methods internal
mridulnagpal Jun 16, 2017
642ab51
Test passing
mridulnagpal Jun 16, 2017
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
13 changes: 12 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,17 @@ module.exports = function(grunt) {
options: {
jshintrc: '.jshintrc'
},
}
},

concat: {
options: {
separator: ';',
},
dist: {
src: ['node_modules/jquery/dist/jquery.min.js', 'node_modules/leaflet/dist/leaflet.js', 'src/object.js'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then concat also seems redundant with Browserify and uglify - which are we using to compile? It looks liek concat, based on line 76, but maybe we should be using Browserify, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at the Browserify example in PublicLab.Editor -- it'll be helpful! or in https://github.com/publiclab/inline-markdown-editor/blob/master/Gruntfile.js#L55 -- a bit simpler!

dest: 'dist/built.js',
},
},

});

Expand All @@ -63,4 +73,5 @@ module.exports = function(grunt) {
'browserify:dist'
]);
grunt.registerTask('test', ['jshint', 'jasmine']);
grunt.registerTask('build', ['concat']);
};
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ To set up the library first clone this repo to your local after that run 'npm in
## Creating a map object

To create a new object just call the constructor 'BlurredLocation' as shown in the following example:
(There must a div with id="map" in your html to hold the object)

// this "constructs" an instance of the library:
var object = new BlurredLocation({
Expand All @@ -43,3 +44,11 @@ To run tests, open /test.html in a browser. If you have phantomjs installed, you
You can find the installation instructions for phantomjs in its official [build documentation](http://phantomjs.org/build.html). For Ubuntu/debian based system you can follow [these instructions](https://gist.github.com/julionc/7476620) or use the script mentioned there.

To add new tests, edit the `*_spec.js` files in `/spec/javascripts/`.

## Options

| Methods | Use | Usage (Example) |
|---------|-----|-----------------|
|getLat | Used to get the current latitude of the center of the map. | blurredLocation.getLat() //This would return the value in numerics |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, am I missing getSize() here? just checking!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've added that. I think this looks good to merge now. What do you say? @jywarren

|getLon | Used to get the current latitude of the center of the map. | blurredLocation.getLon() //This would return the value in numerics |
|goTo | Takes in three parameters, namely latitude, longitude and zoom. Will set the center of map to co-ordinates input.| blurredLocation.goTo(44.51, -89.99, 13) //Will set center of map to (44.51,-89.99) with zoom set as 13 |
47 changes: 47 additions & 0 deletions dist/built.js

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions examples/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok but by using index.html you can get a shorter demo url, like https://publiclab.github.io/leaflet-blurred-location/examples/

<html lang="en">
<head>

<title>Leaflet.BlurredLocation</title>
</head>
<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">
<body>
<!-- START OF EXAMPLE -->
<div class="container" >
<div class="row" >
<div class="col-md-8">
<label class="h2 font-size-big"><input type="radio" />&nbsp;&nbsp;Add location to your content</label>
<br/><br/>
<h4 class="font-size-small">Option 1 : By Placename</h4>
</br>
<input id="geo_location" 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>
<label class="h2 font-size-big"><input type="checkbox" onchange='getLocation(this);'>&nbsp;&nbsp;Obscure my exact location</label>
</div>
<div class="col-md-4">
<h3 class="font-size-small">On a map : </h3>
<br />
<div id="map" class="leaflet-map" style="width: 400px; height: 400px;"></div>
<br/>
<h3 class="font-size-small">In Text:</h3><br/>
<input id="location" type="text" class="form-control"><br/>
</div>
</div>
</div>
<!-- END OF EXAMPLE -->
</body>
<script src="../dist/built.js"></script>


<script>
var blurredLocation = new BlurredLocation({
lat: 41.01,
lon: -85.66
});
</script>
</html>
10 changes: 7 additions & 3 deletions spec/javascripts/test_spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
var map;

describe("Basic testing", function() {
"use strict";

var fixture = loadFixtures('index.html');
map = L.map('map');

var blurredLocation = new BlurredLocation({
lat: 41.01,
Expand All @@ -27,6 +24,13 @@ describe("Basic testing", function() {
expect(blurredLocation.getLon()).toBe(-0.09);
});

it("getSize spec", function() {
var size = L.point(400,400);
expect(blurredLocation.getSize().equals(size)).toBe(true);
});



// it("geocode spec", function() {
// var geometry = blurredLocation.geocode("Buenos Aires");
// console.log(blurredLocation.getLat());
Expand Down
56 changes: 31 additions & 25 deletions src/object.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
function BlurredLocation(location) {
if(map) {
map.setView([location.lat, location.lon], 10);
this.getLat = function () {
return map.getCenter().lat;
}
this.getLon = function() {
return map.getCenter().lng;
}
this.goTo = function(lat, lon, zoom) {
map.setView([lat, lon], zoom);
}
this.geocode = function(string) {
$.ajaxSetup({async: false});
var url = "https://maps.googleapis.com/maps/api/geocode/json?address="+string.split(" ").join("+");
var temp = $.ajax({
async: false,
url: url
});
var geometry = temp.responseJSON.results[0].geometry.location;
var default_zoom = 13;
console.log(geometry.lat);
map.setView([geometry.lat, geometry.lng],default_zoom);
return geometry;
}
if(!map) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, but lets set map via the constructor options, like new BlurredImage(options) where options is like:

function BlurredLocation(options) {
  options = options || {};
  options.map = options.map || L.map('map');
  options.location = options.location || someDefault;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that looks neat.

var map = L.map('map');
L.tileLayer("https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png").addTo(map);
}
}
map.setView([location.lat, location.lon], 10);
this.getLat = function () {
return map.getCenter().lat;
}
this.getLon = function() {
return map.getCenter().lng;
}
this.goTo = function(lat, lon, zoom) {
map.setView([lat, lon], zoom);
}
this.geocode = function(string) {
var url = "https://maps.googleapis.com/maps/api/geocode/json?address="+string.split(" ").join("+");
var Blurred = $.ajax({
async: false,
url: url
});
// console.log(Object.getOwnPropertyNames(Blurred));
// console.log(Blurred.readyState);

var geometry = Blurred.responseJSON.results[0].geometry.location;
var default_zoom = 13;
// console.log(geometry.lat);
map.setView([geometry.lat, geometry.lng],default_zoom);
return geometry;
}
this.getSize = function() {
return map.getSize();
}
}
exports.BlurredLocation = BlurredLocation;