From a62d97e708012a6f1bfee0e0e3c4b57e19a77d54 Mon Sep 17 00:00:00 2001 From: Kyle Walker Date: Fri, 1 Nov 2024 10:14:19 -0500 Subject: [PATCH] update docs --- DESCRIPTION | 2 +- NEWS.md | 10 ++ R/controls.R | 2 +- R/layers.R | 5 +- docs/articles/getting-started.html | 2 +- .../mapbox-gl-globe-minimap-1.2.1/bundle.js | 1 + .../mapboxgl-binding-0.1.4/mapboxgl.js | 76 +++++++++- .../maplibregl-binding-0.1.4/maplibregl.js | 76 +++++++++- docs/articles/layers-overview.html | 2 +- .../mapbox-gl-globe-minimap-1.2.1/bundle.js | 1 + .../mapboxgl-binding-0.1.4/mapboxgl.js | 76 +++++++++- .../maplibregl-binding-0.1.4/maplibregl.js | 76 +++++++++- docs/articles/map-design.html | 2 +- .../mapbox-gl-globe-minimap-1.2.1/bundle.js | 1 + .../mapboxgl-binding-0.1.4/mapboxgl.js | 76 +++++++++- docs/index.html | 9 +- docs/news/index.html | 15 +- docs/pkgdown.yml | 2 +- docs/reference/add_draw_control.html | 2 +- docs/reference/add_fill_layer.html | 5 + docs/reference/add_geolocate_control.html | 142 ++++++++++++++++++ docs/reference/add_globe_minimap.html | 127 ++++++++++++++++ docs/reference/add_line_layer.html | 92 ++++++++++-- docs/reference/cluster_options.html | 10 +- docs/reference/index.html | 12 ++ docs/search.json | 2 +- docs/sitemap.xml | 2 + man/add_draw_control.Rd | 2 +- man/add_line_layer.Rd | 4 +- man/cluster_options.Rd | 2 + 30 files changed, 794 insertions(+), 42 deletions(-) create mode 100644 docs/articles/getting-started_files/mapbox-gl-globe-minimap-1.2.1/bundle.js create mode 100644 docs/articles/layers-overview_files/mapbox-gl-globe-minimap-1.2.1/bundle.js create mode 100644 docs/articles/map-design_files/mapbox-gl-globe-minimap-1.2.1/bundle.js create mode 100644 docs/reference/add_geolocate_control.html create mode 100644 docs/reference/add_globe_minimap.html diff --git a/DESCRIPTION b/DESCRIPTION index 7a54062..badbdc2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "kyle@walker-data.com", role = c("aut", "cre")) Description: Provides an interface to the 'Mapbox GL JS' () diff --git a/NEWS.md b/NEWS.md index c407b90..333d43a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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()` diff --git a/R/controls.R b/R/controls.R index 2e206d1..c3bdacb 100644 --- a/R/controls.R +++ b/R/controls.R @@ -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", diff --git a/R/layers.R b/R/layers.R index 2a75bb7..b7d093e 100644 --- a/R/layers.R +++ b/R/layers.R @@ -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. @@ -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 diff --git a/docs/articles/getting-started.html b/docs/articles/getting-started.html index bf2f5f7..9a59130 100644 --- a/docs/articles/getting-started.html +++ b/docs/articles/getting-started.html @@ -62,7 +62,7 @@ - +
diff --git a/docs/articles/getting-started_files/mapbox-gl-globe-minimap-1.2.1/bundle.js b/docs/articles/getting-started_files/mapbox-gl-globe-minimap-1.2.1/bundle.js new file mode 100644 index 0000000..e2b91ff --- /dev/null +++ b/docs/articles/getting-started_files/mapbox-gl-globe-minimap-1.2.1/bundle.js @@ -0,0 +1 @@ +var MapboxGLGlobeMinimap=function(){"use strict";class t{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const n=this._partials;let e=0;for(let r=0;r0){for(o=t[--i];i>0&&(n=o,e=t[--i],o=n+e,r=e-(o-n),!r););i>0&&(r<0&&t[i-1]<0||r>0&&t[i-1]>0)&&(e=2*r,n=o+e,e==n-o&&(o=n))}return o}}function n(t){return Array.from(function*(t){for(const n of t)yield*n}(t))}var e={value:()=>{}};function r(){for(var t,n=0,e=arguments.length,r={};n=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))),l=-1,s=a.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++l0)for(var e,r,i=new Array(e),o=0;o=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),l.hasOwnProperty(n)?{space:l[n],local:t}:t}function c(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e===a&&n.documentElement.namespaceURI===a?n.createElement(t):n.createElementNS(e,t)}}function f(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function h(t){var n=s(t);return(n.local?f:c)(n)}function p(){}function d(t){return null==t?p:function(){return this.querySelector(t)}}function v(){return[]}function g(t){return null==t?v:function(){return this.querySelectorAll(t)}}function y(t){return function(){return null==(n=t.apply(this,arguments))?[]:Array.isArray(n)?n:Array.from(n);var n}}function _(t){return function(){return this.matches(t)}}function m(t){return function(n){return n.matches(t)}}var w=Array.prototype.find;function b(){return this.firstElementChild}var x=Array.prototype.filter;function E(){return Array.from(this.children)}function S(t){return new Array(t.length)}function N(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function k(t,n,e,r,i,o){for(var u,a=0,l=n.length,s=o.length;an?1:t>=n?0:NaN}function P(t){return function(){this.removeAttribute(t)}}function j(t){return function(){this.removeAttributeNS(t.space,t.local)}}function R(t,n){return function(){this.setAttribute(t,n)}}function T(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function q(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function O(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function L(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function X(t){return function(){this.style.removeProperty(t)}}function z(t,n,e){return function(){this.style.setProperty(t,n,e)}}function D(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function H(t,n){return t.style.getPropertyValue(n)||L(t).getComputedStyle(t,null).getPropertyValue(n)}function I(t){return function(){delete this[t]}}function Y(t,n){return function(){this[t]=n}}function B(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function F(t){return t.trim().split(/^|\s+/)}function V(t){return t.classList||new G(t)}function G(t){this._node=t,this._names=F(t.getAttribute("class")||"")}function U(t,n){for(var e=V(t),r=-1,i=n.length;++r=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var gt=[null];function yt(t,n){this._groups=t,this._parents=n}function _t(){return new yt([[document.documentElement]],gt)}function mt(t){return"string"==typeof t?new yt([[document.querySelector(t)]],[document.documentElement]):new yt([[t]],gt)}function wt(t,n,e){t.prototype=n.prototype=e,e.constructor=t}function bt(t,n){var e=Object.create(t.prototype);for(var r in n)e[r]=n[r];return e}function xt(){}yt.prototype=_t.prototype={constructor:yt,select:function(t){"function"!=typeof t&&(t=d(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i=b&&(b=w+1);!(m=y[b])&&++b=0;)(r=i[o])&&(u&&4^r.compareDocumentPosition(u)&&u.parentNode.insertBefore(r,u),u=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=C);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o1?this.each((null==n?X:"function"==typeof n?D:z)(t,n,null==e?"":e)):H(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?I:"function"==typeof n?B:Y)(t,n)):this.node()[t]},classed:function(t,n){var e=F(t+"");if(arguments.length<2){for(var r=V(this.node()),i=-1,o=e.length;++i=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}}))}(t+""),u=o.length;if(!(arguments.length<2)){for(a=n?ht:ft,r=0;r>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1):8===e?Dt(n>>24&255,n>>16&255,n>>8&255,(255&n)/255):4===e?Dt(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|240&n,((15&n)<<4|15&n)/255):null):(n=$t.exec(t))?new It(n[1],n[2],n[3],1):(n=Ct.exec(t))?new It(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=Pt.exec(t))?Dt(n[1],n[2],n[3],n[4]):(n=jt.exec(t))?Dt(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=Rt.exec(t))?Ut(n[1],n[2]/100,n[3]/100,1):(n=Tt.exec(t))?Ut(n[1],n[2]/100,n[3]/100,n[4]):qt.hasOwnProperty(t)?zt(qt[t]):"transparent"===t?new It(NaN,NaN,NaN,0):null}function zt(t){return new It(t>>16&255,t>>8&255,255&t,1)}function Dt(t,n,e,r){return r<=0&&(t=n=e=NaN),new It(t,n,e,r)}function Ht(t,n,e,r){return 1===arguments.length?((i=t)instanceof xt||(i=Xt(i)),i?new It((i=i.rgb()).r,i.g,i.b,i.opacity):new It):new It(t,n,e,null==r?1:r);var i}function It(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Yt(){return`#${Gt(this.r)}${Gt(this.g)}${Gt(this.b)}`}function Bt(){const t=Ft(this.opacity);return`${1===t?"rgb(":"rgba("}${Vt(this.r)}, ${Vt(this.g)}, ${Vt(this.b)}${1===t?")":`, ${t})`}`}function Ft(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Vt(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Gt(t){return((t=Vt(t))<16?"0":"")+t.toString(16)}function Ut(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Wt(t,n,e,r)}function Zt(t){if(t instanceof Wt)return new Wt(t.h,t.s,t.l,t.opacity);if(t instanceof xt||(t=Xt(t)),!t)return new Wt;if(t instanceof Wt)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),u=NaN,a=o-i,l=(o+i)/2;return a?(u=n===o?(e-r)/a+6*(e0&&l<1?0:u,new Wt(u,a,l,t.opacity)}function Wt(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Kt(t){return(t=(t||0)%360)<0?t+360:t}function Jt(t){return Math.max(0,Math.min(1,t||0))}function Qt(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}wt(xt,Xt,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ot,formatHex:Ot,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Zt(this).formatHsl()},formatRgb:Lt,toString:Lt}),wt(It,Ht,bt(xt,{brighter(t){return t=null==t?St:Math.pow(St,t),new It(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Et:Math.pow(Et,t),new It(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new It(Vt(this.r),Vt(this.g),Vt(this.b),Ft(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Yt,formatHex:Yt,formatHex8:function(){return`#${Gt(this.r)}${Gt(this.g)}${Gt(this.b)}${Gt(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Bt,toString:Bt})),wt(Wt,(function(t,n,e,r){return 1===arguments.length?Zt(t):new Wt(t,n,e,null==r?1:r)}),bt(xt,{brighter(t){return t=null==t?St:Math.pow(St,t),new Wt(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Et:Math.pow(Et,t),new Wt(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new It(Qt(t>=240?t-240:t+120,i,r),Qt(t,i,r),Qt(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Wt(Kt(this.h),Jt(this.s),Jt(this.l),Ft(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Ft(this.opacity);return`${1===t?"hsl(":"hsla("}${Kt(this.h)}, ${100*Jt(this.s)}%, ${100*Jt(this.l)}%${1===t?")":`, ${t})`}`}}));var tn=t=>()=>t;function nn(t){return 1==(t=+t)?en:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):tn(isNaN(n)?e:n)}}function en(t,n){var e=n-t;return e?function(t,n){return function(e){return t+e*n}}(t,e):tn(isNaN(t)?n:t)}var rn=function t(n){var e=nn(n);function r(t,n){var r=e((t=Ht(t)).r,(n=Ht(n)).r),i=e(t.g,n.g),o=e(t.b,n.b),u=en(t.opacity,n.opacity);return function(n){return t.r=r(n),t.g=i(n),t.b=o(n),t.opacity=u(n),t+""}}return r.gamma=t,r}(1);function on(t,n){n||(n=[]);var e,r=t?Math.min(n.length,t.length):0,i=n.slice();return function(o){for(e=0;eo&&(i=n.slice(o,i),a[u]?a[u]+=i:a[++u]=i),(e=e[0])===(r=r[0])?a[u]?a[u]+=r:a[++u]=r:(a[++u]=null,l.push({i:u,x:ln(e,r)})),o=fn.lastIndex;return o180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:ln(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,u.rotate,a,l),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:ln(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,u.skewX,a,l),function(t,n,e,r,o,u){if(t!==e||n!==r){var a=o.push(i(o)+"scale(",null,",",null,")");u.push({i:a-4,x:ln(t,e)},{i:a-2,x:ln(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,u.scaleX,u.scaleY,a,l),o=u=null,function(t){for(var n,e=-1,r=l.length;++e=0&&n._call.call(void 0,t),n=n._next;--En}()}finally{En=0,function(){var t,n,e=mn,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:mn=n);wn=t,Xn(r)}(),An=0}}function Ln(){var t=Cn.now(),n=t-Mn;n>kn&&($n-=n,Mn=t)}function Xn(t){En||(Sn&&(Sn=clearTimeout(Sn)),t-An>24?(t<1/0&&(Sn=setTimeout(On,t-Cn.now()-$n)),Nn&&(Nn=clearInterval(Nn))):(Nn||(Mn=Cn.now(),Nn=setInterval(Ln,kn)),En=1,Pn(On)))}function zn(t,n,e){var r=new Tn;return n=null==n?0:+n,r.restart((e=>{r.stop(),t(e+n)}),n,e),r}Tn.prototype=qn.prototype={constructor:Tn,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?jn():+e)+(null==n?0:+n),this._next||wn===this||(wn?wn._next=this:mn=this,wn=this),this._call=t,this._time=e,Xn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Xn())}};var Dn=r("start","end","cancel","interrupt"),Hn=[],In=0,Yn=1,Bn=2,Fn=3,Vn=4,Gn=5,Un=6;function Zn(t,n,e,r,i,o){var u=t.__transition;if(u){if(e in u)return}else t.__transition={};!function(t,n,e){var r,i=t.__transition;function o(t){e.state=Yn,e.timer.restart(u,e.delay,e.time),e.delay<=t&&u(t-e.delay)}function u(o){var s,c,f,h;if(e.state!==Yn)return l();for(s in i)if((h=i[s]).name===e.name){if(h.state===Fn)return zn(u);h.state===Vn?(h.state=Un,h.timer.stop(),h.on.call("interrupt",t,t.__data__,h.index,h.group),delete i[s]):+sIn)throw new Error("too late; already scheduled");return e}function Kn(t,n){var e=Jn(t,n);if(e.state>Fn)throw new Error("too late; already running");return e}function Jn(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function Qn(t,n){var e,r;return function(){var i=Kn(this,t),o=i.tween;if(o!==e)for(var u=0,a=(r=e=o).length;u=0&&(t=t.slice(0,n)),!t||"start"===t}))}(n)?Wn:Kn;return function(){var u=o(this,t),a=u.on;a!==r&&(i=(r=a).copy()).on(n,e),u.on=i}}(e,t,n))},attr:function(t,n){var e=s(t),r="transform"===e?xn:ee;return this.attrTween(t,"function"==typeof n?(e.local?le:ae)(e,r,ne(this,"attr."+t,n)):null==n?(e.local?ie:re)(e):(e.local?ue:oe)(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=s(t);return this.tween(e,(r.local?se:ce)(r,n))},style:function(t,n,e){var r="transform"==(t+="")?bn:ee;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=H(this,t),u=(this.style.removeProperty(t),H(this,t));return o===u?null:o===e&&u===r?i:i=n(e=o,r=u)}}(t,r)).on("end.style."+t,ge(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,o;return function(){var u=H(this,t),a=e(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=H(this,t)),u===l?null:u===r&&l===i?o:(i=l,o=n(r=u,a))}}(t,r,ne(this,"style."+t,n))).each(function(t,n){var e,r,i,o,u="style."+n,a="end."+u;return function(){var l=Kn(this,t),s=l.on,c=null==l.value[u]?o||(o=ge(n)):void 0;s===e&&i===c||(r=(e=s).copy()).on(a,i=c),l.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,o=e+"";return function(){var u=H(this,t);return u===o?null:u===r?i:i=n(r=u,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(ne(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!=typeof t)throw new Error;return this.tween(n,function(t){var n,e;function r(){var r=t.apply(this,arguments);return r!==e&&(n=(e=r)&&function(t){return function(n){this.textContent=t.call(this,n)}}(r)),n}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=Jn(this.node(),e).tween,o=0,u=i.length;oBn&&e.state0?1:t<0?-1:0},Xe=Math.sqrt;function ze(t){return t>1?Me:t<-1?-Me:Math.asin(t)}function De(){}function He(t,n){t&&Ye.hasOwnProperty(t.type)&&Ye[t.type](t,n)}var Ie={Feature:function(t,n){He(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++rke&&(t-=Math.round(t/$e)*$e),[t,n]}function er(t){return function(n,e){return je(n+=t)>ke&&(n-=Math.round(n/$e)*$e),[n,e]}}function rr(t){var n=er(t);return n.invert=er(-t),n}function ir(t,n){var e=qe(t),r=Oe(t),i=qe(n),o=Oe(n);function u(t,n){var u=qe(n),a=qe(t)*u,l=Oe(t)*u,s=Oe(n),c=s*e+a*r;return[Te(l*i-c*o,a*e-s*r),ze(c*i+l*o)]}return u.invert=function(t,n){var u=qe(n),a=qe(t)*u,l=Oe(t)*u,s=Oe(n),c=s*i-l*o;return[Te(l*i+s*o,a*e+c*r),ze(c*e-a*r)]},u}function or(t,n){(n=Ue(n))[0]-=t,Qe(n);var e,r=(e=-n[1])>1?0:e<-1?ke:Math.acos(e);return((-n[2]<0?-r:r)+$e-Se)%$e}function ur(){var t,n=[];return{point:function(n,e,r){t.push([n,e,r])},lineStart:function(){n.push(t=[])},lineEnd:De,rejoin:function(){n.length>1&&n.push(n.pop().concat(n.shift()))},result:function(){var e=n;return n=[],t=null,e}}}function ar(t,n){return je(t[0]-n[0])=0;--o)i.point((c=s[o])[0],c[1]);else r(h.x,h.p.x,-1,i);h=h.p}s=(h=h.o).z,p=!p}while(!h.v);i.lineEnd()}}}function cr(t){if(n=t.length){for(var n,e,r=0,i=t[0];++r=0?1:-1,M=k*N,A=M>ke,$=y*E;if(s.add(Te($*k*Oe(M),_*S+$*qe(M))),a+=A?N+k*$e:N,A^v>=r^b>=r){var C=We(Ue(d),Ue(w));Qe(C);var P=We(u,C);Qe(P);var j=(A^N>=0?-1:1)*ze(P[2]);(i>j||i===j&&(C[0]||C[1]))&&(l+=A^N>=0?1:-1)}}return(a<-Se||a0){for(p||(u.polygonStart(),p=!0),u.lineStart(),t=0;t1&&2&i&&o.push(o.pop().concat(o.shift())),l.push(o.filter(pr))}return d}}function pr(t){return t.length>1}function dr(t,n){return((t=t.x)[0]<0?t[1]-Me-Se:Me-t[1])-((n=n.x)[0]<0?n[1]-Me-Se:Me-n[1])}nr.invert=nr;var vr=hr((function(){return!0}),(function(t){var n,e=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),n=1},point:function(o,u){var a=o>0?ke:-ke,l=je(o-e);je(l-ke)0?Me:-Me),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),t.point(o,r),n=0):i!==a&&l>=ke&&(je(e-i)Se?Re((Oe(n)*(o=qe(r))*Oe(e)-Oe(r)*(i=qe(n))*Oe(t))/(i*o*u)):(n+r)/2}(e,r,o,u),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),n=0),t.point(e=o,r=u),i=a},lineEnd:function(){t.lineEnd(),e=r=NaN},clean:function(){return 2-n}}}),(function(t,n,e,r){var i;if(null==t)i=e*Me,r.point(-ke,i),r.point(0,i),r.point(ke,i),r.point(ke,0),r.point(ke,-i),r.point(0,-i),r.point(-ke,-i),r.point(-ke,0),r.point(-ke,i);else if(je(t[0]-n[0])>Se){var o=t[0]0,i=je(n)>Se;function o(t,e){return qe(t)*qe(e)>n}function u(t,e,r){var i=[1,0,0],o=We(Ue(t),Ue(e)),u=Ze(o,o),a=o[0],l=u-a*a;if(!l)return!r&&t;var s=n*u/l,c=-n*a/l,f=We(i,o),h=Je(i,s);Ke(h,Je(o,c));var p=f,d=Ze(h,p),v=Ze(p,p),g=d*d-v*(Ze(h,h)-1);if(!(g<0)){var y=Xe(g),_=Je(p,(-d-y)/v);if(Ke(_,h),_=Ge(_),!r)return _;var m,w=t[0],b=e[0],x=t[1],E=e[1];b0^_[1]<(je(_[0]-w)ke^(w<=_[0]&&_[0]<=b)){var k=Je(p,(-d+y)/v);return Ke(k,h),[_,Ge(k)]}}}function a(n,e){var i=r?t:ke-t,o=0;return n<-i?o|=1:n>i&&(o|=2),e<-i?o|=4:e>i&&(o|=8),o}return hr(o,(function(t){var n,e,l,s,c;return{lineStart:function(){s=l=!1,c=1},point:function(f,h){var p,d=[f,h],v=o(f,h),g=r?v?0:a(f,h):v?a(f+(f<0?ke:-ke),h):0;if(!n&&(s=l=v)&&t.lineStart(),v!==l&&(!(p=u(n,d))||ar(n,p)||ar(d,p))&&(d[2]=1),v!==l)c=0,v?(t.lineStart(),p=u(d,n),t.point(p[0],p[1])):(p=u(n,d),t.point(p[0],p[1],2),t.lineEnd()),n=p;else if(i&&n&&r^v){var y;g&e||!(y=u(d,n,!0))||(c=0,r?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1],3)))}!v||n&&ar(n,d)||t.point(d[0],d[1]),n=d,l=v,e=g},lineEnd:function(){l&&t.lineEnd(),n=null},clean:function(){return c|(s&&l)<<1}}}),(function(n,r,i,o){!function(t,n,e,r,i,o){if(e){var u=qe(n),a=Oe(n),l=r*e;null==i?(i=n+r*$e,o=n-l/2):(i=or(u,i),o=or(u,o),(r>0?io)&&(i+=r*$e));for(var s,c=i;r>0?c>o:c0)do{l.point(0===c||3===c?t:r,c>1?i:e)}while((c=(c+u+4)%4)!==f);else l.point(o[0],o[1])}function a(n,i){return je(n[0]-t)0?0:3:je(n[0]-r)0?2:1:je(n[1]-e)0?1:0:i>0?3:2}function l(t,n){return s(t.x,n.x)}function s(t,n){var e=a(t,1),r=a(n,1);return e!==r?e-r:0===e?n[1]-t[1]:1===e?t[0]-n[0]:2===e?t[1]-n[1]:n[0]-t[0]}return function(a){var s,c,f,h,p,d,v,g,y,_,m,w=a,b=ur(),x={point:E,lineStart:function(){x.point=S,c&&c.push(f=[]);_=!0,y=!1,v=g=NaN},lineEnd:function(){s&&(S(h,p),d&&y&&b.rejoin(),s.push(b.result()));x.point=E,y&&w.lineEnd()},polygonStart:function(){w=b,s=[],c=[],m=!0},polygonEnd:function(){var e=function(){for(var n=0,e=0,r=c.length;ei&&(h-o)*(i-u)>(p-u)*(t-o)&&++n:p<=i&&(h-o)*(i-u)<(p-u)*(t-o)&&--n;return n}(),r=m&&e,o=(s=n(s)).length;(r||o)&&(a.polygonStart(),r&&(a.lineStart(),u(null,null,1,a),a.lineEnd()),o&&sr(s,l,e,u,a),a.polygonEnd());w=a,s=c=f=null}};function E(t,n){o(t,n)&&w.point(t,n)}function S(n,u){var a=o(n,u);if(c&&f.push([n,u]),_)h=n,p=u,d=a,_=!1,a&&(w.lineStart(),w.point(n,u));else if(a&&y)w.point(n,u);else{var l=[v=Math.max(_r,Math.min(yr,v)),g=Math.max(_r,Math.min(yr,g))],s=[n=Math.max(_r,Math.min(yr,n)),u=Math.max(_r,Math.min(yr,u))];!function(t,n,e,r,i,o){var u,a=t[0],l=t[1],s=0,c=1,f=n[0]-a,h=n[1]-l;if(u=e-a,f||!(u>0)){if(u/=f,f<0){if(u0){if(u>c)return;u>s&&(s=u)}if(u=i-a,f||!(u<0)){if(u/=f,f<0){if(u>c)return;u>s&&(s=u)}else if(f>0){if(u0)){if(u/=h,h<0){if(u0){if(u>c)return;u>s&&(s=u)}if(u=o-l,h||!(u<0)){if(u/=h,h<0){if(u>c)return;u>s&&(s=u)}else if(h>0){if(u0&&(t[0]=a+s*f,t[1]=l+s*h),c<1&&(n[0]=a+c*f,n[1]=l+c*h),!0}}}}}(l,s,t,e,r,i)?a&&(w.lineStart(),w.point(n,u),m=!1):(y||(w.lineStart(),w.point(l[0],l[1])),w.point(s[0],s[1]),a||w.lineEnd(),m=!1)}v=n,g=u,y=a}return x}}var wr,br,xr,Er,Sr=t=>t,Nr=new t,kr=new t,Mr={point:De,lineStart:De,lineEnd:De,polygonStart:function(){Mr.lineStart=Ar,Mr.lineEnd=Pr},polygonEnd:function(){Mr.lineStart=Mr.lineEnd=Mr.point=De,Nr.add(je(kr)),kr=new t},result:function(){var n=Nr/2;return Nr=new t,n}};function Ar(){Mr.point=$r}function $r(t,n){Mr.point=Cr,wr=xr=t,br=Er=n}function Cr(t,n){kr.add(Er*t-xr*n),xr=t,Er=n}function Pr(){Cr(wr,br)}var jr=1/0,Rr=jr,Tr=-jr,qr=Tr,Or={point:function(t,n){tTr&&(Tr=t);nqr&&(qr=n)},lineStart:De,lineEnd:De,polygonStart:De,polygonEnd:De,result:function(){var t=[[jr,Rr],[Tr,qr]];return Tr=qr=-(Rr=jr=1/0),t}};var Lr,Xr,zr,Dr,Hr=0,Ir=0,Yr=0,Br=0,Fr=0,Vr=0,Gr=0,Ur=0,Zr=0,Wr={point:Kr,lineStart:Jr,lineEnd:ni,polygonStart:function(){Wr.lineStart=ei,Wr.lineEnd=ri},polygonEnd:function(){Wr.point=Kr,Wr.lineStart=Jr,Wr.lineEnd=ni},result:function(){var t=Zr?[Gr/Zr,Ur/Zr]:Vr?[Br/Vr,Fr/Vr]:Yr?[Hr/Yr,Ir/Yr]:[NaN,NaN];return Hr=Ir=Yr=Br=Fr=Vr=Gr=Ur=Zr=0,t}};function Kr(t,n){Hr+=t,Ir+=n,++Yr}function Jr(){Wr.point=Qr}function Qr(t,n){Wr.point=ti,Kr(zr=t,Dr=n)}function ti(t,n){var e=t-zr,r=n-Dr,i=Xe(e*e+r*r);Br+=i*(zr+t)/2,Fr+=i*(Dr+n)/2,Vr+=i,Kr(zr=t,Dr=n)}function ni(){Wr.point=Kr}function ei(){Wr.point=ii}function ri(){oi(Lr,Xr)}function ii(t,n){Wr.point=oi,Kr(Lr=zr=t,Xr=Dr=n)}function oi(t,n){var e=t-zr,r=n-Dr,i=Xe(e*e+r*r);Br+=i*(zr+t)/2,Fr+=i*(Dr+n)/2,Vr+=i,Gr+=(i=Dr*t-zr*n)*(zr+t),Ur+=i*(Dr+n),Zr+=3*i,Kr(zr=t,Dr=n)}function ui(t){this._context=t}ui.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,n){switch(this._point){case 0:this._context.moveTo(t,n),this._point=1;break;case 1:this._context.lineTo(t,n);break;default:this._context.moveTo(t+this._radius,n),this._context.arc(t,n,this._radius,0,$e)}},result:De};var ai,li,si,ci,fi,hi=new t,pi={point:De,lineStart:function(){pi.point=di},lineEnd:function(){ai&&vi(li,si),pi.point=De},polygonStart:function(){ai=!0},polygonEnd:function(){ai=null},result:function(){var n=+hi;return hi=new t,n}};function di(t,n){pi.point=vi,li=ci=t,si=fi=n}function vi(t,n){ci-=t,fi-=n,hi.add(Xe(ci*ci+fi*fi)),ci=t,fi=n}let gi,yi,_i,mi;class wi{constructor(t){this._append=null==t?bi:function(t){const n=Math.floor(t);if(!(n>=0))throw new RangeError(`invalid digits: ${t}`);if(n>15)return bi;if(n!==gi){const t=10**n;gi=n,yi=function(n){let e=1;this._+=n[0];for(const r=n.length;e4*n&&v--){var w=u+h,b=a+p,x=l+d,E=Xe(w*w+b*b+x*x),S=ze(x/=E),N=je(je(x)-1)n||je((y*$+_*C)/m-.5)>.3||u*h+a*p+l*d2?t[2]%360*Pe:0,$()):[g*Ce,y*Ce,_*Ce]},M.angle=function(t){return arguments.length?(m=t%360*Pe,$()):m*Ce},M.reflectX=function(t){return arguments.length?(w=t?-1:1,$()):w<0},M.reflectY=function(t){return arguments.length?(b=t?-1:1,$()):b<0},M.precision=function(t){return arguments.length?(u=Ai(a,k=t*t),C()):Xe(k)},M.fitExtent=function(t,n){return Ni(M,t,n)},M.fitSize=function(t,n){return function(t,n,e){return Ni(t,[[0,0],n],e)}(M,t,n)},M.fitWidth=function(t,n){return function(t,n,e){return Si(t,(function(e){var r=+n,i=r/(e[1][0]-e[0][0]),o=(r-i*(e[1][0]+e[0][0]))/2,u=-i*e[0][1];t.scale(150*i).translate([o,u])}),e)}(M,t,n)},M.fitHeight=function(t,n){return function(t,n,e){return Si(t,(function(e){var r=+n,i=r/(e[1][1]-e[0][1]),o=-i*e[0][0],u=(r-i*(e[1][1]+e[0][1]))/2;t.scale(150*i).translate([o,u])}),e)}(M,t,n)},function(){return n=t.apply(this,arguments),M.invert=n.invert&&A,$()}}((function(){return t}))()}function Ri(t,n){return[qe(n)*Oe(t),Oe(n)]}function Ti(t,n,e){this.k=t,this.x=n,this.y=e}function qi(t){return t}function Oi(t,n){var e=n.id,r=n.bbox,i=null==n.properties?{}:n.properties,o=function(t,n){var e=function(t){if(null==t)return qi;var n,e,r=t.scale[0],i=t.scale[1],o=t.translate[0],u=t.translate[1];return function(t,a){a||(n=e=0);var l=2,s=t.length,c=new Array(s);for(c[0]=(n+=t[0])*r+o,c[1]=(e+=t[1])*i+u;l=0))throw new RangeError(`invalid digits: ${t}`);i=n}return null===n&&(r=new wi(i)),u},u.projection(t).digits(i).context(n)}(this.projection,r),this.globe={type:"Sphere"},this.land=(o=Li,"GeometryCollection"===(u=Li.objects.land).type?{type:"FeatureCollection",features:u.geometries.map((function(t){return Oi(o,t)}))}:Oi(o,u)),this._update(),n.on("move",this._update.bind(this))},_draw_marker:function(){const{globeSize:t,markerSize:n,markerColor:e}=this.options;mt(Xi).append("svg").attr("width",t).attr("height",t).attr("style","position: absolute; left: 0; top: 0;").append("path").attr("opacity",0).attr("d","M5.36018 5.33333C5.36018 4.59722 5.61972 3.96875 6.13881 3.44792C6.65789 2.92708 7.28426 2.66667 8.0179 2.66667C8.75154 2.66667 9.3779 2.92708 9.89699 3.44792C10.4161 3.96875 10.6756 4.59722 10.6756 5.33333C10.6756 6.06944 10.4161 6.69792 9.89699 7.21875C9.3779 7.73958 8.75154 8 8.0179 8C7.28426 8 6.65789 7.73958 6.13881 7.21875C5.61972 6.69792 5.36018 6.06944 5.36018 5.33333ZM2.70246 5.33333C2.70246 6.09028 2.81666 6.7118 3.04506 7.19792L6.824 15.2604C6.93474 15.4896 7.09911 15.6701 7.31713 15.8021C7.53515 15.934 7.76874 16 8.0179 16C8.26706 16 8.50065 15.934 8.71866 15.8021C8.93668 15.6701 9.09759 15.4896 9.20141 15.2604L12.9907 7.19792C13.2191 6.71181 13.3333 6.09028 13.3333 5.33333C13.3333 3.86111 12.8142 2.60417 11.7761 1.5625C10.7379 0.520833 9.48518 -8.13254e-07 8.0179 -9.41527e-07C6.55062 -1.0698e-06 5.29789 0.520832 4.25972 1.5625C3.22155 2.60417 2.70246 3.86111 2.70246 5.33333Z").attr("transform",`scale(${n}, ${n}), translate(${t*(1/n)/2-8}, ${t*(1/n)/2-16})`).attr("style","fill:"+e).transition().duration(100).attr("opacity",1)},_update:function(){const t=this,n=this._parentMap.getCenter();me().duration(this.initialTween?1e3:1).tween("rotate",(function(){const e=pn(t.projection.rotate(),[-n.lng,-n.lat]);return function(n){t.projection.rotate(e(n)),t.context.clearRect(0,0,t.canvas.width,t.canvas.height),t.context.fillStyle=t.options.waterColor,t.context.beginPath(),t.path(t.globe),t.context.fill(),t.context.fillStyle=t.options.landColor,t.context.beginPath(),t.path(t.land),t.context.fill()}})).on("end",(()=>{t.initialTween&&(t._draw_marker(),t.initialTween=!1)}))},_createContainer:function(t){const{globeSize:n,id:e}=this.options,r=document.createElement("div");return r.className="mapboxgl-ctrl-globe-minimap mapboxgl-ctrl",r.setAttribute("style","width: "+n+"; height: "+n+";"),r.addEventListener("contextmenu",this._preventDefault),t.getContainer().appendChild(r),""!==e&&(r.id=e),r},_preventDefault:function(t){t.preventDefault()}},window.GlobeMinimap=zi,zi}(); diff --git a/docs/articles/getting-started_files/mapboxgl-binding-0.1.4/mapboxgl.js b/docs/articles/getting-started_files/mapboxgl-binding-0.1.4/mapboxgl.js index 9a613a4..88d118b 100644 --- a/docs/articles/getting-started_files/mapboxgl-binding-0.1.4/mapboxgl.js +++ b/docs/articles/getting-started_files/mapboxgl-binding-0.1.4/mapboxgl.js @@ -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, ), ); @@ -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) { @@ -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 = { @@ -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({ @@ -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") { @@ -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) { @@ -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, ), ); @@ -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, diff --git a/docs/articles/getting-started_files/maplibregl-binding-0.1.4/maplibregl.js b/docs/articles/getting-started_files/maplibregl-binding-0.1.4/maplibregl.js index b241ed1..aa9d5e1 100644 --- a/docs/articles/getting-started_files/maplibregl-binding-0.1.4/maplibregl.js +++ b/docs/articles/getting-started_files/maplibregl-binding-0.1.4/maplibregl.js @@ -99,7 +99,7 @@ HTMLWidgets.widget({ mapMarker.setPopup( new maplibregl.Popup({ offset: 25, - }).setText(marker.popup), + }).setHTML(marker.popup), ); } @@ -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) { @@ -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 = { @@ -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({ @@ -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") { @@ -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) { @@ -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, ), ); @@ -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) => { diff --git a/docs/articles/layers-overview.html b/docs/articles/layers-overview.html index 36d6adb..473b37f 100644 --- a/docs/articles/layers-overview.html +++ b/docs/articles/layers-overview.html @@ -62,7 +62,7 @@ - +
diff --git a/docs/articles/layers-overview_files/mapbox-gl-globe-minimap-1.2.1/bundle.js b/docs/articles/layers-overview_files/mapbox-gl-globe-minimap-1.2.1/bundle.js new file mode 100644 index 0000000..e2b91ff --- /dev/null +++ b/docs/articles/layers-overview_files/mapbox-gl-globe-minimap-1.2.1/bundle.js @@ -0,0 +1 @@ +var MapboxGLGlobeMinimap=function(){"use strict";class t{constructor(){this._partials=new Float64Array(32),this._n=0}add(t){const n=this._partials;let e=0;for(let r=0;r0){for(o=t[--i];i>0&&(n=o,e=t[--i],o=n+e,r=e-(o-n),!r););i>0&&(r<0&&t[i-1]<0||r>0&&t[i-1]>0)&&(e=2*r,n=o+e,e==n-o&&(o=n))}return o}}function n(t){return Array.from(function*(t){for(const n of t)yield*n}(t))}var e={value:()=>{}};function r(){for(var t,n=0,e=arguments.length,r={};n=0&&(n=t.slice(e+1),t=t.slice(0,e)),t&&!r.hasOwnProperty(t))throw new Error("unknown type: "+t);return{type:t,name:n}}))),l=-1,s=a.length;if(!(arguments.length<2)){if(null!=n&&"function"!=typeof n)throw new Error("invalid callback: "+n);for(;++l0)for(var e,r,i=new Array(e),o=0;o=0&&"xmlns"!==(n=t.slice(0,e))&&(t=t.slice(e+1)),l.hasOwnProperty(n)?{space:l[n],local:t}:t}function c(t){return function(){var n=this.ownerDocument,e=this.namespaceURI;return e===a&&n.documentElement.namespaceURI===a?n.createElement(t):n.createElementNS(e,t)}}function f(t){return function(){return this.ownerDocument.createElementNS(t.space,t.local)}}function h(t){var n=s(t);return(n.local?f:c)(n)}function p(){}function d(t){return null==t?p:function(){return this.querySelector(t)}}function v(){return[]}function g(t){return null==t?v:function(){return this.querySelectorAll(t)}}function y(t){return function(){return null==(n=t.apply(this,arguments))?[]:Array.isArray(n)?n:Array.from(n);var n}}function _(t){return function(){return this.matches(t)}}function m(t){return function(n){return n.matches(t)}}var w=Array.prototype.find;function b(){return this.firstElementChild}var x=Array.prototype.filter;function E(){return Array.from(this.children)}function S(t){return new Array(t.length)}function N(t,n){this.ownerDocument=t.ownerDocument,this.namespaceURI=t.namespaceURI,this._next=null,this._parent=t,this.__data__=n}function k(t,n,e,r,i,o){for(var u,a=0,l=n.length,s=o.length;an?1:t>=n?0:NaN}function P(t){return function(){this.removeAttribute(t)}}function j(t){return function(){this.removeAttributeNS(t.space,t.local)}}function R(t,n){return function(){this.setAttribute(t,n)}}function T(t,n){return function(){this.setAttributeNS(t.space,t.local,n)}}function q(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttribute(t):this.setAttribute(t,e)}}function O(t,n){return function(){var e=n.apply(this,arguments);null==e?this.removeAttributeNS(t.space,t.local):this.setAttributeNS(t.space,t.local,e)}}function L(t){return t.ownerDocument&&t.ownerDocument.defaultView||t.document&&t||t.defaultView}function X(t){return function(){this.style.removeProperty(t)}}function z(t,n,e){return function(){this.style.setProperty(t,n,e)}}function D(t,n,e){return function(){var r=n.apply(this,arguments);null==r?this.style.removeProperty(t):this.style.setProperty(t,r,e)}}function H(t,n){return t.style.getPropertyValue(n)||L(t).getComputedStyle(t,null).getPropertyValue(n)}function I(t){return function(){delete this[t]}}function Y(t,n){return function(){this[t]=n}}function B(t,n){return function(){var e=n.apply(this,arguments);null==e?delete this[t]:this[t]=e}}function F(t){return t.trim().split(/^|\s+/)}function V(t){return t.classList||new G(t)}function G(t){this._node=t,this._names=F(t.getAttribute("class")||"")}function U(t,n){for(var e=V(t),r=-1,i=n.length;++r=0&&(this._names.splice(n,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(t){return this._names.indexOf(t)>=0}};var gt=[null];function yt(t,n){this._groups=t,this._parents=n}function _t(){return new yt([[document.documentElement]],gt)}function mt(t){return"string"==typeof t?new yt([[document.querySelector(t)]],[document.documentElement]):new yt([[t]],gt)}function wt(t,n,e){t.prototype=n.prototype=e,e.constructor=t}function bt(t,n){var e=Object.create(t.prototype);for(var r in n)e[r]=n[r];return e}function xt(){}yt.prototype=_t.prototype={constructor:yt,select:function(t){"function"!=typeof t&&(t=d(t));for(var n=this._groups,e=n.length,r=new Array(e),i=0;i=b&&(b=w+1);!(m=y[b])&&++b=0;)(r=i[o])&&(u&&4^r.compareDocumentPosition(u)&&u.parentNode.insertBefore(r,u),u=r);return this},sort:function(t){function n(n,e){return n&&e?t(n.__data__,e.__data__):!n-!e}t||(t=C);for(var e=this._groups,r=e.length,i=new Array(r),o=0;o1?this.each((null==n?X:"function"==typeof n?D:z)(t,n,null==e?"":e)):H(this.node(),t)},property:function(t,n){return arguments.length>1?this.each((null==n?I:"function"==typeof n?B:Y)(t,n)):this.node()[t]},classed:function(t,n){var e=F(t+"");if(arguments.length<2){for(var r=V(this.node()),i=-1,o=e.length;++i=0&&(n=t.slice(e+1),t=t.slice(0,e)),{type:t,name:n}}))}(t+""),u=o.length;if(!(arguments.length<2)){for(a=n?ht:ft,r=0;r>8&15|n>>4&240,n>>4&15|240&n,(15&n)<<4|15&n,1):8===e?Dt(n>>24&255,n>>16&255,n>>8&255,(255&n)/255):4===e?Dt(n>>12&15|n>>8&240,n>>8&15|n>>4&240,n>>4&15|240&n,((15&n)<<4|15&n)/255):null):(n=$t.exec(t))?new It(n[1],n[2],n[3],1):(n=Ct.exec(t))?new It(255*n[1]/100,255*n[2]/100,255*n[3]/100,1):(n=Pt.exec(t))?Dt(n[1],n[2],n[3],n[4]):(n=jt.exec(t))?Dt(255*n[1]/100,255*n[2]/100,255*n[3]/100,n[4]):(n=Rt.exec(t))?Ut(n[1],n[2]/100,n[3]/100,1):(n=Tt.exec(t))?Ut(n[1],n[2]/100,n[3]/100,n[4]):qt.hasOwnProperty(t)?zt(qt[t]):"transparent"===t?new It(NaN,NaN,NaN,0):null}function zt(t){return new It(t>>16&255,t>>8&255,255&t,1)}function Dt(t,n,e,r){return r<=0&&(t=n=e=NaN),new It(t,n,e,r)}function Ht(t,n,e,r){return 1===arguments.length?((i=t)instanceof xt||(i=Xt(i)),i?new It((i=i.rgb()).r,i.g,i.b,i.opacity):new It):new It(t,n,e,null==r?1:r);var i}function It(t,n,e,r){this.r=+t,this.g=+n,this.b=+e,this.opacity=+r}function Yt(){return`#${Gt(this.r)}${Gt(this.g)}${Gt(this.b)}`}function Bt(){const t=Ft(this.opacity);return`${1===t?"rgb(":"rgba("}${Vt(this.r)}, ${Vt(this.g)}, ${Vt(this.b)}${1===t?")":`, ${t})`}`}function Ft(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function Vt(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function Gt(t){return((t=Vt(t))<16?"0":"")+t.toString(16)}function Ut(t,n,e,r){return r<=0?t=n=e=NaN:e<=0||e>=1?t=n=NaN:n<=0&&(t=NaN),new Wt(t,n,e,r)}function Zt(t){if(t instanceof Wt)return new Wt(t.h,t.s,t.l,t.opacity);if(t instanceof xt||(t=Xt(t)),!t)return new Wt;if(t instanceof Wt)return t;var n=(t=t.rgb()).r/255,e=t.g/255,r=t.b/255,i=Math.min(n,e,r),o=Math.max(n,e,r),u=NaN,a=o-i,l=(o+i)/2;return a?(u=n===o?(e-r)/a+6*(e0&&l<1?0:u,new Wt(u,a,l,t.opacity)}function Wt(t,n,e,r){this.h=+t,this.s=+n,this.l=+e,this.opacity=+r}function Kt(t){return(t=(t||0)%360)<0?t+360:t}function Jt(t){return Math.max(0,Math.min(1,t||0))}function Qt(t,n,e){return 255*(t<60?n+(e-n)*t/60:t<180?e:t<240?n+(e-n)*(240-t)/60:n)}wt(xt,Xt,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Ot,formatHex:Ot,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return Zt(this).formatHsl()},formatRgb:Lt,toString:Lt}),wt(It,Ht,bt(xt,{brighter(t){return t=null==t?St:Math.pow(St,t),new It(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Et:Math.pow(Et,t),new It(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new It(Vt(this.r),Vt(this.g),Vt(this.b),Ft(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Yt,formatHex:Yt,formatHex8:function(){return`#${Gt(this.r)}${Gt(this.g)}${Gt(this.b)}${Gt(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:Bt,toString:Bt})),wt(Wt,(function(t,n,e,r){return 1===arguments.length?Zt(t):new Wt(t,n,e,null==r?1:r)}),bt(xt,{brighter(t){return t=null==t?St:Math.pow(St,t),new Wt(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Et:Math.pow(Et,t),new Wt(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),n=isNaN(t)||isNaN(this.s)?0:this.s,e=this.l,r=e+(e<.5?e:1-e)*n,i=2*e-r;return new It(Qt(t>=240?t-240:t+120,i,r),Qt(t,i,r),Qt(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new Wt(Kt(this.h),Jt(this.s),Jt(this.l),Ft(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=Ft(this.opacity);return`${1===t?"hsl(":"hsla("}${Kt(this.h)}, ${100*Jt(this.s)}%, ${100*Jt(this.l)}%${1===t?")":`, ${t})`}`}}));var tn=t=>()=>t;function nn(t){return 1==(t=+t)?en:function(n,e){return e-n?function(t,n,e){return t=Math.pow(t,e),n=Math.pow(n,e)-t,e=1/e,function(r){return Math.pow(t+r*n,e)}}(n,e,t):tn(isNaN(n)?e:n)}}function en(t,n){var e=n-t;return e?function(t,n){return function(e){return t+e*n}}(t,e):tn(isNaN(t)?n:t)}var rn=function t(n){var e=nn(n);function r(t,n){var r=e((t=Ht(t)).r,(n=Ht(n)).r),i=e(t.g,n.g),o=e(t.b,n.b),u=en(t.opacity,n.opacity);return function(n){return t.r=r(n),t.g=i(n),t.b=o(n),t.opacity=u(n),t+""}}return r.gamma=t,r}(1);function on(t,n){n||(n=[]);var e,r=t?Math.min(n.length,t.length):0,i=n.slice();return function(o){for(e=0;eo&&(i=n.slice(o,i),a[u]?a[u]+=i:a[++u]=i),(e=e[0])===(r=r[0])?a[u]?a[u]+=r:a[++u]=r:(a[++u]=null,l.push({i:u,x:ln(e,r)})),o=fn.lastIndex;return o180?n+=360:n-t>180&&(t+=360),o.push({i:e.push(i(e)+"rotate(",null,r)-2,x:ln(t,n)})):n&&e.push(i(e)+"rotate("+n+r)}(o.rotate,u.rotate,a,l),function(t,n,e,o){t!==n?o.push({i:e.push(i(e)+"skewX(",null,r)-2,x:ln(t,n)}):n&&e.push(i(e)+"skewX("+n+r)}(o.skewX,u.skewX,a,l),function(t,n,e,r,o,u){if(t!==e||n!==r){var a=o.push(i(o)+"scale(",null,",",null,")");u.push({i:a-4,x:ln(t,e)},{i:a-2,x:ln(n,r)})}else 1===e&&1===r||o.push(i(o)+"scale("+e+","+r+")")}(o.scaleX,o.scaleY,u.scaleX,u.scaleY,a,l),o=u=null,function(t){for(var n,e=-1,r=l.length;++e=0&&n._call.call(void 0,t),n=n._next;--En}()}finally{En=0,function(){var t,n,e=mn,r=1/0;for(;e;)e._call?(r>e._time&&(r=e._time),t=e,e=e._next):(n=e._next,e._next=null,e=t?t._next=n:mn=n);wn=t,Xn(r)}(),An=0}}function Ln(){var t=Cn.now(),n=t-Mn;n>kn&&($n-=n,Mn=t)}function Xn(t){En||(Sn&&(Sn=clearTimeout(Sn)),t-An>24?(t<1/0&&(Sn=setTimeout(On,t-Cn.now()-$n)),Nn&&(Nn=clearInterval(Nn))):(Nn||(Mn=Cn.now(),Nn=setInterval(Ln,kn)),En=1,Pn(On)))}function zn(t,n,e){var r=new Tn;return n=null==n?0:+n,r.restart((e=>{r.stop(),t(e+n)}),n,e),r}Tn.prototype=qn.prototype={constructor:Tn,restart:function(t,n,e){if("function"!=typeof t)throw new TypeError("callback is not a function");e=(null==e?jn():+e)+(null==n?0:+n),this._next||wn===this||(wn?wn._next=this:mn=this,wn=this),this._call=t,this._time=e,Xn()},stop:function(){this._call&&(this._call=null,this._time=1/0,Xn())}};var Dn=r("start","end","cancel","interrupt"),Hn=[],In=0,Yn=1,Bn=2,Fn=3,Vn=4,Gn=5,Un=6;function Zn(t,n,e,r,i,o){var u=t.__transition;if(u){if(e in u)return}else t.__transition={};!function(t,n,e){var r,i=t.__transition;function o(t){e.state=Yn,e.timer.restart(u,e.delay,e.time),e.delay<=t&&u(t-e.delay)}function u(o){var s,c,f,h;if(e.state!==Yn)return l();for(s in i)if((h=i[s]).name===e.name){if(h.state===Fn)return zn(u);h.state===Vn?(h.state=Un,h.timer.stop(),h.on.call("interrupt",t,t.__data__,h.index,h.group),delete i[s]):+sIn)throw new Error("too late; already scheduled");return e}function Kn(t,n){var e=Jn(t,n);if(e.state>Fn)throw new Error("too late; already running");return e}function Jn(t,n){var e=t.__transition;if(!e||!(e=e[n]))throw new Error("transition not found");return e}function Qn(t,n){var e,r;return function(){var i=Kn(this,t),o=i.tween;if(o!==e)for(var u=0,a=(r=e=o).length;u=0&&(t=t.slice(0,n)),!t||"start"===t}))}(n)?Wn:Kn;return function(){var u=o(this,t),a=u.on;a!==r&&(i=(r=a).copy()).on(n,e),u.on=i}}(e,t,n))},attr:function(t,n){var e=s(t),r="transform"===e?xn:ee;return this.attrTween(t,"function"==typeof n?(e.local?le:ae)(e,r,ne(this,"attr."+t,n)):null==n?(e.local?ie:re)(e):(e.local?ue:oe)(e,r,n))},attrTween:function(t,n){var e="attr."+t;if(arguments.length<2)return(e=this.tween(e))&&e._value;if(null==n)return this.tween(e,null);if("function"!=typeof n)throw new Error;var r=s(t);return this.tween(e,(r.local?se:ce)(r,n))},style:function(t,n,e){var r="transform"==(t+="")?bn:ee;return null==n?this.styleTween(t,function(t,n){var e,r,i;return function(){var o=H(this,t),u=(this.style.removeProperty(t),H(this,t));return o===u?null:o===e&&u===r?i:i=n(e=o,r=u)}}(t,r)).on("end.style."+t,ge(t)):"function"==typeof n?this.styleTween(t,function(t,n,e){var r,i,o;return function(){var u=H(this,t),a=e(this),l=a+"";return null==a&&(this.style.removeProperty(t),l=a=H(this,t)),u===l?null:u===r&&l===i?o:(i=l,o=n(r=u,a))}}(t,r,ne(this,"style."+t,n))).each(function(t,n){var e,r,i,o,u="style."+n,a="end."+u;return function(){var l=Kn(this,t),s=l.on,c=null==l.value[u]?o||(o=ge(n)):void 0;s===e&&i===c||(r=(e=s).copy()).on(a,i=c),l.on=r}}(this._id,t)):this.styleTween(t,function(t,n,e){var r,i,o=e+"";return function(){var u=H(this,t);return u===o?null:u===r?i:i=n(r=u,e)}}(t,r,n),e).on("end.style."+t,null)},styleTween:function(t,n,e){var r="style."+(t+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(null==n)return this.tween(r,null);if("function"!=typeof n)throw new Error;return this.tween(r,function(t,n,e){var r,i;function o(){var o=n.apply(this,arguments);return o!==i&&(r=(i=o)&&function(t,n,e){return function(r){this.style.setProperty(t,n.call(this,r),e)}}(t,o,e)),r}return o._value=n,o}(t,n,null==e?"":e))},text:function(t){return this.tween("text","function"==typeof t?function(t){return function(){var n=t(this);this.textContent=null==n?"":n}}(ne(this,"text",t)):function(t){return function(){this.textContent=t}}(null==t?"":t+""))},textTween:function(t){var n="text";if(arguments.length<1)return(n=this.tween(n))&&n._value;if(null==t)return this.tween(n,null);if("function"!=typeof t)throw new Error;return this.tween(n,function(t){var n,e;function r(){var r=t.apply(this,arguments);return r!==e&&(n=(e=r)&&function(t){return function(n){this.textContent=t.call(this,n)}}(r)),n}return r._value=t,r}(t))},remove:function(){return this.on("end.remove",function(t){return function(){var n=this.parentNode;for(var e in this.__transition)if(+e!==t)return;n&&n.removeChild(this)}}(this._id))},tween:function(t,n){var e=this._id;if(t+="",arguments.length<2){for(var r,i=Jn(this.node(),e).tween,o=0,u=i.length;oBn&&e.state0?1:t<0?-1:0},Xe=Math.sqrt;function ze(t){return t>1?Me:t<-1?-Me:Math.asin(t)}function De(){}function He(t,n){t&&Ye.hasOwnProperty(t.type)&&Ye[t.type](t,n)}var Ie={Feature:function(t,n){He(t.geometry,n)},FeatureCollection:function(t,n){for(var e=t.features,r=-1,i=e.length;++rke&&(t-=Math.round(t/$e)*$e),[t,n]}function er(t){return function(n,e){return je(n+=t)>ke&&(n-=Math.round(n/$e)*$e),[n,e]}}function rr(t){var n=er(t);return n.invert=er(-t),n}function ir(t,n){var e=qe(t),r=Oe(t),i=qe(n),o=Oe(n);function u(t,n){var u=qe(n),a=qe(t)*u,l=Oe(t)*u,s=Oe(n),c=s*e+a*r;return[Te(l*i-c*o,a*e-s*r),ze(c*i+l*o)]}return u.invert=function(t,n){var u=qe(n),a=qe(t)*u,l=Oe(t)*u,s=Oe(n),c=s*i-l*o;return[Te(l*i+s*o,a*e+c*r),ze(c*e-a*r)]},u}function or(t,n){(n=Ue(n))[0]-=t,Qe(n);var e,r=(e=-n[1])>1?0:e<-1?ke:Math.acos(e);return((-n[2]<0?-r:r)+$e-Se)%$e}function ur(){var t,n=[];return{point:function(n,e,r){t.push([n,e,r])},lineStart:function(){n.push(t=[])},lineEnd:De,rejoin:function(){n.length>1&&n.push(n.pop().concat(n.shift()))},result:function(){var e=n;return n=[],t=null,e}}}function ar(t,n){return je(t[0]-n[0])=0;--o)i.point((c=s[o])[0],c[1]);else r(h.x,h.p.x,-1,i);h=h.p}s=(h=h.o).z,p=!p}while(!h.v);i.lineEnd()}}}function cr(t){if(n=t.length){for(var n,e,r=0,i=t[0];++r=0?1:-1,M=k*N,A=M>ke,$=y*E;if(s.add(Te($*k*Oe(M),_*S+$*qe(M))),a+=A?N+k*$e:N,A^v>=r^b>=r){var C=We(Ue(d),Ue(w));Qe(C);var P=We(u,C);Qe(P);var j=(A^N>=0?-1:1)*ze(P[2]);(i>j||i===j&&(C[0]||C[1]))&&(l+=A^N>=0?1:-1)}}return(a<-Se||a0){for(p||(u.polygonStart(),p=!0),u.lineStart(),t=0;t1&&2&i&&o.push(o.pop().concat(o.shift())),l.push(o.filter(pr))}return d}}function pr(t){return t.length>1}function dr(t,n){return((t=t.x)[0]<0?t[1]-Me-Se:Me-t[1])-((n=n.x)[0]<0?n[1]-Me-Se:Me-n[1])}nr.invert=nr;var vr=hr((function(){return!0}),(function(t){var n,e=NaN,r=NaN,i=NaN;return{lineStart:function(){t.lineStart(),n=1},point:function(o,u){var a=o>0?ke:-ke,l=je(o-e);je(l-ke)0?Me:-Me),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),t.point(o,r),n=0):i!==a&&l>=ke&&(je(e-i)Se?Re((Oe(n)*(o=qe(r))*Oe(e)-Oe(r)*(i=qe(n))*Oe(t))/(i*o*u)):(n+r)/2}(e,r,o,u),t.point(i,r),t.lineEnd(),t.lineStart(),t.point(a,r),n=0),t.point(e=o,r=u),i=a},lineEnd:function(){t.lineEnd(),e=r=NaN},clean:function(){return 2-n}}}),(function(t,n,e,r){var i;if(null==t)i=e*Me,r.point(-ke,i),r.point(0,i),r.point(ke,i),r.point(ke,0),r.point(ke,-i),r.point(0,-i),r.point(-ke,-i),r.point(-ke,0),r.point(-ke,i);else if(je(t[0]-n[0])>Se){var o=t[0]0,i=je(n)>Se;function o(t,e){return qe(t)*qe(e)>n}function u(t,e,r){var i=[1,0,0],o=We(Ue(t),Ue(e)),u=Ze(o,o),a=o[0],l=u-a*a;if(!l)return!r&&t;var s=n*u/l,c=-n*a/l,f=We(i,o),h=Je(i,s);Ke(h,Je(o,c));var p=f,d=Ze(h,p),v=Ze(p,p),g=d*d-v*(Ze(h,h)-1);if(!(g<0)){var y=Xe(g),_=Je(p,(-d-y)/v);if(Ke(_,h),_=Ge(_),!r)return _;var m,w=t[0],b=e[0],x=t[1],E=e[1];b0^_[1]<(je(_[0]-w)ke^(w<=_[0]&&_[0]<=b)){var k=Je(p,(-d+y)/v);return Ke(k,h),[_,Ge(k)]}}}function a(n,e){var i=r?t:ke-t,o=0;return n<-i?o|=1:n>i&&(o|=2),e<-i?o|=4:e>i&&(o|=8),o}return hr(o,(function(t){var n,e,l,s,c;return{lineStart:function(){s=l=!1,c=1},point:function(f,h){var p,d=[f,h],v=o(f,h),g=r?v?0:a(f,h):v?a(f+(f<0?ke:-ke),h):0;if(!n&&(s=l=v)&&t.lineStart(),v!==l&&(!(p=u(n,d))||ar(n,p)||ar(d,p))&&(d[2]=1),v!==l)c=0,v?(t.lineStart(),p=u(d,n),t.point(p[0],p[1])):(p=u(n,d),t.point(p[0],p[1],2),t.lineEnd()),n=p;else if(i&&n&&r^v){var y;g&e||!(y=u(d,n,!0))||(c=0,r?(t.lineStart(),t.point(y[0][0],y[0][1]),t.point(y[1][0],y[1][1]),t.lineEnd()):(t.point(y[1][0],y[1][1]),t.lineEnd(),t.lineStart(),t.point(y[0][0],y[0][1],3)))}!v||n&&ar(n,d)||t.point(d[0],d[1]),n=d,l=v,e=g},lineEnd:function(){l&&t.lineEnd(),n=null},clean:function(){return c|(s&&l)<<1}}}),(function(n,r,i,o){!function(t,n,e,r,i,o){if(e){var u=qe(n),a=Oe(n),l=r*e;null==i?(i=n+r*$e,o=n-l/2):(i=or(u,i),o=or(u,o),(r>0?io)&&(i+=r*$e));for(var s,c=i;r>0?c>o:c0)do{l.point(0===c||3===c?t:r,c>1?i:e)}while((c=(c+u+4)%4)!==f);else l.point(o[0],o[1])}function a(n,i){return je(n[0]-t)0?0:3:je(n[0]-r)0?2:1:je(n[1]-e)0?1:0:i>0?3:2}function l(t,n){return s(t.x,n.x)}function s(t,n){var e=a(t,1),r=a(n,1);return e!==r?e-r:0===e?n[1]-t[1]:1===e?t[0]-n[0]:2===e?t[1]-n[1]:n[0]-t[0]}return function(a){var s,c,f,h,p,d,v,g,y,_,m,w=a,b=ur(),x={point:E,lineStart:function(){x.point=S,c&&c.push(f=[]);_=!0,y=!1,v=g=NaN},lineEnd:function(){s&&(S(h,p),d&&y&&b.rejoin(),s.push(b.result()));x.point=E,y&&w.lineEnd()},polygonStart:function(){w=b,s=[],c=[],m=!0},polygonEnd:function(){var e=function(){for(var n=0,e=0,r=c.length;ei&&(h-o)*(i-u)>(p-u)*(t-o)&&++n:p<=i&&(h-o)*(i-u)<(p-u)*(t-o)&&--n;return n}(),r=m&&e,o=(s=n(s)).length;(r||o)&&(a.polygonStart(),r&&(a.lineStart(),u(null,null,1,a),a.lineEnd()),o&&sr(s,l,e,u,a),a.polygonEnd());w=a,s=c=f=null}};function E(t,n){o(t,n)&&w.point(t,n)}function S(n,u){var a=o(n,u);if(c&&f.push([n,u]),_)h=n,p=u,d=a,_=!1,a&&(w.lineStart(),w.point(n,u));else if(a&&y)w.point(n,u);else{var l=[v=Math.max(_r,Math.min(yr,v)),g=Math.max(_r,Math.min(yr,g))],s=[n=Math.max(_r,Math.min(yr,n)),u=Math.max(_r,Math.min(yr,u))];!function(t,n,e,r,i,o){var u,a=t[0],l=t[1],s=0,c=1,f=n[0]-a,h=n[1]-l;if(u=e-a,f||!(u>0)){if(u/=f,f<0){if(u0){if(u>c)return;u>s&&(s=u)}if(u=i-a,f||!(u<0)){if(u/=f,f<0){if(u>c)return;u>s&&(s=u)}else if(f>0){if(u0)){if(u/=h,h<0){if(u0){if(u>c)return;u>s&&(s=u)}if(u=o-l,h||!(u<0)){if(u/=h,h<0){if(u>c)return;u>s&&(s=u)}else if(h>0){if(u0&&(t[0]=a+s*f,t[1]=l+s*h),c<1&&(n[0]=a+c*f,n[1]=l+c*h),!0}}}}}(l,s,t,e,r,i)?a&&(w.lineStart(),w.point(n,u),m=!1):(y||(w.lineStart(),w.point(l[0],l[1])),w.point(s[0],s[1]),a||w.lineEnd(),m=!1)}v=n,g=u,y=a}return x}}var wr,br,xr,Er,Sr=t=>t,Nr=new t,kr=new t,Mr={point:De,lineStart:De,lineEnd:De,polygonStart:function(){Mr.lineStart=Ar,Mr.lineEnd=Pr},polygonEnd:function(){Mr.lineStart=Mr.lineEnd=Mr.point=De,Nr.add(je(kr)),kr=new t},result:function(){var n=Nr/2;return Nr=new t,n}};function Ar(){Mr.point=$r}function $r(t,n){Mr.point=Cr,wr=xr=t,br=Er=n}function Cr(t,n){kr.add(Er*t-xr*n),xr=t,Er=n}function Pr(){Cr(wr,br)}var jr=1/0,Rr=jr,Tr=-jr,qr=Tr,Or={point:function(t,n){tTr&&(Tr=t);nqr&&(qr=n)},lineStart:De,lineEnd:De,polygonStart:De,polygonEnd:De,result:function(){var t=[[jr,Rr],[Tr,qr]];return Tr=qr=-(Rr=jr=1/0),t}};var Lr,Xr,zr,Dr,Hr=0,Ir=0,Yr=0,Br=0,Fr=0,Vr=0,Gr=0,Ur=0,Zr=0,Wr={point:Kr,lineStart:Jr,lineEnd:ni,polygonStart:function(){Wr.lineStart=ei,Wr.lineEnd=ri},polygonEnd:function(){Wr.point=Kr,Wr.lineStart=Jr,Wr.lineEnd=ni},result:function(){var t=Zr?[Gr/Zr,Ur/Zr]:Vr?[Br/Vr,Fr/Vr]:Yr?[Hr/Yr,Ir/Yr]:[NaN,NaN];return Hr=Ir=Yr=Br=Fr=Vr=Gr=Ur=Zr=0,t}};function Kr(t,n){Hr+=t,Ir+=n,++Yr}function Jr(){Wr.point=Qr}function Qr(t,n){Wr.point=ti,Kr(zr=t,Dr=n)}function ti(t,n){var e=t-zr,r=n-Dr,i=Xe(e*e+r*r);Br+=i*(zr+t)/2,Fr+=i*(Dr+n)/2,Vr+=i,Kr(zr=t,Dr=n)}function ni(){Wr.point=Kr}function ei(){Wr.point=ii}function ri(){oi(Lr,Xr)}function ii(t,n){Wr.point=oi,Kr(Lr=zr=t,Xr=Dr=n)}function oi(t,n){var e=t-zr,r=n-Dr,i=Xe(e*e+r*r);Br+=i*(zr+t)/2,Fr+=i*(Dr+n)/2,Vr+=i,Gr+=(i=Dr*t-zr*n)*(zr+t),Ur+=i*(Dr+n),Zr+=3*i,Kr(zr=t,Dr=n)}function ui(t){this._context=t}ui.prototype={_radius:4.5,pointRadius:function(t){return this._radius=t,this},polygonStart:function(){this._line=0},polygonEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){0===this._line&&this._context.closePath(),this._point=NaN},point:function(t,n){switch(this._point){case 0:this._context.moveTo(t,n),this._point=1;break;case 1:this._context.lineTo(t,n);break;default:this._context.moveTo(t+this._radius,n),this._context.arc(t,n,this._radius,0,$e)}},result:De};var ai,li,si,ci,fi,hi=new t,pi={point:De,lineStart:function(){pi.point=di},lineEnd:function(){ai&&vi(li,si),pi.point=De},polygonStart:function(){ai=!0},polygonEnd:function(){ai=null},result:function(){var n=+hi;return hi=new t,n}};function di(t,n){pi.point=vi,li=ci=t,si=fi=n}function vi(t,n){ci-=t,fi-=n,hi.add(Xe(ci*ci+fi*fi)),ci=t,fi=n}let gi,yi,_i,mi;class wi{constructor(t){this._append=null==t?bi:function(t){const n=Math.floor(t);if(!(n>=0))throw new RangeError(`invalid digits: ${t}`);if(n>15)return bi;if(n!==gi){const t=10**n;gi=n,yi=function(n){let e=1;this._+=n[0];for(const r=n.length;e4*n&&v--){var w=u+h,b=a+p,x=l+d,E=Xe(w*w+b*b+x*x),S=ze(x/=E),N=je(je(x)-1)n||je((y*$+_*C)/m-.5)>.3||u*h+a*p+l*d2?t[2]%360*Pe:0,$()):[g*Ce,y*Ce,_*Ce]},M.angle=function(t){return arguments.length?(m=t%360*Pe,$()):m*Ce},M.reflectX=function(t){return arguments.length?(w=t?-1:1,$()):w<0},M.reflectY=function(t){return arguments.length?(b=t?-1:1,$()):b<0},M.precision=function(t){return arguments.length?(u=Ai(a,k=t*t),C()):Xe(k)},M.fitExtent=function(t,n){return Ni(M,t,n)},M.fitSize=function(t,n){return function(t,n,e){return Ni(t,[[0,0],n],e)}(M,t,n)},M.fitWidth=function(t,n){return function(t,n,e){return Si(t,(function(e){var r=+n,i=r/(e[1][0]-e[0][0]),o=(r-i*(e[1][0]+e[0][0]))/2,u=-i*e[0][1];t.scale(150*i).translate([o,u])}),e)}(M,t,n)},M.fitHeight=function(t,n){return function(t,n,e){return Si(t,(function(e){var r=+n,i=r/(e[1][1]-e[0][1]),o=-i*e[0][0],u=(r-i*(e[1][1]+e[0][1]))/2;t.scale(150*i).translate([o,u])}),e)}(M,t,n)},function(){return n=t.apply(this,arguments),M.invert=n.invert&&A,$()}}((function(){return t}))()}function Ri(t,n){return[qe(n)*Oe(t),Oe(n)]}function Ti(t,n,e){this.k=t,this.x=n,this.y=e}function qi(t){return t}function Oi(t,n){var e=n.id,r=n.bbox,i=null==n.properties?{}:n.properties,o=function(t,n){var e=function(t){if(null==t)return qi;var n,e,r=t.scale[0],i=t.scale[1],o=t.translate[0],u=t.translate[1];return function(t,a){a||(n=e=0);var l=2,s=t.length,c=new Array(s);for(c[0]=(n+=t[0])*r+o,c[1]=(e+=t[1])*i+u;l=0))throw new RangeError(`invalid digits: ${t}`);i=n}return null===n&&(r=new wi(i)),u},u.projection(t).digits(i).context(n)}(this.projection,r),this.globe={type:"Sphere"},this.land=(o=Li,"GeometryCollection"===(u=Li.objects.land).type?{type:"FeatureCollection",features:u.geometries.map((function(t){return Oi(o,t)}))}:Oi(o,u)),this._update(),n.on("move",this._update.bind(this))},_draw_marker:function(){const{globeSize:t,markerSize:n,markerColor:e}=this.options;mt(Xi).append("svg").attr("width",t).attr("height",t).attr("style","position: absolute; left: 0; top: 0;").append("path").attr("opacity",0).attr("d","M5.36018 5.33333C5.36018 4.59722 5.61972 3.96875 6.13881 3.44792C6.65789 2.92708 7.28426 2.66667 8.0179 2.66667C8.75154 2.66667 9.3779 2.92708 9.89699 3.44792C10.4161 3.96875 10.6756 4.59722 10.6756 5.33333C10.6756 6.06944 10.4161 6.69792 9.89699 7.21875C9.3779 7.73958 8.75154 8 8.0179 8C7.28426 8 6.65789 7.73958 6.13881 7.21875C5.61972 6.69792 5.36018 6.06944 5.36018 5.33333ZM2.70246 5.33333C2.70246 6.09028 2.81666 6.7118 3.04506 7.19792L6.824 15.2604C6.93474 15.4896 7.09911 15.6701 7.31713 15.8021C7.53515 15.934 7.76874 16 8.0179 16C8.26706 16 8.50065 15.934 8.71866 15.8021C8.93668 15.6701 9.09759 15.4896 9.20141 15.2604L12.9907 7.19792C13.2191 6.71181 13.3333 6.09028 13.3333 5.33333C13.3333 3.86111 12.8142 2.60417 11.7761 1.5625C10.7379 0.520833 9.48518 -8.13254e-07 8.0179 -9.41527e-07C6.55062 -1.0698e-06 5.29789 0.520832 4.25972 1.5625C3.22155 2.60417 2.70246 3.86111 2.70246 5.33333Z").attr("transform",`scale(${n}, ${n}), translate(${t*(1/n)/2-8}, ${t*(1/n)/2-16})`).attr("style","fill:"+e).transition().duration(100).attr("opacity",1)},_update:function(){const t=this,n=this._parentMap.getCenter();me().duration(this.initialTween?1e3:1).tween("rotate",(function(){const e=pn(t.projection.rotate(),[-n.lng,-n.lat]);return function(n){t.projection.rotate(e(n)),t.context.clearRect(0,0,t.canvas.width,t.canvas.height),t.context.fillStyle=t.options.waterColor,t.context.beginPath(),t.path(t.globe),t.context.fill(),t.context.fillStyle=t.options.landColor,t.context.beginPath(),t.path(t.land),t.context.fill()}})).on("end",(()=>{t.initialTween&&(t._draw_marker(),t.initialTween=!1)}))},_createContainer:function(t){const{globeSize:n,id:e}=this.options,r=document.createElement("div");return r.className="mapboxgl-ctrl-globe-minimap mapboxgl-ctrl",r.setAttribute("style","width: "+n+"; height: "+n+";"),r.addEventListener("contextmenu",this._preventDefault),t.getContainer().appendChild(r),""!==e&&(r.id=e),r},_preventDefault:function(t){t.preventDefault()}},window.GlobeMinimap=zi,zi}(); diff --git a/docs/articles/layers-overview_files/mapboxgl-binding-0.1.4/mapboxgl.js b/docs/articles/layers-overview_files/mapboxgl-binding-0.1.4/mapboxgl.js index 9a613a4..88d118b 100644 --- a/docs/articles/layers-overview_files/mapboxgl-binding-0.1.4/mapboxgl.js +++ b/docs/articles/layers-overview_files/mapboxgl-binding-0.1.4/mapboxgl.js @@ -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, ), ); @@ -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) { @@ -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 = { @@ -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({ @@ -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") { @@ -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) { @@ -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, ), ); @@ -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, diff --git a/docs/articles/layers-overview_files/maplibregl-binding-0.1.4/maplibregl.js b/docs/articles/layers-overview_files/maplibregl-binding-0.1.4/maplibregl.js index b241ed1..aa9d5e1 100644 --- a/docs/articles/layers-overview_files/maplibregl-binding-0.1.4/maplibregl.js +++ b/docs/articles/layers-overview_files/maplibregl-binding-0.1.4/maplibregl.js @@ -99,7 +99,7 @@ HTMLWidgets.widget({ mapMarker.setPopup( new maplibregl.Popup({ offset: 25, - }).setText(marker.popup), + }).setHTML(marker.popup), ); } @@ -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) { @@ -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 = { @@ -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({ @@ -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") { @@ -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) { @@ -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, ), ); @@ -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) => { diff --git a/docs/articles/map-design.html b/docs/articles/map-design.html index 2599323..6509fac 100644 --- a/docs/articles/map-design.html +++ b/docs/articles/map-design.html @@ -62,7 +62,7 @@ - +
-
@@ -101,6 +102,10 @@

Argumentscircle_stroke_width

The width of the circle's stroke.

+ +
text_color
+

The color to use for labels on the cluster circles.

+