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

Conversation

mridulnagpal
Copy link
Member

No description provided.

@mridulnagpal
Copy link
Member Author

@jywarren Added a new option for our object and corresponding test. Also made a new template which works with the object. And integrated all js files to a main distribution file. Please review

@mridulnagpal
Copy link
Member Author

README updated with options section, will complete it as I write new methods.

@jywarren
Copy link
Member

Sounds great -- shall I merge this, then? Were you able to check off items on the planning issue at #1 ?

@aspriya - take a look at @mridulnagpal's work here in working with a separate self-contained library. Related, structurally, to your work on publiclab/inline-markdown-editor!

README.md Outdated

| 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

README.md Outdated
|getLat |Used to get the current latitude of the center of the map.| blurredLocation.getLat() //This would return the value in numerics|
|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|
|getSize |Used to get the current size of the map, namely the width and height.| blurredLocation.getSize() //This would return the size of the 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 looks good, and I assume it's needed for some of the other functions. But let's keep in mind what is essential API that cannot be provided by direct access to the map, such as a native Leaflet call (not sure but probably map.getSize()?) Can this be done here without a redundant wrapper, or is getSize really necessary for the API? Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it would be necessary, should I remove it then?

@mridulnagpal
Copy link
Member Author

If you could merge this I have an upcoming issue which includes file added in this PR.

src/object.js Outdated
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.

@mridulnagpal
Copy link
Member Author

@jywarren Please review made the changes.

@mridulnagpal
Copy link
Member Author

@jywarren Made changes please have a look

Gruntfile.js Outdated
@@ -32,7 +32,7 @@ module.exports = function(grunt) {
uglify: {
my_target: {
files: {
'dist/Leaflet.BlurredLocation.js': ['src/location_tags.js', 'src/locationForm.js', 'main.js']
'dist/Leaflet.BlurredLocation.js': ['src/location_tags.js', 'main.js']
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, so here, are you concatenating these files into dist/Leaflet.BlurredLocation.js, and how does this work before or after browserify compiles into dist/Leaflet.BlurredLocation.js? Don't you want Browserify to do the compiling, then uglify the output? I'm actually not that familiar with uglify - is that typically run after Browserify?

Gruntfile.js Outdated
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!

@mridulnagpal
Copy link
Member Author

mridulnagpal commented Jun 13, 2017 via email

@mridulnagpal
Copy link
Member Author

Please have a look, tried to make it like the inline editor

src/object.js Outdated
};

function geoLocateFromLatLng(lat,lng) {
var lat = document.getElementById(lat);
Copy link
Member

Choose a reason for hiding this comment

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

Can we separate the interface from the underlying code here? So, geoLocateFromLatLng would accept just two decimals, and when it's called, we do, for example, geoLocateFromLatLng($('lat').value,$('lon').value) -- that way it's more re-usable? We could also have a separate mini function like getLatLonFromElements(latEl,lonEl) or even a wrapper like geoLocateFromElements(latId,lonId) which then runs geoLocateFromLatLng() inside itself. See how this modularity can result in simpler and more re-usable code, and simpler tests too?

Copy link
Member

Choose a reason for hiding this comment

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

Also - once this big PR is merged, we can hopefully limit ourselves to each PR dealing with one isolated method, and its matching test. That way each PR can be reviewed quickly and easily by comparing the single method to the test that describes its intended use and output. Make sense?

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 sure, I was also thinking of doing it like we used to do it in the main repo, by creating different branches for different issues. Also the function I would make which accepts two decimals and pan the map to that location is already present, i.e panMap().

@jywarren
Copy link
Member

Going well! I think as we go we'll want, as much as possible, to be isolating the code that touches HTML/UI from the underlying functional code. Maybe even breaking it into subfolders like /src/ui/ and /src/core/ -- though we can do that at another time.

Also -- what's the difference between /dist/built.js and /dist/Leaflet.BlurredLocation.js?

@mridulnagpal
Copy link
Member Author

@jywarren I made the build.js file for testing purposes, once it works okay I will replace it. Currently the example uses built.js only

@mridulnagpal
Copy link
Member Author

@jywarren Just started on the lines you had suggested. Made /src/core and /src/ui and grunt compiles them accordingly. Please have a look

@jywarren
Copy link
Member

Re build.js, so they will be redundant? Can you please open an issue to merge them so we don't forget? Thanks.

@jywarren jywarren mentioned this pull request Jun 15, 2017
Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

OK -- this is really looking good, it's much more readable and i'm so happy it's compiling using browserify.

I've made a number of requests, some are renamings so that when we write tests for each method, the name of the method really clearly states the (one) thing it's supposed to do. By making methods each do just one thing, we can more easily test them.

I also asked for a couple of them to be rewired to reduce redundancy. If you can run through and make these changes today, that would be great and we can move on to the next step!

Great work and thank you! You're really learning a lot here about architecting a library and it shows!

Gruntfile.js Outdated
files: {
'dist/Leaflet.BlurredLocation.js': ['src/location_tags.js', 'src/locationForm.js', 'main.js']
src: ['node_modules/jquery/dist/jquery.min.js', 'node_modules/leaflet/dist/leaflet.js', 'src/core/object.js'],
dest: 'dist/built.js'
Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's build to 'dist/Leaflet.BlurredLocation.js' here -- thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

On it

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

setTimeout(function () {
var str = input.value;
var loc = str.split(' ').join('+');
$.getJSON("https://maps.googleapis.com/maps/api/geocode/json?address=" + loc + "&key=AIzaSyDWgc7p4WWFsO3y0MTe50vF4l4NUPcPuwE", function(data){
Copy link
Member

Choose a reason for hiding this comment

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

Can't this use the geocode function on line 26?

Copy link
Member

Choose a reason for hiding this comment

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

Also let's change the name to panMapToGeocodedLocation() maybe - since we're doing more than just geocoding, we're moving the map too.

Copy link
Member Author

Choose a reason for hiding this comment

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

On it

Copy link
Member Author

Choose a reason for hiding this comment

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

Please have a look

var lat = document.getElementById(lat);
var lng = document.getElementById(lng);

lat.addEventListener('change blur input', function() {
Copy link
Member

Choose a reason for hiding this comment

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

if you define this function as a named function like function panIfValue() {} -- just within the scope of geoLocateFromLatLng(), you can reduce code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please have a look

});
};

function geoLocateFromLatLng(lat,lng) {
Copy link
Member

Choose a reason for hiding this comment

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

Again here, maybe panMapFromLatLng()?

Copy link
Member

Choose a reason for hiding this comment

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

er, more specifically -- panMapWhenInputsChange(latId, lngId)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

map.panTo(new L.LatLng(lat, lng));
}

function getLocationFromMap(lat, lng) {
Copy link
Member

Choose a reason for hiding this comment

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

this needs to be getPlacenameFromCoordinates()

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

$.getJSON("https://maps.googleapis.com/maps/api/geocode/json?latlng="+lat+","+lng, function(data) {
if (data.results[0]) {
var address = data.results[0].formatted_address;
$("#location").val(address);
Copy link
Member

Choose a reason for hiding this comment

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

And here, we need this method to return the address, not reference specific DOM elements -- the method should just do one thing, and when we use the method, we can decide what to do with the output. That makes this much easier to test and makes for more modular code!

Copy link
Member Author

Choose a reason for hiding this comment

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

I have made it return only the location but it doesn't return the location for some reason can you please have a look

});
}

function getLocation(checkbox) {
Copy link
Member

Choose a reason for hiding this comment

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

let's call this panMapByBrowserGeocode() -- sound good?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@jywarren
Copy link
Member

So exciting -- this is really coming together and you can see the codebase a whole becoming more clear, more readable, and more organized -- great work!

@mridulnagpal
Copy link
Member Author

@jywarren Made some changes please have a look

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

OK, one more request (i promise!) -- see how I've proposed how to distinguish between internal private methods, and an external API that can be accessed like blurredLocation._methodName_() ? This helps us organize what's for internal use (internal scope) and what's "exposed" to the outside for anyone to use.


<script>
var blurredLocation = new BlurredLocation();
panMapToGeocodedLocation('geo_location');
Copy link
Member

Choose a reason for hiding this comment

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

Here, let's use this as an internal method to blurredLocation -- like blurredLocation.panMapToGeocodedLocation(...) -- i'll show you how, below. Same with panMapWhenInputsChange.

}

this.addGrid = options.addGrid;
}
Copy link
Member

Choose a reason for hiding this comment

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

If we move this to include all the below functions, we can make them all methods of blurredLocation.

Copy link
Member

Choose a reason for hiding this comment

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

move this }, i mean

}
}
}

Copy link
Member

Choose a reason for hiding this comment

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

So right here, where we move the close-curly-bracket for the constructor of function BlurredLocation(options) -- just before the } we can add:

return {
  getPlacenameFromCoordinates: getPlacenameFromCoordinates,
  panMapByBrowserGeocode: panMapByBrowserGeocode,
  //... and so on
}

That way we are returning all those functions as an API -- and they're all collected in once place so we know exactly what the outwardly promised API is. Does this make sense?

@mridulnagpal
Copy link
Member Author

@jywarren Made the methods internal please have a look

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

This is great. Please do a followup with consistent indents, but it's really great to see such progress! Congrats on this really big PR!

@jywarren jywarren merged commit 4b06a1d into publiclab:master Jun 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants