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

write tests that assert the markers are shown or hidden as in the new example code #52

Merged
merged 15 commits into from
Apr 2, 2019
Merged
14 changes: 12 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,18 @@ module.exports = function(grunt) {
},

jasmine: {
src: "src/client/js/*.js",
src: "dist/*.js",
options: {
specs: "spec/javascripts/*spec.js",
vendor: ['node_modules/jquery/dist/jquery.js','dist/Leaflet.BlurredLocationDisplay.js','node_modules/jasmine-jquery/lib/jasmine-jquery.js'],
vendor: [
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.min.js',
'node_modules/jasmine-jquery/lib/jasmine-jquery.js' ,
'node_modules/jasmine-ajax/lib/mock-ajax.js',
'https://maps.googleapis.com/maps/api/js?libraries=places&language=en&key=AIzaSyDWgc7p4WWFsO3y0MTe50vF4l4NUPcPuwE',
'node_modules/leaflet/dist/leaflet-src.js',
'node_modules/leaflet-blurred-location/dist/Leaflet.BlurredLocation.js' ,
Copy link
Member

Choose a reason for hiding this comment

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

]
}
},

Expand All @@ -50,9 +58,11 @@ module.exports = function(grunt) {
});

/* Default (development): Watch files and build on change. */
grunt.registerTask("default", ["watch", "jasmine"]);
grunt.registerTask('build', [
'browserify:dist'
]);
grunt.registerTask('test', ['jshint', 'jasmine']);
grunt.registerTask('build', ['browserify']);
grunt.loadNpmTasks("grunt-contrib-jasmine");
};
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ var options_display = {
}
```

##### Changing the zoom levels range where 'x' precision marker should be visible :

```js
// [lower zoom level , upper zoom level , >= precision allowed]
zoom_filter = [[0,5,0] , [5,6,2] , [8,10,4] , [11,18,5]] ;
```
The first number signifies the lower zoom level .

The second number signifies the upper zoom level .

The last number signifies that all markers having precision greater than equal to this number should be shown .

The default zoom level filter array is :
```js
[[0,5,0] , [5,6,2] , [8,10,4] , [11,18,5]] ;
```
##### Using external API to fetch data

```js
Expand Down
90 changes: 45 additions & 45 deletions dist/Leaflet.BlurredLocationDisplay.js

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

6 changes: 5 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ <h4><b>By entering co-ordinates</b></h4>
[24.123456 , 78.123456],
[25.123456 , 77.123456]];

// [lower zoom level , upper zoom level , >= precision allowed]
zoom_filter = [[0,5,0] , [5,6,2] , [8,10,4] , [11,18,5]] ;

var options_display = {
blurredLocation: BlurredLocation,
locations: locations,
source_url: "https://publiclab.org/api/srch/nearbyPeople",
JSONparser: JSONparser
JSONparser: JSONparser,
zoom_filter: zoom_filter
}

var blurredLocationDisplay = new BlurredLocationDisplay(options_display);
Expand Down
125 changes: 125 additions & 0 deletions spec/javascripts/fixtures/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<!DOCTYPE html>
<html lang="en">
<head>

<title>Leaflet.BlurredLocationDisplay</title>

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

Choose a reason for hiding this comment

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

So i think you may want to load these in the Gruntfile on these lines: https://github.com/publiclab/leaflet-blurred-location-display/pull/52/files#diff-35b4a816e0441e6a375cd925af50752cR35

because they won't be loaded from this file until you load the fixture. And some of the tests you may not actually want the HTML fixture data, but just to test basic methods in the JS lib.

See for example:

https://github.com/publiclab/leaflet-blurred-location/blob/4f452d5cc486ac320fa168eeabbb46bedb1b8378/spec/javascripts/fixtures/index.html#L5-L8


</head>

<body>

<div class="container" >

<h1>Leaflet BlurredLocationDisplay <small>| by <a href="">Public Lab</a></small></h1>

<p>This page shows how different markers are shown according to their precision at different zoom levels .</p>

<hr />

<p>
<h3>1.) At zoom level = 5 , all 7 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Red"> [23.1 , 77.1] </span>, <br>
<span style="color: Red"> [20.1 , 76.1] </span>, <br>
<span style="color: Green"> [21.111 , 76.111] </span>,<br>
<span style="color: Green">[22.111 , 78.111]</span>,<br>
<span style="color: Black">[23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map1" class="leaflet-map" style="width: 100%; height: 400px;"></div>
<br><br>
<h3>2.) At zoom level = 6 , 5 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Green"> [21.111 , 76.111]</span>,<br>
<span style="color: Green"> [22.111 , 78.111]</span>,<br>
<span style="color: Black"> [23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map2" class="leaflet-map" style="width: 100%; height: 400px;"></div>
<br><br>
<h3>3.) At zoom level = 8 , 3 markers are shown : </h3>
<div style="background-color: #d6dfe0;">
<span style="color: Black"> [23.1234 , 76.1234]</span>,<br>
<span style="color: Yellow"> [24.123456 , 78.123456]</span>,<br>
<span style="color: Yellow"> [25.123456 , 77.123456]</span>
</div>
<div id="map3" class="leaflet-map" style="width: 100%; height: 400px;"></div>

<br />

</div>

<script>
var options1 = {
mapID: 'map1'
}
var options2 = {
mapID: 'map2'
}
var options3 = {
mapID: 'map3'
}


var BlurredLocation1 = new BlurredLocation(options1) ;

var BlurredLocation2 = new BlurredLocation(options2) ;

var BlurredLocation3 = new BlurredLocation(options3) ;

/*
zoom_level <= 5 : 7 Markers
zoom_level between 6 and 7 : 5 Markers
zoom_level between 8 and 10 : 3 Markers
zoom_level >= 11 : 2 Markers
*/

var locations = [[23.1 , 77.1],
[20.1 , 76.1],
[21.111 , 76.111],
[22.111 , 78.111],
[23.1234 , 76.1234],
[24.123456 , 78.123456],
[25.123456 , 77.123456]];

var options_display1 = {
blurredLocation: BlurredLocation1,
locations: locations
}
var options_display2 = {
blurredLocation: BlurredLocation2,
locations: locations
}
var options_display3 = {
blurredLocation: BlurredLocation3,
locations: locations
}

var blurredLocationDisplay1 = new BlurredLocationDisplay(options_display1);
var blurredLocationDisplay2 = new BlurredLocationDisplay(options_display2);
var blurredLocationDisplay3 = new BlurredLocationDisplay(options_display3);

BlurredLocation1.map.setView([23,77] , 5) ;
BlurredLocation2.map.setView([23,77] , 6) ;
BlurredLocation3.map.setView([24.23694700391752, 76.89880371093751] , 8) ;
</script>

<style>
html { background: #f8f8f8; margin-bottom: 100px;}
body { background: none; }
</style>


</body>
</html>
Loading