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

Labels: Can display labels in 3 formats - #5

Open
rasamimalala wants to merge 3 commits into
Leaflet:masterfrom
tagip:master
Open

Labels: Can display labels in 3 formats#5
rasamimalala wants to merge 3 commits into
Leaflet:masterfrom
tagip:master

Conversation

@rasamimalala

@rasamimalala rasamimalala commented Jan 3, 2019

Copy link
Copy Markdown

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

@srappel srappel left a comment

Copy link
Copy Markdown

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.

@srappel srappel left a comment

Copy link
Copy Markdown

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

rasamimalala commented Jan 10, 2019

Copy link
Copy Markdown
Author

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

Comment thread Leaflet.Graticule.js Outdated
font: '12px Verdana',
lngLineCurved: 0,
latLineCurved: 0,
dmd: false, // Labels: Display Degrees - Decimal Minutes instead of Decimal Degrees

Copy link
Copy Markdown
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.

@rasamimalala rasamimalala Jan 14, 2019

Copy link
Copy Markdown
Author

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

Comment thread Leaflet.Graticule.js Outdated
Comment thread Leaflet.Graticule.js Outdated
if (this.options.dmd) {
// todo: format type of float
if (lng > 180) {
return this.__deg_to_dmd(360 - lng) + ' W';

Copy link
Copy Markdown
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.

Comment thread Leaflet.Graticule.js
ctx.stroke();
if (self.options.showLabel && label) {
var _yy = ll.y + (txtHeight/2)-2;
var _yy = ll.y - (txtHeight/2) + 2;

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread Leaflet.Graticule.js
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
Copy Markdown
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
Copy Markdown
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

rasamimalala commented Jan 14, 2019

Copy link
Copy Markdown
Author

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