Skip to content

Commit

Permalink
stash..
Browse files Browse the repository at this point in the history
  • Loading branch information
trafficonese committed Sep 2, 2024
1 parent 5f12b1e commit d5d3586
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
7 changes: 3 additions & 4 deletions R/layergroupcollision.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ layergroupCollisionDependency <- function() {
}

#' Add LayerroupCollision Plugin
#' Needs data to be ordered, as frst elements will have priority.
#' @return A leaflet map object
#' @export
#'
Expand All @@ -25,8 +26,8 @@ addLayerGroupCollision <- function(
popup = NULL, popupOptions = NULL, label = NULL,
labelOptions = NULL,
className = NULL, html = NULL,
options = markerOptions(), clusterOptions = NULL,
clusterId = NULL, margin = 5, data = getMapData(map)
options = markerOptions(),
margin = 5, data = getMapData(map)
) {

map$dependencies <- c(map$dependencies, layergroupCollisionDependency())
Expand All @@ -49,9 +50,7 @@ addLayerGroupCollision <- function(
className, html,
popup, popupOptions,
label, labelOptions,
clusterId, clusterOptions,
margin
# getCrosstalkOptions(data)
) %>%
expandLimits(pts$lat, pts$lng)
}
16 changes: 10 additions & 6 deletions inst/examples/layergroupcollision_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ df <- sf::st_as_sf(atlStorms2005)
df <- suppressWarnings(st_cast(df, "POINT"))
df <- df[sample(1:nrow(df), 150, replace = F),]
# df$classes = sample(x = c("myclass1","myclass2","myclass3"), nrow(df), replace = TRUE)
df$classes = sample(x = 1:5, nrow(df), replace = TRUE)
df$classes = sample(x = 1:10, nrow(df), replace = TRUE)
df$ID <- paste0("ID_", 1:nrow(df))
df$scalerank <- sample(x = 1:5, nrow(df), replace = TRUE)
df$scalerank <- sample(x = 1:10, nrow(df), replace = TRUE)

## Ordering is important
df <- df[order(df$scalerank, decreasing = FALSE),]

ui <- fluidPage(
## CSS-style ############
Expand All @@ -29,10 +32,10 @@ ui <- fluidPage(
white-space: nowrap;
}
.city-label-0 { font-size: 20px; top: -27px; }
.city-label-1 { font-size: 19px; top: -26px; }
.city-label-2 { font-size: 18px; top: -25px; }
.city-label-3 { font-size: 17px; top: -24px; }
.city-label-0 { font-size: 30px; top: -27px; }
.city-label-1 { font-size: 25px; top: -26px; }
.city-label-2 { font-size: 24px; top: -25px; }
.city-label-3 { font-size: 22px; top: -24px; }
.city-label-4 { font-size: 16px; top: -23px; }
.city-label-5 { font-size: 15px; top: -22px; }
.city-label-6 { font-size: 14px; top: -21px; }
Expand All @@ -45,6 +48,7 @@ ui <- fluidPage(
leafletOutput("map", height = 800)
)

## Server ###########
server <- function(input, output, session) {
output$map <- renderLeaflet({
leaflet() %>%
Expand Down
12 changes: 5 additions & 7 deletions inst/htmlwidgets/lfx-layergroupcollision/layergroup-binding.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
/* global LeafletWidget, $, L, Shiny, HTMLWidgets */
LeafletWidget.methods.addLayerGroupCollision = function(
data, layerId, group, options,
className, html,
popup, popupOptions, label, labelOptions,
clusterId, clusterOptions, divOptions,
crosstalkOptions) {
className, html, popup, popupOptions,
label, labelOptions, margin) {


var collisionLayer = L.LayerGroup.collision({margin:5});
var collisionLayer = L.LayerGroup.collision({margin: margin});
console.log("collisionLayer"); console.log(collisionLayer)

// Manually parse the GeoJSON and create the L.Markers one by one
Expand All @@ -16,15 +14,15 @@ LeafletWidget.methods.addLayerGroupCollision = function(
for (var i=0; i < data.features.length; i++) {

var feat = data.features[i];
var labelClass = 'city-label city-label-' + feat.properties.scalerank;
var labelClass = 'city-label city-label-' + feat.properties.strklasse_numeric;

// Note that the markers are not interactive because MSIE on a WinPhone will take *ages*
// to run addEventListener() on them.
var marker = L.marker(L.GeoJSON.coordsToLatLng(feat.geometry.coordinates), {
icon: L.divIcon({
html:
"<span class='" + labelClass + "'>" +
feat.properties.Name +
feat.properties.strnummer +
"</span>"
})
,interactive: false // Post-0.7.3
Expand Down
4 changes: 3 additions & 1 deletion man/LayerroupCollision.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d5d3586

Please sign in to comment.