Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed Nov 1, 2024
1 parent 28a8316 commit a62d97e
Show file tree
Hide file tree
Showing 30 changed files with 794 additions and 42 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mapgl
Title: Interactive Maps with 'Mapbox GL JS' and 'MapLibre GL JS'
Version: 0.1.4
Date: 2024-10-29
Date: 2024-11-01
Authors@R:
person(given = "Kyle", family = "Walker", email = "[email protected]", role = c("aut", "cre"))
Description: Provides an interface to the 'Mapbox GL JS' (<https://docs.mapbox.com/mapbox-gl-js/guides>)
Expand Down
10 changes: 10 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# mapgl 0.1.4

* `add_image()` allows you to add your own image to the map's sprite for use as an icon / symbol layer
* `add_geolocate_control()` adds a Geolocate control to the map
* `add_globe_minimap()` adds a mini globe overview map that tracks how your map moves around the globe
* Support for multiple legends with the argument `add = TRUE`
* A `move_layer()` function that gives you more fine-grained control over layer ordering in a Shiny session
* Various bug fixes and performance improvements.


# mapgl 0.1.3

* Geocoding support for Mapbox and MapLibre maps added with `add_geocoder_control()`
Expand Down
2 changes: 1 addition & 1 deletion R/controls.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ add_scale_control <- function(map,
#' center = c(-74.50, 40),
#' zoom = 9
#' ) |>
#' add_draw_control(position = "top-left", freehand = TRUE, simplify_freehand = TRUE, orientation = "horizontal")
#' add_draw_control()
#' }
add_draw_control <- function(map,
position = "top-left",
Expand Down
5 changes: 3 additions & 2 deletions R/layers.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ add_fill_layer <- function(map,
#' @param line_translate_anchor Controls the frame of reference for `line-translate`.
#' @param line_trim_color The color to be used for rendering the trimmed line section.
#' @param line_trim_fade_range The fade range for the trim-start and trim-end points.
#' @param line_trim_offset The line part between [trim-start, trim-end] will be
#' painted using line-trim-color.
#' @param line_trim_offset The line part between `c(trim_start, trim_end)` will be
#' painted using `line_trim_color`.
#' @param line_width Stroke thickness.
#' @param line_z_offset Vertical offset from ground, in meters.
#' @param visibility Whether this layer is displayed.
Expand Down Expand Up @@ -628,6 +628,7 @@ add_fill_extrusion_layer <- function(map,
#' @param circle_stroke_color The color of the circle's stroke.
#' @param circle_stroke_opacity The opacity of the circle's stroke.
#' @param circle_stroke_width The width of the circle's stroke.
#' @param text_color The color to use for labels on the cluster circles.
#'
#' @return A list of cluster options.
#' @export
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/getting-started.html

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ HTMLWidgets.widget({

if (marker.popup) {
mapMarker.setPopup(
new mapboxgl.Popup({ offset: 25 }).setText(
new mapboxgl.Popup({ offset: 25 }).setHTML(
marker.popup,
),
);
Expand Down Expand Up @@ -271,6 +271,17 @@ HTMLWidgets.widget({
.setHTML(description)
.addTo(map);
});

// Change cursor to pointer when hovering over the layer
map.on("mouseenter", layer.id, function () {
map.getCanvas().style.cursor =
"pointer";
});

// Change cursor back to default when leaving the layer
map.on("mouseleave", layer.id, function () {
map.getCanvas().style.cursor = "";
});
}

if (layer.tooltip) {
Expand Down Expand Up @@ -461,6 +472,22 @@ HTMLWidgets.widget({
map.controls.push(scaleControl);
}

// Add globe minimap if enabled
if (x.globe_minimap && x.globe_minimap.enabled) {
const globeMinimapOptions = {
globeSize: x.globe_minimap.globe_size,
landColor: x.globe_minimap.land_color,
waterColor: x.globe_minimap.water_color,
markerColor: x.globe_minimap.marker_color,
markerSize: x.globe_minimap.marker_size,
};
const globeMinimap = new GlobeMinimap(
globeMinimapOptions,
);
map.addControl(globeMinimap, x.globe_minimap.position);
map.controls.push(globeMinimap);
}

// Add geocoder control if enabled
if (x.geocoder_control) {
const geocoderOptions = {
Expand Down Expand Up @@ -588,6 +615,26 @@ HTMLWidgets.widget({
map.controls.push(fullscreen);
}

// Add geolocate control if enabled
if (x.geolocate_control) {
const geolocate = new mapboxgl.GeolocateControl({
positionOptions:
x.geolocate_control.positionOptions,
trackUserLocation:
x.geolocate_control.trackUserLocation,
showAccuracyCircle:
x.geolocate_control.showAccuracyCircle,
showUserLocation:
x.geolocate_control.showUserLocation,
showUserHeading:
x.geolocate_control.showUserHeading,
fitBoundsOptions:
x.geolocate_control.fitBoundsOptions,
});
map.addControl(geolocate, x.geolocate_control.position);
map.controls.push(geolocate);
}

// Add navigation control if enabled
if (x.navigation_control) {
const nav = new mapboxgl.NavigationControl({
Expand Down Expand Up @@ -891,7 +938,9 @@ HTMLWidgets.widget({

if (HTMLWidgets.shinyMode) {
Shiny.addCustomMessageHandler("mapboxgl-proxy", function (data) {
var map = HTMLWidgets.find("#" + data.id).getMap();
var widget = HTMLWidgets.find("#" + data.id);
if (!widget) return;
var map = widget.getMap();
if (map) {
var message = data.message;
if (message.type === "set_filter") {
Expand Down Expand Up @@ -962,6 +1011,16 @@ if (HTMLWidgets.shinyMode) {
.setHTML(description)
.addTo(map);
});

// Change cursor to pointer when hovering over the layer
map.on("mouseenter", message.layer.id, function () {
map.getCanvas().style.cursor = "pointer";
});

// Change cursor back to default when leaving the layer
map.on("mouseleave", message.layer.id, function () {
map.getCanvas().style.cursor = "";
});
}

if (message.layer.tooltip) {
Expand Down Expand Up @@ -1337,7 +1396,7 @@ if (HTMLWidgets.shinyMode) {

if (marker.popup) {
mapMarker.setPopup(
new mapboxgl.Popup({ offset: 25 }).setText(
new mapboxgl.Popup({ offset: 25 }).setHTML(
marker.popup,
),
);
Expand Down Expand Up @@ -1386,6 +1445,17 @@ if (HTMLWidgets.shinyMode) {
});
map.addControl(scaleControl, message.options.position);
map.controls.push(scaleControl);
} else if (message.type === "add_geolocate_control") {
const geolocate = new mapboxgl.GeolocateControl({
positionOptions: message.options.positionOptions,
trackUserLocation: message.options.trackUserLocation,
showAccuracyCircle: message.options.showAccuracyCircle,
showUserLocation: message.options.showUserLocation,
showUserHeading: message.options.showUserHeading,
fitBoundsOptions: message.options.fitBoundsOptions,
});
map.addControl(geolocate, message.options.position);
map.controls.push(geolocate);
} else if (message.type === "add_geocoder_control") {
const geocoderOptions = {
accessToken: mapboxgl.accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ HTMLWidgets.widget({
mapMarker.setPopup(
new maplibregl.Popup({
offset: 25,
}).setText(marker.popup),
}).setHTML(marker.popup),
);
}

Expand Down Expand Up @@ -269,6 +269,17 @@ HTMLWidgets.widget({
.setHTML(description)
.addTo(map);
});

// Change cursor to pointer when hovering over the layer
map.on("mouseenter", layer.id, function () {
map.getCanvas().style.cursor =
"pointer";
});

// Change cursor back to default when leaving the layer
map.on("mouseleave", layer.id, function () {
map.getCanvas().style.cursor = "";
});
}

if (layer.tooltip) {
Expand Down Expand Up @@ -446,6 +457,22 @@ HTMLWidgets.widget({
map.controls.push(scaleControl);
}

// Add globe minimap if enabled
if (x.globe_minimap && x.globe_minimap.enabled) {
const globeMinimapOptions = {
globeSize: x.globe_minimap.globe_size,
landColor: x.globe_minimap.land_color,
waterColor: x.globe_minimap.water_color,
markerColor: x.globe_minimap.marker_color,
markerSize: x.globe_minimap.marker_size,
};
const globeMinimap = new GlobeMinimap(
globeMinimapOptions,
);
map.addControl(globeMinimap, x.globe_minimap.position);
map.controls.push(globeMinimap);
}

// Add geocoder control if enabled
if (x.geocoder_control) {
const geocoderApi = {
Expand Down Expand Up @@ -628,6 +655,26 @@ HTMLWidgets.widget({
map.controls.push(fullscreen);
}

// Add geolocate control if enabled
if (x.geolocate_control) {
const geolocate = new maplibregl.GeolocateControl({
positionOptions:
x.geolocate_control.positionOptions,
trackUserLocation:
x.geolocate_control.trackUserLocation,
showAccuracyCircle:
x.geolocate_control.showAccuracyCircle,
showUserLocation:
x.geolocate_control.showUserLocation,
showUserHeading:
x.geolocate_control.showUserHeading,
fitBoundsOptions:
x.geolocate_control.fitBoundsOptions,
});
map.addControl(geolocate, x.geolocate_control.position);
map.controls.push(geolocate);
}

// Add navigation control if enabled
if (x.navigation_control) {
const nav = new maplibregl.NavigationControl({
Expand Down Expand Up @@ -919,7 +966,9 @@ HTMLWidgets.widget({

if (HTMLWidgets.shinyMode) {
Shiny.addCustomMessageHandler("maplibre-proxy", function (data) {
var map = HTMLWidgets.find("#" + data.id).getMap();
var widget = HTMLWidgets.find("#" + data.id);
if (!widget) return;
var map = widget.getMap();
if (map) {
var message = data.message;
if (message.type === "set_filter") {
Expand All @@ -944,6 +993,16 @@ if (HTMLWidgets.shinyMode) {
.setHTML(description)
.addTo(map);
});

// Change cursor to pointer when hovering over the layer
map.on("mouseenter", message.layer.id, function () {
map.getCanvas().style.cursor = "pointer";
});

// Change cursor back to default when leaving the layer
map.on("mouseleave", message.layer.id, function () {
map.getCanvas().style.cursor = "";
});
}

if (message.layer.tooltip) {
Expand Down Expand Up @@ -1254,7 +1313,7 @@ if (HTMLWidgets.shinyMode) {

if (marker.popup) {
mapMarker.setPopup(
new maplibregl.Popup({ offset: 25 }).setText(
new maplibregl.Popup({ offset: 25 }).setHTML(
marker.popup,
),
);
Expand Down Expand Up @@ -1372,6 +1431,17 @@ if (HTMLWidgets.shinyMode) {
resetContainer.parentNode.removeChild(resetContainer);
},
});
} else if (message.type === "add_geolocate_control") {
const geolocate = new maplibregl.GeolocateControl({
positionOptions: message.options.positionOptions,
trackUserLocation: message.options.trackUserLocation,
showAccuracyCircle: message.options.showAccuracyCircle,
showUserLocation: message.options.showUserLocation,
showUserHeading: message.options.showUserHeading,
fitBoundsOptions: message.options.fitBoundsOptions,
});
map.addControl(geolocate, message.options.position);
map.controls.push(geolocate);
} else if (message.type === "add_geocoder_control") {
const geocoderApi = {
forwardGeocode: async (config) => {
Expand Down
2 changes: 1 addition & 1 deletion docs/articles/layers-overview.html

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

Large diffs are not rendered by default.

Loading

0 comments on commit a62d97e

Please sign in to comment.