-
Notifications
You must be signed in to change notification settings - Fork 17
Labels: Can display labels in 3 formats #5
base: master
Are you sure you want to change the base?
Conversation
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.
Wow this cleans up the formatting a lot! I like the text justified to the side of the lines. Decimal minutes makes more sense than trying to cram minutes and seconds in there like I was.
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'm still having a minor issue that when I scroll all the way to the west and reach the 180th meridian, the numbers to the west of it are labeled as W when they are in the Eastern Hemisphere. The same happens scrolling to 180 to the East.
I solved your minor issue. However, labelling is only working for longitude which are between -360 and 360 degrees. |
Leaflet.Graticule.js
Outdated
@@ -13,6 +13,8 @@ L.LatLngGraticule = L.Layer.extend({ | |||
font: '12px Verdana', | |||
lngLineCurved: 0, | |||
latLineCurved: 0, | |||
dmd: false, // Labels: Display Degrees - Decimal Minutes instead of Decimal Degrees |
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 would like a format
options instead (with dmd
as possible value) instead. There are more than 2 coordinate formats.
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'll put an option named format
which can have one of the following values:
- dd: Decimal Degrees (default value)
- dmd: Degrees - Decimal Minutes
- dms: Degrees - Minutes - Seconds
Leaflet.Graticule.js
Outdated
if (this.options.dmd) { | ||
// todo: format type of float | ||
if (lng > 180) { | ||
return this.__deg_to_dmd(360 - lng) + ' W'; |
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.
Use modulus 360 (i.e. lng % 360
) instead.
Or better yet, use wrapLatLng()
of the map's CRS. (i.e this._map.options.crs.warpLatLng(latlng)
) on the appropriate place, or even this._map.options.crs.warpLatLng([0, lng]).lng
. That should care of maps with non-default CRSs.
@@ -419,7 +480,7 @@ L.LatLngGraticule = L.Layer.extend({ | |||
ctx.lineTo(rr.x-1, rr.y); | |||
ctx.stroke(); | |||
if (self.options.showLabel && label) { | |||
var _yy = ll.y + (txtHeight/2)-2; | |||
var _yy = ll.y - (txtHeight/2) + 2; |
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.
Why this change? Seems unrelated at first sight.
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 change is about labels placements.
@@ -490,8 +551,8 @@ L.LatLngGraticule = L.Layer.extend({ | |||
ctx.stroke(); | |||
|
|||
if (self.options.showLabel && label) { | |||
ctx.fillText(lngstr, tt.x - (txtWidth/2), txtHeight+1); | |||
ctx.fillText(lngstr, bb.x - (txtWidth/2), hh-3); | |||
ctx.fillText(lngstr, tt.x + 3, txtHeight+1); |
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.
Why this change? Seems unrelated at first sight.
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 change is about labels placements.
I make a new commit according to your changes request. |
Hi,
I've commited the following modification: