Skip to content
This repository has been archived by the owner on Mar 28, 2022. It is now read-only.

Labels: Can display labels in 3 formats #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rasamimalala
Copy link

@rasamimalala rasamimalala commented Jan 3, 2019

Hi,
I've commited the following modification:

  • Add dmd option to show labels in Degrees - Decimal minutes instead of Decimal Degrees.
  • Modify labels placement to be more readable by users
  • Allow to specify fractional interval by adding precision option for Lat and Lon
  • Update docs

Copy link

@srappel srappel left a 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.

Copy link

@srappel srappel left a 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.

@rasamimalala
Copy link
Author

rasamimalala commented Jan 10, 2019

I solved your minor issue. However, labelling is only working for longitude which are between -360 and 360 degrees.

@@ -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
Copy link
Member

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.

Copy link
Author

@rasamimalala rasamimalala Jan 14, 2019

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 Show resolved Hide resolved
if (this.options.dmd) {
// todo: format type of float
if (lng > 180) {
return this.__deg_to_dmd(360 - lng) + ' W';
Copy link
Member

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;
Copy link
Member

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.

Copy link
Author

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);
Copy link
Member

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.

Copy link
Author

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.

@rasamimalala
Copy link
Author

rasamimalala commented Jan 14, 2019

I make a new commit according to your changes request.

@rasamimalala rasamimalala changed the title Labels: Can display labels in Degrees - Decimal minutes Labels: Can display labels in 3 formats Jan 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants