Skip to content

Conversation

bhaskarvk
Copy link
Collaborator

@jcheng5 Not for merging, only for review.

Code sample http://rpubs.com/bhaskarvk/proj4leaflet.

cc @timelyportfolio / @tim-salabim.

@bhaskarvk bhaskarvk added type: enhancement Adds a new, backwards-compatible feature in progress labels Sep 18, 2016
@bhaskarvk bhaskarvk added this to the v1.1 milestone Sep 18, 2016
@jcheng5
Copy link
Member

jcheng5 commented Sep 18, 2016

Try running git-apply this patch: https://gist.github.com/jcheng5/4167fadc93be166cae94de13dba3b029/raw/6ba0dd73c7deecc61b6e8f14a443bb69082a4955/onrender.diff

This is one approach we can take to preserving backward compatibility; it doesn't involve changing htmlwidgets, but it does make an assumption about how render hooks are stored on the htmlwidget object.

@bhaskarvk
Copy link
Collaborator Author

Will do.

Copy link
Member

@jcheng5 jcheng5 left a comment

Choose a reason for hiding this comment

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

Other than my comments, looks good. Please do make sure you test with:

  1. Shiny
    a. With alternating NULL and non-NULL maps
    b. With leafletProxy
    c. With resizing
  2. RStudio viewer
    a. Resizing
  3. R Markdown document
    a. Resizing

R/leaflet.R Outdated
#' @export
leaflet = function(data = NULL, width = NULL, height = NULL, padding = 0) {
leaflet = function(data = NULL, width = NULL, height = NULL,
padding = 0, mapOptions = list()) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd like you to rename the mapOptions argument as options (and make its default mapOptions()), and add a mapOptions function that takes crs/minzoom/maxzoom/maxbounds as arguments (center and zoom are covered by setView--or if you prefer we could have center/zoom in both places). This style is what we've used for the other functions and lets us provide autocomplete help.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed on renaming mapOptions argument to options.

But as for introducing a mapOptions() function, there's already a mapOptions function, which behaves differently than other options() function. tileOptions(), markerOptions() etc. all give back a list . But mapOptions as it's implemented now returns a map. Here's the current implementation

function (map, zoomToLimits = c("always", "first", "never"))
{
    if (is.null(map$x$options))
        map$x$options <- list()
    zoomToLimits <- match.arg(zoomToLimits)
    map$x$options$zoomToLimits <- zoomToLimits
    map
}

If I make it similar to other Options() functions it breaks compatibility.

R/leaflet.R Outdated
attr(map$x, "leafletData", exact = TRUE)
}

getMapOptions = function(map) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason you added this? It's not referenced anywhere else that I can tell.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If it's OK with you I would rather put it in, it may come handy in certain use cases, none of which are coded in as of now. Besides it makes the code around the map object symmetric.


# CRS classes supported
crsClasses <- list( 'L.CRS.EPSG3857', 'L.CRS.EPSG4326', 'L.CRS.EPSG3395',
'L.CRS.Simple', 'L.Proj.CRS', 'L.Proj.CRS.TMS' )
Copy link
Member

Choose a reason for hiding this comment

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

Just checking--we'll be able to support (at least) these CRS classes even after we move to Leaflet 1.0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, but on a side note this is not an exported list, it is used internally for checking the crsClass argument to mapOptions. So technically it can change w/o breaking API.
But just to be sure, I checked 1.0 code and these projs. are indeed supported there.


// Merge data options into defaults
let options = $.extend({ zoomToLimits: "always" }, data.options);
map = L.map(el, data.options);
Copy link
Member

Choose a reason for hiding this comment

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

Before doing this, do you have to check if there's an existing map and destroy it if so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will do. I need to read up on htmlwidgets code to truly understand what happens when, and scenarios where there will already be an instance of map.

}
});

//###HTMLWidgets.widget({
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 remove all this :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yup, I left it for the code review part, coz git diff was wanky for this portion, so easier to check new code against commented code in same file. :)

@bhaskarvk
Copy link
Collaborator Author

Closing this one, preparing a new one as per discussion.

@bhaskarvk bhaskarvk closed this Sep 22, 2016
@bhaskarvk bhaskarvk deleted the feature/plugin-Proj4Leaflet branch September 22, 2016 17:22
@bhaskarvk
Copy link
Collaborator Author

Now part of #298.

@bhaskarvk bhaskarvk added duplicate Already catalogued invalid and removed in progress labels Oct 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate Already catalogued type: enhancement Adds a new, backwards-compatible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants