-
Notifications
You must be signed in to change notification settings - Fork 32
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
Conversation
@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 |
README updated with options section, will complete it as I write new methods. |
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 | |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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| |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
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) { |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that looks neat.
@jywarren Please review made the changes. |
@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'] |
There was a problem hiding this comment.
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'], |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
Sorry I was out of town, will look into it right now. Thanks
…On 12-Jun-2017 10:21 PM, "Jeffrey Warren" ***@***.***> wrote:
Had a chance to look at my comments? Thanks for your hard work, Mridul!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#7 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AVULlKzYfl_Sr7rqE0OVDIj9F-aK-0gbks5sDWykgaJpZM4Nlk0I>
.
|
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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().
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 Also -- what's the difference between |
@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 |
@jywarren Just started on the lines you had suggested. Made |
Re build.js, so they will be redundant? Can you please open an issue to merge them so we don't forget? Thanks. |
There was a problem hiding this 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' |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/object.js
Outdated
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){ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look
src/core/object.js
Outdated
var lat = document.getElementById(lat); | ||
var lng = document.getElementById(lng); | ||
|
||
lat.addEventListener('change blur input', function() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please have a look
src/core/object.js
Outdated
}); | ||
}; | ||
|
||
function geoLocateFromLatLng(lat,lng) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again here, maybe panMapFromLatLng()
?
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/object.js
Outdated
map.panTo(new L.LatLng(lat, lng)); | ||
} | ||
|
||
function getLocationFromMap(lat, lng) { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/core/object.js
Outdated
$.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); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
src/core/object.js
Outdated
}); | ||
} | ||
|
||
function getLocation(checkbox) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
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! |
@jywarren Made some changes please have a look |
There was a problem hiding this 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.
examples/index.html
Outdated
|
||
<script> | ||
var blurredLocation = new BlurredLocation(); | ||
panMapToGeocodedLocation('geo_location'); |
There was a problem hiding this comment.
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
.
src/core/object.js
Outdated
} | ||
|
||
this.addGrid = options.addGrid; | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this }
, i mean
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
@jywarren Made the methods internal please have a look |
There was a problem hiding this 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!
No description provided.