├── .Rbuildignore ├── .github ├── .gitignore └── workflows │ └── R-CMD-check.yaml ├── .gitignore ├── .travis.yml ├── DESCRIPTION ├── LICENSE.md ├── NAMESPACE ├── R ├── basemap.R ├── chunkerize.R ├── codeinc.R ├── genmeths.R ├── legend.R ├── rleafmap-package.R ├── serial.R ├── splayer.R ├── toGeoJSON.R ├── toJS.R ├── ui.R ├── utilities.R └── writemap.R ├── README.md ├── _data ├── _dataicons.js ├── _datalines.js ├── _datapoints.js └── _datapolygons.js ├── _map.html ├── data ├── campsites.RData ├── hotels.RData └── velov.RData ├── man ├── basemap.Rd ├── bmCredit.Rd ├── bmServer.Rd ├── bmSource.Rd ├── campsites.Rd ├── chunkerize.Rd ├── col2hexa.Rd ├── hotels.Rd ├── layerLegend.Rd ├── printspl.Rd ├── rleafmap.Rd ├── spLayer.Rd ├── spLayer.SpatialGridDataFrame.Rd ├── spLayer.SpatialLines.Rd ├── spLayer.SpatialPoints.Rd ├── spLayer.SpatialPolygons.Rd ├── spLayer.default.Rd ├── spLayerControl.Rd ├── summarymaplayer.Rd ├── toGeoJSON.Rd ├── toJS.Rd ├── ui.Rd ├── uiJS.Rd ├── velov.Rd └── writeMap.Rd └── rleafmap.Rproj /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ignore 4 | ^\.travis\.yml$ 5 | LICENSE.md 6 | ^\.github$ 7 | _data 8 | _map.html 9 | cran-comments.md 10 | ^CRAN-SUBMISSION$ 11 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | branches: [main, master] 8 | 9 | name: R-CMD-check 10 | 11 | jobs: 12 | R-CMD-check: 13 | runs-on: ${{ matrix.config.os }} 14 | 15 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 16 | 17 | strategy: 18 | fail-fast: false 19 | matrix: 20 | config: 21 | - {os: macos-latest, r: 'release'} 22 | - {os: windows-latest, r: 'release'} 23 | - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} 24 | - {os: ubuntu-latest, r: 'release'} 25 | - {os: ubuntu-latest, r: 'oldrel-1'} 26 | 27 | env: 28 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 29 | R_KEEP_PKG_SOURCE: yes 30 | 31 | steps: 32 | - uses: actions/checkout@v3 33 | 34 | - uses: r-lib/actions/setup-pandoc@v2 35 | 36 | - uses: r-lib/actions/setup-r@v2 37 | with: 38 | r-version: ${{ matrix.config.r }} 39 | http-user-agent: ${{ matrix.config.http-user-agent }} 40 | use-public-rspm: true 41 | 42 | - uses: r-lib/actions/setup-r-dependencies@v2 43 | with: 44 | extra-packages: any::rcmdcheck 45 | needs: check 46 | 47 | - uses: r-lib/actions/check-r-package@v2 48 | with: 49 | upload-snapshots: true 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | cran-comments.md 5 | CRAN-SUBMISSION 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # http://docs.travis-ci.com/user/languages/r/ 2 | language: r 3 | 4 | sudo: required 5 | warnings_are_errors: true 6 | 7 | 8 | env: 9 | global: 10 | - NOT_CRAN=true 11 | 12 | before_install: echo "options(repos = c(CRAN='http://cran.rstudio.com'))" > ~/.Rprofile 13 | 14 | r_binary_packages: 15 | - sp 16 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: rleafmap 2 | Title: Interactive Maps with R and Leaflet 3 | Description: Display spatial data with interactive maps powered by the open- 4 | source JavaScript library 'Leaflet' (see ). Maps can be 5 | rendered in a web browser or displayed in the HTML viewer pane of 'RStudio'. 6 | This package is designed to be easy to use and can create complex maps with 7 | vector and raster data, web served map tiles and interface elements. 8 | Version: 0.2.1 9 | Author: Francois Keck 10 | Maintainer: Francois Keck 11 | Encoding: UTF-8 12 | Depends: 13 | R (>= 3.0.0) 14 | Imports: 15 | knitr (>= 1.5), 16 | sp, 17 | raster, 18 | methods, 19 | grDevices, 20 | graphics, 21 | utils 22 | License: GPL-3 23 | URL: http://www.francoiskeck.fr/rleafmap/, https://github.com/fkeck/rleafmap 24 | RoxygenNote: 7.2.1 25 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | S3method(print,splgrid) 4 | S3method(print,splicons) 5 | S3method(print,spllines) 6 | S3method(print,splpoints) 7 | S3method(print,splpolygons) 8 | S3method(spLayer,SpatialGridDataFrame) 9 | S3method(spLayer,SpatialLines) 10 | S3method(spLayer,SpatialPoints) 11 | S3method(spLayer,SpatialPolygons) 12 | S3method(spLayer,default) 13 | S3method(summary,basemap) 14 | S3method(summary,splgrid) 15 | S3method(summary,splicons) 16 | S3method(summary,spllines) 17 | S3method(summary,splpoints) 18 | S3method(summary,splpolygons) 19 | S3method(summary,ui) 20 | export(basemap) 21 | export(bmSource) 22 | export(chunkerize) 23 | export(col2hexa) 24 | export(layerLegend) 25 | export(spLayer) 26 | export(ui) 27 | export(writeMap) 28 | import(knitr) 29 | import(raster) 30 | import(sp) 31 | importFrom(grDevices,col2rgb) 32 | importFrom(grDevices,dev.off) 33 | importFrom(grDevices,heat.colors) 34 | importFrom(grDevices,png) 35 | importFrom(grDevices,rgb) 36 | importFrom(graphics,par) 37 | importFrom(methods,as) 38 | importFrom(methods,is) 39 | importFrom(utils,browseURL) 40 | -------------------------------------------------------------------------------- /R/basemap.R: -------------------------------------------------------------------------------- 1 | #'Define a Tile Basemap Layer 2 | #' 3 | #'Define a new basemap layer from a tile server. 4 | #' 5 | #'@param URL a character string giving the tile server url or a the name of a pre-configured server. 6 | #'@param name a character string to name the layer. 7 | #'@param alpha a numeric value in \eqn{[0, 1]} setting the layer opacity. 8 | #'@param minZoom,maxZoom numeric values setting the minimum and maximum zoom level. 9 | #'@param tileSize a numeric value setting tile size (width and height in pixels, assuming tiles are square). 10 | #'@param tms logical. If \code{TRUE}, inverses Y axis numbering for tiles (for TMS services) 11 | #' 12 | #'@details \code{URL} should have the form \code{'http://{s}.somedomain.com/somepath/{z}/{x}/{y}.png'} 13 | #'with \code{{s}} a facultative subdomain, \code{{z}} the zoom level and \code{{x}}, \code{{y}} the coordinates. 14 | #'\pkg{rleafmap} comes with a list of pre-configured servers. Names of these servers are returned 15 | #'by the function \code{bmSource}. 16 | #' 17 | #'@return An object of class \code{basemap} which can be directly used in \code{\link{writeMap}}. 18 | #'@seealso \code{\link{spLayer}} to define data layers. 19 | #'@examples \dontrun{ 20 | #' #A simple map with two nice basemaps. 21 | #' bm1 <- basemap("mapquest.map") 22 | #' bm2 <- basemap("stamen.watercolor") 23 | #' writeMap(bm1, bm2) 24 | #'} 25 | #'@export 26 | basemap <- function(URL, name=NULL, alpha=1, minZoom=0, maxZoom=18, tileSize=256, tms=FALSE){ 27 | if(is.vector(URL) && length(URL)==1){ 28 | URL <- as.character(URL) 29 | URL <- bmServer(URL) 30 | URL.cr <- bmCredit(URL) 31 | }else{ 32 | stop("URL must be a single value character vector") 33 | } 34 | if(!is.numeric(alpha)){ 35 | stop("alpha must be numeric") 36 | }else{ 37 | if (alpha<0 || alpha>1){ 38 | stop("alpha must be comprise between 0 and 1") 39 | } 40 | } 41 | if(!is.numeric(minZoom)) 42 | stop("minZoom must be numeric") 43 | if(!is.numeric(maxZoom)) 44 | stop("maxZoom must be numeric") 45 | if(!is.logical(tms)) 46 | stop("tms must be set on TRUE or FALSE") 47 | 48 | res <- list(name, URL, URL.cr, alpha, minZoom, maxZoom, tileSize, tolower(as.character(tms))) 49 | names(res) <- c("name", "URL", "URL.cr", "alpha", "minZoom", "maxZoom", "tileSize", "tms") 50 | class(res) <- "basemap" 51 | return(res) 52 | } 53 | -------------------------------------------------------------------------------- /R/chunkerize.R: -------------------------------------------------------------------------------- 1 | #' Multiple code chunks 2 | #' 3 | #' This function creates multiple code chunks from a function and along arguments marked with a star (*). 4 | #' Each of these special arguments is a list. 5 | #' The nth code chunk will use the nth element of each marked list (recycled if necessary) as argument. 6 | #' 7 | #' @param FUN the function to use for the chunks. 8 | #' @param arg.names a character vector giving the argument names of \code{FUN} to set. 9 | #' @param arg.values a vector giving the values or object names to assign to 10 | #' each argument given with \code{arg.names} (they must match in order). 11 | #' Object names must be backquoted or quoted. 12 | #' Lists names marked with a star (e.g. \code{"*L1"} for \code{L1}) 13 | #' indicate their elements will be used sequentially in chunks. 14 | #' @param type the type of chunk to produce. Can be "\code{block}", "\code{inline}" or "\code{none}". 15 | #' @param echo logical indicating whether to include R source code in the result. 16 | #' @param warning logical indicating whether to print warnings in the result. 17 | #' @param error logical indicating whether to stop on errors. 18 | #' @param message logical indicating whether to print messages in the result. 19 | #' @param fig.width,fig.height numeric value setting width and height of the plots in inches. 20 | #' @param fig.align character string setting the alignment of the plots. Can be "\code{left}", "\code{right}" and "\code{center}". 21 | #' @param options a character string to specify the knitr options. 22 | #' This will overwrite the options set with the other arguments. 23 | #' 24 | #' @return a character vector of R code chunks which can be evaluated by \pkg{knitr}. 25 | #' 26 | #' @export 27 | chunkerize <- function(FUN, arg.names, arg.values, type = "block", 28 | echo = FALSE, warning = FALSE, error = FALSE, message = TRUE, 29 | fig.width = 4, fig.height = 4, fig.align = "center", 30 | options = NULL){ 31 | 32 | if(!is.character(FUN)){ 33 | FUN <- deparse(substitute(FUN)) 34 | } 35 | 36 | type <- match.arg(type, c("block", "inline", "none")) 37 | 38 | arg.star <- sapply(arg.values, function(x) substr(x, 1, 1) == "*" & nchar(x) > 1) 39 | arg.values[arg.star] <- substr(arg.values[arg.star], 2, 100000L) 40 | 41 | star.len <- sapply(arg.values[arg.star], function(x) length(eval(parse(text = x)))) 42 | 43 | if(max(star.len) != min(star.len)){ 44 | stop("Rolling lists must have same lengths.") 45 | } 46 | 47 | arg.values.mat <- matrix(arg.values, nrow = max(star.len), ncol = length(arg.values), byrow = TRUE) 48 | idx <- paste("[[", seq(1:max(star.len)), "]]", sep = "") 49 | 50 | arg.values.mat[, which(arg.star)] <- paste(arg.values.mat[, which(arg.star)], idx, sep = "") 51 | 52 | arg.comp <- paste(arg.names, " = ", t(arg.values.mat), sep = "") 53 | arg.comp <- matrix(arg.comp, nrow = max(star.len), ncol = length(arg.values), byrow = TRUE) 54 | arg.comp <- apply(arg.comp, 1, paste, sep = "", collapse = ", ") 55 | 56 | res <- paste(FUN, "(", arg.comp, ")", sep = "") 57 | 58 | if(type == "inline"){ 59 | res <- paste("`r ", res, "`", sep = "") 60 | } 61 | 62 | if(type == "block"){ 63 | if(is.null(options)){ 64 | options <- paste("echo=", echo, 65 | ", warning=", warning, 66 | ", error=", error, 67 | ", message=", message, 68 | ", fig.width=", fig.width, 69 | ", fig.height=", fig.height, 70 | ", fig.align='", fig.align, "'", sep = "") 71 | } 72 | res <- paste("\n```{r ", options, "}\n\t", res, "\n```\n", sep = "") 73 | } 74 | 75 | return(res) 76 | } 77 | 78 | -------------------------------------------------------------------------------- /R/codeinc.R: -------------------------------------------------------------------------------- 1 | 2 | incLeaflet <- function(loc){ 3 | if(loc == "online"){ 4 | res <- paste(" 5 | ") 6 | } else { 7 | res <- paste(" 8 | ", sep="") 9 | } 10 | return(res) 11 | } 12 | 13 | incEncoding <- function(code){ 14 | res <- paste(" 15 | 17 | 18 | ", sep="") 19 | return(res) 20 | } 21 | 22 | incPopupCSS <- function(height, width){ 23 | res <- paste0( 24 | ".leaflet-popup-content { 25 | padding-right:20px !important; 26 | width:auto !important; 27 | max-width:", width*0.75, "px !important; 28 | max-height:", height*0.75, "px !important; 29 | overflow:auto !important; 30 | }") 31 | return(res) 32 | } 33 | 34 | incData <- function(prefix){ 35 | paste(" 36 | 37 | 38 | ", # Fix le 2eme prefix + faire une fonction 39 | sep="") 40 | } 41 | 42 | initMap0 <- function(height, width){ 43 | paste("
", sep="") 44 | } 45 | 46 | initMap1 <- function(setView, setZoom){ 47 | if(is.null(setView)) setView <- c(0, 0) 48 | if(is.null(setZoom)) setZoom <- 1 49 | paste("var map = L.map('map', {zoomControl:false, attributionControl:false}).setView([", setView[1], ", ", setView[2],"], ", setZoom, ");", sep="") 50 | } 51 | 52 | incInfoPanelCSS <- function(){ 53 | ".info { 54 | padding: 6px 8px; 55 | background: rgba(255,255,255,0.8); 56 | box-shadow: 0 0 15px rgba(0,0,0,0.2); 57 | border-radius: 5px; 58 | }" 59 | } 60 | 61 | incLegendCSS <- function(){ 62 | ".legend i { 63 | clear: left; 64 | float: left; 65 | margin-right: 8px; 66 | margin-top: 5px; 67 | } 68 | .legend p { 69 | float: left;; 70 | line-height: 5px; 71 | } 72 | .legend h1 { 73 | font-size: 10px; 74 | margin-top: 0px; 75 | margin-bottom: 2px; 76 | } 77 | .legend hr { 78 | margin-top: 2px; 79 | margin-bottom: 2px; 80 | display: block; 81 | height: 1px; 82 | border: 0; 83 | border-top: 1px solid #AAAAAA; 84 | }" 85 | } -------------------------------------------------------------------------------- /R/genmeths.R: -------------------------------------------------------------------------------- 1 | 2 | 3 | splPrint <- function(x, ...){ 4 | print.default(x, max = 10) 5 | } 6 | 7 | #' Printing spl object 8 | #' 9 | #' Print spl objects 10 | #' 11 | #'@param x an \code{spl} object. 12 | #'@param ... additional arguments. Not used. 13 | #' 14 | #'@rdname printspl 15 | #'@method print splpoints 16 | #'@export 17 | print.splpoints <- splPrint 18 | 19 | #'@rdname printspl 20 | #'@method print splicons 21 | #'@export 22 | print.splicons <- splPrint 23 | 24 | #'@rdname printspl 25 | #'@method print spllines 26 | #'@export 27 | print.spllines <- splPrint 28 | 29 | #'@rdname printspl 30 | #'@method print splpolygons 31 | #'@export 32 | print.splpolygons <- splPrint 33 | 34 | #'@rdname printspl 35 | #'@method print splgrid 36 | #'@export 37 | print.splgrid <- splPrint 38 | 39 | 40 | 41 | 42 | #' Summary of map elements 43 | #' 44 | #' Get a summary of a map element. 45 | #' 46 | #'@param object a map layer, \code{basemap}, \code{spl} or \code{ui} object. 47 | #'@param ... additional arguments. Not used. 48 | #' 49 | #'@rdname summarymaplayer 50 | #'@method summary basemap 51 | #'@export 52 | summary.basemap <- function(object, ...){ 53 | cat(object$name, ":\nrleafmap tile layer\nSource : ", object$URL) 54 | } 55 | 56 | #'@rdname summarymaplayer 57 | #'@method summary splpoints 58 | #'@export 59 | summary.splpoints <- function(object, ...){ 60 | cat(object$name, ":\nrleafmap vector layer of", length(object$coords[,1]), "points symbolized by circles \n") 61 | } 62 | 63 | #'@rdname summarymaplayer 64 | #'@method summary splicons 65 | #'@export 66 | summary.splicons <- function(object, ...){ 67 | cat(object$name, ":\nrleafmap vector layer of", length(object$coords[,1]), "points symbolized by icons \n") 68 | } 69 | 70 | #'@rdname summarymaplayer 71 | #'@method summary spllines 72 | #'@export 73 | summary.spllines <- function(object, ...){ 74 | cat(object$name, ":\nrleafmap vector layer of", length(object$coords), "lines \n") 75 | } 76 | 77 | #'@rdname summarymaplayer 78 | #'@method summary splpolygons 79 | #'@export 80 | summary.splpolygons <- function(object, ...){ 81 | cat(object$name, ":\nrleafmap vector layer of", length(object$coords), "polygons \n") 82 | } 83 | 84 | #'@rdname summarymaplayer 85 | #'@method summary splgrid 86 | #'@export 87 | summary.splgrid <- function(object, ...){ 88 | cat(object$name, ":\nrleafmap raster layer from a sp SpatialGridDataFrame\n------------\n") 89 | print(object$x) 90 | cat("------------") 91 | } 92 | 93 | #'@rdname summarymaplayer 94 | #'@method summary ui 95 | #'@export 96 | summary.ui <- function(object, ...){ 97 | cat("User interface configuration for rleafmap maps\n------------\n") 98 | cat("Zoom position : ",object$zoom, "\n") 99 | cat("Layers control position : ",object$layers, "\n") 100 | cat("Attributions position : ",object$attrib, "\n") 101 | cat("Additionnal attribution text : ",object$attrib.text, "\n") 102 | cat("------------") 103 | } -------------------------------------------------------------------------------- /R/legend.R: -------------------------------------------------------------------------------- 1 | 2 | #' Data layer legend 3 | #' 4 | #' This function creates a legend object that can be attached to a data layer. 5 | #' 6 | #' @inheritParams spLayer.SpatialPoints 7 | #' @param style the style of legend to generate. 8 | #' Can be one of "\code{points}", "\code{lines}", "\code{polygons}", "\code{icons}", "\code{gradient}". 9 | #' @param labels a vector to label each element of the legend. 10 | #' @param title a title which will appear above the legend. 11 | #' If \code{NULL} (default), it will inherit the name of the data layer during the compilation of the map. 12 | #' If \code{NA}, the legend will appear without title. 13 | #' @param position a character string indicating where should the legend be displayed. 14 | #' This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}" 15 | #' @param cells.range range of gradient values. 16 | #' @param cells.col a vector of any of the three kinds of \R color specifications giving the colors of the gradient. 17 | #' @param cells.alpha a vector of numeric values in \eqn{[0, 1]} setting the gradient opacity. 18 | #' 19 | #' @return an object \code{layerlegend} which can be passed to an \code{spLayer*} function through the \code{legend} argument. 20 | #' 21 | #' @export 22 | layerLegend <- function(style, labels = "", title = NULL, position = "bottomright", 23 | png = NULL, size = 5, png.width = NULL, png.height = NULL, 24 | stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, 25 | fill.col = 2, fill.alpha = 0.5, 26 | cells.range = c(1, 10), cells.col = heat.colors(12), cells.alpha = 1){ 27 | 28 | position <- match.arg(position, c("bottomright", "topleft", "topright", "bottomleft", "none"), several.ok = FALSE) 29 | style <- match.arg(style, c("points", "lines", "polygons", "icons", "gradient"), several.ok = FALSE) 30 | labels <- as.character(labels) 31 | tab.max <- length(labels) 32 | 33 | labels <- paste0("\"", as.character(labels), "\"") 34 | 35 | if(style %in% c("points", "lines", "polygons")){ 36 | stroke.lty <- paste0("\"", as.character(stroke.lty), "\"") 37 | } 38 | 39 | if(style == "points"){ 40 | tab <- list(labels, size, 41 | stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 42 | fill.col, fill.alpha) 43 | tab <- lapply(tab, rep, length.out = tab.max) 44 | names(tab) <- c("legLabels", "legSize", 45 | "legStrokeCol", "legStrokeLwd", "legStrokeLty", "legStrokeAlpha", 46 | "legFillCol", "legFillAlpha") 47 | tab$legWidth <- (tab$legSize + tab$legStrokeLwd) * 2 48 | tab$legHeight <- (tab$legSize + tab$legStrokeLwd) * 2 49 | } 50 | 51 | if(style == "icons"){ 52 | if(is.null(png.width)){ 53 | png.width <- size 54 | } 55 | if(is.null(png.height)){ 56 | png.height <- size 57 | } 58 | tab <- list(labels, png, png.width, png.height) 59 | tab <- lapply(tab, rep, length.out = tab.max) 60 | names(tab) <- c("legLabels", "legPng", "legPngWidth", "legPngHeight") 61 | tab$legWidth <- tab$legPngWidth 62 | tab$legHeight <- tab$legPngHeight 63 | } 64 | 65 | if(style == "lines"){ 66 | tab <- list(labels, 67 | stroke.col, stroke.lwd, stroke.lty, stroke.alpha) 68 | tab <- lapply(tab, rep, length.out = tab.max) 69 | names(tab) <- c("legLabels", 70 | "legStrokeCol", "legStrokeLwd", "legStrokeLty", "legStrokeAlpha") 71 | tab$legWidth <- rep(40, tab.max) 72 | tab$legHeight <- rep(stroke.lwd + 5, tab.max) 73 | } 74 | 75 | if(style == "polygons"){ 76 | tab <- list(labels, 77 | stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 78 | fill.col, fill.alpha) 79 | tab <- lapply(tab, rep, length.out = tab.max) 80 | names(tab) <- c("legLabels", 81 | "legStrokeCol", "legStrokeLwd", "legStrokeLty", "legStrokeAlpha", 82 | "legFillCol", "legFillAlpha") 83 | tab$legWidth <- rep(30, tab.max) + (2 * tab$legStrokeLwd) 84 | tab$legHeight <- rep(17, tab.max) + (2 * tab$legStrokeLwd) 85 | } 86 | 87 | if(style == "gradient"){ 88 | breaks <- seq(min(cells.range), max(cells.range), length.out = length(cells.col)) 89 | tab <- list() 90 | tab$gradcol <- col2rgb(cells.col, alpha = FALSE) 91 | tab$gradalpha <- rep(cells.alpha, length.out = length(cells.col)) 92 | tab$gradlab <- pretty(breaks, 5) 93 | tab$gradlab <- tab$gradlab[c(-1, -length(tab$gradlab))] 94 | tab$gradoffset <- round(seq(0, 100, length.out = length(cells.col)), digits = 2) 95 | tab$legWidth <- 15 96 | tab$legHeight <- 150 97 | tab$gradlabpos <- rev((tab$legHeight/diff(cells.range)) * (tab$gradlab - min(cells.range))) 98 | } 99 | 100 | if(style %in% c("points", "polygons")){ 101 | tab$legStrokeCol <- col2rgb(col2hexa(tab$legStrokeCol, alpha.channel = TRUE, alpha = tab$legStrokeAlpha, charstring = FALSE), alpha = TRUE) 102 | tab$legStrokeCol["alpha", ] <- tab$legStrokeAlpha 103 | tab$legFillCol <- col2rgb(col2hexa(tab$legFillCol, alpha.channel = TRUE, alpha = tab$legFillAlpha, charstring = FALSE), alpha = TRUE) 104 | tab$legFillCol["alpha", ] <- tab$legFillAlpha 105 | tab$legStrokeAlpha <- tab$legFillAlpha <- NULL 106 | } 107 | 108 | if(style %in% c("lines")){ 109 | tab$legStrokeCol <- col2rgb(col2hexa(tab$legStrokeCol, alpha.channel = TRUE, alpha = tab$legStrokeAlpha, charstring = FALSE), alpha = TRUE) 110 | tab$legStrokeCol["alpha", ] <- tab$legStrokeAlpha 111 | } 112 | 113 | res <- list(style = style, title = title, position = position, tab = tab) 114 | class(res) <- "layerlegend" 115 | return(res) 116 | 117 | } 118 | 119 | 120 | processLegend <- function(x, icons.legend.dir, prefix){ 121 | legend.name <- safeVar(paste0("legend", x$layer)) 122 | 123 | res <- paste0("var ", legend.name, " = L.control({position: '", x$position, "'});\n") 124 | res <- paste0(res, legend.name, ".onAdd = function (map) {\n\nvar div = L.DomUtil.create('div', 'info legend');\n") 125 | if(!is.na(x$title)){ 126 | res <- paste0(res, "div.innerHTML += '

", x$title, "


'\n") 127 | } 128 | 129 | if(x$style != "gradient"){ 130 | tab.names <- names(x$tab) 131 | 132 | if(x$style %in% c("points", "lines", "polygons")){ 133 | x$tab$legStrokeCol <- apply(x$tab$legStrokeCol, 2, function(x) paste0("[", paste(x, collapse = ","), "]")) 134 | } 135 | if(x$style %in% c("points", "polygons")){ 136 | x$tab$legFillCol <- apply(x$tab$legFillCol, 2, function(x) paste0("[", paste(x, collapse = ","), "]")) 137 | } 138 | if(x$style == "icons"){ 139 | file.copy(from = levels(as.factor(x$tab$legPng)), to = icons.legend.dir) 140 | x$tab$legPng <- paste0("\"", 141 | prefix, "_data/", 142 | prefix, "_icons/", 143 | prefix, "_legend_icons/", 144 | gsub("(.*\\/)([^.]+\\.[[:alnum:]]+$)","\\2", x$tab$legPng), "\"") 145 | } 146 | 147 | tab <- lapply(x$tab, function(x) paste(x, collapse = ",")) 148 | tab <- unlist(tab) 149 | tab <- paste0(tab.names, " = [", tab, "],", collapse = "\n") 150 | 151 | 152 | res <- paste0(res, "var ", tab, "\n", "labels = [];\n\n") 153 | 154 | if(x$style %in% c("points", "icons")){ 155 | marginLeft <- paste0("var marginLeft = [", paste0((max(x$tab$legWidth) - x$tab$legWidth)/2, collapse = ","), "];\n") 156 | res <- paste0(res, marginLeft) 157 | i.sty <- "" 158 | } else { 159 | i.sty <- "" 160 | } 161 | 162 | res <- paste0(res, "for (var i = 0; i < legLabels.length; i++) {\nvar lineHeight = legHeight[i];\ndiv.innerHTML +=\n'", i.sty) 163 | 164 | if(x$style == "points"){ 165 | svg <- "" 166 | } 167 | if(x$style == "icons"){ 168 | svg <- "" 169 | } 170 | if(x$style == "lines"){ 171 | svg <- "" 172 | } 173 | if(x$style == "polygons"){ 174 | svg <- "" 175 | } 176 | res <- paste0(res, svg) 177 | if(x$style == "lines"){ 178 | res <- paste0(res, "

' + legLabels[i] + '


';\n}") 179 | } else { 180 | res <- paste0(res, "

' + legLabels[i] + '


';\n}") 181 | } 182 | } 183 | 184 | if(x$style == "gradient"){ 185 | tab <- x$tab 186 | svg <- paste0("") 187 | svg <- paste0(svg, "") 188 | svg <- paste0(svg, "") 189 | svg.def <- paste0("", collapse = "") 190 | svg <- paste0(svg, svg.def) 191 | svg <- paste0(svg, "") 192 | svg <- paste0(svg, "") 193 | svg <- paste0(svg, "") 194 | svg.tick <- paste0("", collapse = "") 195 | svg.lab <- paste0("", tab$gradlab, "", collapse = "") 196 | svg <- paste0(svg, svg.tick, svg.lab, "") 197 | 198 | res <- paste0(res, "div.innerHTML +=\n'", svg, "'") 199 | } 200 | 201 | res <- paste0(res, "\n\nreturn div;\n};\n\n", legend.name,".addTo(map);\n\n") 202 | 203 | res <- paste0(res, "map.on('overlayadd', function (eventLayer) {\nif (eventLayer.name === '", x$layer.name, "') {\n", legend.name, ".addTo(this);\n}\n});\n") 204 | res <- paste0(res, "map.on('overlayremove', function (eventLayer) {\nif (eventLayer.name === '", x$layer.name, "') {\nthis.removeControl(", legend.name, ");\n}\n});") 205 | 206 | return(res) 207 | } 208 | 209 | -------------------------------------------------------------------------------- /R/rleafmap-package.R: -------------------------------------------------------------------------------- 1 | #' rleafmap 2 | #' 3 | #' Display spatial data with interactive maps powered by the open- 4 | #' source JavaScript library 'Leaflet' (see ). Maps can be 5 | #' rendered in a web browser or displayed in the HTML viewer pane of 'RStudio'. 6 | #' This package is designed to be easy to use and can create complex maps with 7 | #' vector and raster data, web served map tiles and interface elements. 8 | #' 9 | #' @import sp 10 | #' @import knitr 11 | #' @import raster 12 | #' @importFrom grDevices col2rgb dev.off heat.colors png rgb 13 | #' @importFrom graphics par 14 | #' @importFrom methods as is 15 | #' @importFrom utils browseURL 16 | #' 17 | #' @name rleafmap 18 | #' @docType package 19 | NULL 20 | 21 | #' French Hotels 22 | #' 23 | #' This dataset gives the number of hotels, number of rooms and capacity for each department of metropolitan France. 24 | #' 25 | #' @format a \code{SpatialPolygonsDataFrame} with geometries of the 96 french departements (epsg:4326) and 12 variables. 26 | #' \itemize{ 27 | #' \item DEP.CODE The code number of each department. 28 | #' \item DEP.NAME The name of each department. 29 | #' \item CHF.NAME The name of the main (administrative) city of each department. 30 | #' \item REGION.NAME The name of the french region (administrative) of each department. 31 | #' \item N.HOTELS The number of hotels. 32 | #' \item N.5, N.4, N.3, N.2, N.1 The number of hotels for each ranking categories (i.e. stars). 33 | #' \item ROOMS The number of hotel's rooms for each department. 34 | #' \item CAPACITY The total capacity (beds) for each department. 35 | #' } 36 | #' @source \itemize{ 37 | #' \item Institut National de l'Information Geographique et Forestiere (2014) 38 | #' \item ATOUT FRANCE - Agence de developpement touristique de la France (2014). 39 | #' } 40 | #' @docType data 41 | #' @keywords datasets 42 | #' @name hotels 43 | #' @usage data(hotels) 44 | NULL 45 | 46 | 47 | #' French Campsites 48 | #' 49 | #' This dataset gives the number of ranked campsites and the number of tent pitches for each department of metropolitan France. 50 | #' 51 | #' @format a \code{SpatialPolygonsDataFrame} with geometries of the 96 french departements (epsg:4326) and 11 variables. 52 | #' \itemize{ 53 | #' \item DEP.CODE The code number of each department. 54 | #' \item DEP.NAME The name of each department. 55 | #' \item CHF.NAME The name of the main (administrative) city of each department. 56 | #' \item REGION.NAME The name of the administrative french region of each department. 57 | #' \item N.CAMPSITES The number of campsites. 58 | #' \item N.5, N.4, N.3, N.2, N.1 The number of campsites for each ranking categories (i.e. stars). 59 | #' \item PITCHES The number of camp pitches for each department. 60 | #' } 61 | #' @source \itemize{ 62 | #' \item Institut National de l'Information Geographique et Forestiere (2014) 63 | #' \item ATOUT FRANCE - Agence de developpement touristique de la France (2014). 64 | #' } 65 | #' @docType data 66 | #' @keywords datasets 67 | #' @name campsites 68 | #' @usage data(campsites) 69 | NULL 70 | 71 | 72 | #' Velo'v stations 73 | #' 74 | #' Stations of the bicycle sharing system of the city of Lyon (France). 75 | #' 76 | #' @format a \code{SpatialPointsDataFrame} with the location and name of the 349 Velov stations (epsg:4326). 77 | #' @source 78 | #' OpenStreetMap (14/04/2014) 79 | #' 80 | #' @docType data 81 | #' @keywords datasets 82 | #' @name velov 83 | #' @usage data(velov) 84 | NULL 85 | -------------------------------------------------------------------------------- /R/serial.R: -------------------------------------------------------------------------------- 1 | # 2 | # serial <- function(FUN, ...){ 3 | # 4 | # if(!is.character(FUN)){ 5 | # FUN <- deparse(substitute(FUN)) 6 | # } 7 | # 8 | # x <- list(...) 9 | # x.len.max <- max(sapply(x, length)) 10 | # seq.len.max <- seq(1, x.len.max) 11 | # xb <- lapply(x, rep, length.out = x.len.max) 12 | # 13 | # ds.arg <- deparse(substitute(list(...))) 14 | # ds.arg <- substr(ds.arg, 6, nchar(ds.arg)-1) 15 | # ds.arg <- strsplit(ds.arg, ",") 16 | # n.arg <- length(ds.arg) 17 | # arg.comp <- matrix(NA, nrow = x.len.max, ncol = n.arg) 18 | # for(i in n.arg){ 19 | # arg.comp[, i] <- paste(ds.arg[i], "[[", seq.len.max, "]]", sep = "") 20 | # } 21 | # arg.comp <- apply(arg.comp, 1, paste, collapse = "", sep = "") 22 | # 23 | # res <- paste(FUN, "(", arg.comp, ")", sep = "") 24 | # return(res) 25 | # } 26 | # 27 | # 28 | # 29 | # serial2 <- function(FUN, ...){ 30 | # fo <- deparse(substitute(list(...))) 31 | # return(fo) 32 | # } 33 | # FUN <- mean 34 | # L1 <- lapply(1:10, rep, 10) 35 | # L2 <- lapply(5:1, rep, 3) 36 | # x <- list(L1, L2) 37 | # serial("mean", a = L1, b=3) 38 | # serial2(FUN="mean", a=L1, b=3) 39 | # 40 | # 41 | # x <- function(y, z) print(deparse(substitute(y))) 42 | # x(y= sum) 43 | # 44 | # 45 | # writeLines(c("# hello markdown", "```{r hello-random, echo=TRUE}", "rnorm(5)", "```"), 46 | # "test.Rmd") 47 | # knit2html(text=c("# hello markdown", "```{r hello-random, echo=TRUE}", "rnorm(5)", "```"), 48 | # options = 'fragment_only') 49 | # library(knitr) 50 | # ss <- knit2html(output=NULL, text="# hello markdown\n```{r hello-random, echo=FALSE}\nplot(3)\n```", 51 | # options = c('fragment_only', 'base64_images')) 52 | # write(x=ss, "tt.html") 53 | -------------------------------------------------------------------------------- /R/splayer.R: -------------------------------------------------------------------------------- 1 | #'Define a Data Layer 2 | #' 3 | #'Define a new data layer from an object sp. 4 | #' 5 | #' @param x a spatial object as defined in the package \pkg{sp}. 6 | #' @param ... additional arguments to pass to the function. 7 | #' 8 | #' @examples \dontrun{ 9 | #' #POINTS 10 | #' data(velov) 11 | #' vv <- spLayer(velov, stroke=F, popup=velov$NAME) 12 | #' 13 | #' #POLYGONS 14 | #' data(campsites) 15 | #' gcol <- rev(heat.colors(5)) 16 | #' gcut <- cut(mapdep$N.CAMPSITES, breaks=c(-1, 20, 40, 60, 80, 1000)) 17 | #' cs <- spLayer(campsites, fill.col=as.numeric(gcut)) 18 | #' bm1 <- basemap("mapquest.map") 19 | #' 20 | #' writeMap(bm1, cs, vv) 21 | #'} 22 | #'@export 23 | spLayer <- function(x, ...){ 24 | UseMethod("spLayer", x) 25 | } 26 | 27 | #'Define a Vector Data Layer 28 | #' 29 | #' @param x a spatial object as defined in the package \pkg{sp}. 30 | #' @param ... additional arguments to pass to the function. 31 | #' @export 32 | spLayer.default <- function(x, ...){ 33 | print("Error: x not recognized as Spatial* object") 34 | } 35 | 36 | 37 | 38 | #'Define a Vector Data Layer 39 | #' 40 | #'\itemize{ 41 | #'\item \code{spLayer.SpatialPoints} defines a new data layer from an object \code{SpatialPoints} or \code{SpatialPointsDataFrame} 42 | #'\item \code{spLayer.SpatialLines} defines a new data layer from an object \code{SpatialLines} or \code{SpatialLinesDataFrame} 43 | #'\item \code{spLayer.SpatialPolygons} defines a new data layer from an object \code{SpatialPolygons} or \code{SpatialPolygonsDataFrame} 44 | #'} 45 | #' 46 | #'@param x a spatial object (see Details). 47 | #'@param name a character string to name the layer. 48 | #'@param size a numerical vector giving the size of points (radius in pixels). 49 | #'@param png character vector giving the paths for the PNG icons. If \code{NULL} (default), circles are drawn. 50 | #'@param png.width,png.height numerical vectors giving the PNG icons dimensions on the map (in pixels). 51 | #'@param stroke logical. Should a stroke be drawn along lines and polygons? 52 | #'@param stroke.col a vector of any of the three kinds of \R color specifications to set strokes color. 53 | #'@param stroke.lwd a numerical vector to set strokes width. 54 | #'@param stroke.lty a character vector that defines the strokes dash patterns (See Details). 55 | #'@param stroke.alpha a vector of numeric values in \eqn{[0, 1]} setting strokes opacity. 56 | #'@param fill logical. Should points and polygons be filled? 57 | #'@param fill.col a vector of any of the three kinds of \R color specifications to set fill colors. 58 | #'@param fill.alpha a vector of numeric values in \eqn{[0, 1]} setting fill opacity. 59 | #'@param label a reserved argument (in development). 60 | #'@param popup a character vector giving contents for popups. HTML tags are accepted. 61 | #'@param popup.rmd a logical indicating whether the popups should be processed as R Markdown with \pkg{knitr}. Default \code{FALSE}. 62 | #'@param legend a legend object created with \code{\link{layerLegend}}. 63 | #'@param ... additional arguments to pass to the function. 64 | #' 65 | #'@method spLayer SpatialPoints 66 | #'@export 67 | spLayer.SpatialPoints <- function(x, name = NULL, png = NULL, size = 5, png.width = 15, png.height = 15, 68 | stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, 69 | fill = TRUE, fill.col = 2, fill.alpha = 0.5, 70 | label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ...){ 71 | if(is.null(png)){ 72 | 73 | if(!inherits(x, "SpatialPoints")) 74 | stop("x must be an object of class SpatialPoints or SpatialPointsDataFrame") 75 | 76 | spLayerControl(name = name, size = size, legend = legend, 77 | stroke = stroke, stroke.col = stroke.col, stroke.lwd = stroke.lwd, stroke.lty = stroke.lty, stroke.alpha = stroke.alpha, 78 | fill = fill, fill.col = fill.col, fill.alpha = fill.alpha) 79 | 80 | tested.index <- !sapply(list(size, stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 81 | fill, fill.col, fill.alpha, label, popup), is.null) 82 | 83 | stroke.logical <- stroke 84 | fill.logical <- fill 85 | stroke <- paste("\"", tolower(as.character(stroke)), "\"", sep="") 86 | fill <- paste("\"", tolower(as.character(fill)), "\"", sep="") 87 | stroke.lty <- paste("\"", as.character(stroke.lty), "\"", sep="") 88 | 89 | tab.max <- length(x) 90 | tab <- list(size, 91 | stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 92 | fill, fill.col, fill.alpha, label, popup)[tested.index] 93 | tab <- lapply(tab, rep, length.out=tab.max) 94 | 95 | tested.names <- c("size", "stroke", "strokeCol", "strokeLwd", "strokeLty", "strokeAlpha", 96 | "fill", "fillCol", "fillAlpha", "label", "popup")[tested.index] 97 | names(tab) <- tested.names 98 | 99 | legend$layer <- name 100 | tab$name <- name 101 | tab$legend <- legend 102 | tab$coords <- coordinates(x) 103 | 104 | tab$strokeCol[!stroke.logical] <- tab$strokeLwd[!stroke.logical] <- tab$strokeLty[!stroke.logical] <- 1 105 | tab$strokeAlpha[!stroke.logical] <- 0 106 | tab$strokeCol <- col2hexa(tab$strokeCol) 107 | 108 | tab$fillCol[!fill.logical] <- 1 109 | tab$fillAlpha[!fill.logical] <- 0 110 | tab$fillCol <- col2hexa(tab$fillCol) 111 | 112 | 113 | if (any(as.numeric(tab$strokeAlpha)<0) || any(as.numeric(tab$strokeAlpha)>1)) 114 | stop("stroke.alpha must be comprise between 0 and 1") 115 | if (any(as.numeric(tab$strokeLwd)<0)) 116 | stop("stroke.lwd must be positive") 117 | if (any(as.numeric(tab$fillAlpha)<0) || any(as.numeric(tab$fillAlpha)>1)) 118 | stop("fill.alpha must be comprise between 0 and 1") 119 | 120 | if("label" %in% tested.names) 121 | tab$label <- paste("\"", as.character(tab$label), "\"", sep="") 122 | if("popup" %in% tested.names){ 123 | if(popup.rmd){ 124 | tab$popup <- sapply(as.vector(tab$popup), function(x) knitr::knit2html(output = NULL, text = x, 125 | options = c('fragment_only', 'base64_images'))) 126 | tab$popup <- gsub("\\n", "
", tab$popup) 127 | tab$popup <- gsub("\"", "\\\\\"", tab$popup) 128 | } 129 | tab$popup <- paste("\"", as.character(tab$popup), "\"", sep="") 130 | } 131 | 132 | class(tab) <- c("splpoints") 133 | return(tab) 134 | 135 | } else { 136 | 137 | if(!inherits(x, "SpatialPoints")) 138 | stop("x must be an object of class SpatialPoints or SpatialPointsDataFrame") 139 | 140 | spLayerControl(name = name, legend = legend) 141 | size <- paste("[", png.width, ",", png.height, "]", sep="") 142 | tested.index <- !sapply(list(png, size, label, popup), is.null) 143 | 144 | tab.max <- length(x) 145 | tab <- list(png, size, label, popup)[tested.index] 146 | tab <- lapply(tab, rep, length.out=tab.max) 147 | 148 | tested.names <- c("png", "size", "label", "popup")[tested.index] 149 | names(tab) <- tested.names 150 | 151 | legend$layer <- name 152 | tab$name <- name 153 | tab$legend <- legend 154 | tab$coords <- coordinates(x) 155 | 156 | if("label" %in% tested.names) 157 | tab$label <- paste("\"", as.character(tab$label), "\"", sep="") 158 | if("popup" %in% tested.names){ 159 | if(popup.rmd){ 160 | tab$popup <- sapply(as.vector(tab$popup), function(x) knitr::knit2html(output = NULL, text = x, 161 | options = c('fragment_only', 'base64_images'))) 162 | tab$popup <- gsub("\\n", "
", tab$popup) 163 | tab$popup <- gsub("\"", "\\\\\"", tab$popup) 164 | } 165 | tab$popup <- paste("\"", as.character(tab$popup), "\"", sep="") 166 | } 167 | class(tab) <- c("splicons") 168 | return(tab) 169 | } 170 | } 171 | 172 | #'Define a Vector Data Layer 173 | #' 174 | #'@inheritParams spLayer.SpatialPoints 175 | #' 176 | #'@method spLayer SpatialLines 177 | #'@export 178 | spLayer.SpatialLines <- function(x, name = NULL, 179 | stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, 180 | label = NULL, popup = "", popup.rmd = FALSE, legend = NULL, ...){ 181 | 182 | if(!inherits(x, "SpatialLines")) 183 | stop("x must be an object of class SpatialLines or SpatialLinesDataFrame") 184 | 185 | spLayerControl(name = name, legend = legend, 186 | stroke = stroke, stroke.col = stroke.col, stroke.lwd = stroke.lwd, stroke.lty = stroke.lty, stroke.alpha = stroke.alpha) 187 | 188 | tested.index <- !sapply(list(stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 189 | label, popup), is.null) 190 | 191 | stroke.logical <- stroke 192 | stroke <- paste("\"", tolower(as.character(stroke)), "\"", sep="") 193 | stroke.lty <- paste("\"", as.character(stroke.lty), "\"", sep="") 194 | 195 | tab <- list(stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 196 | label, popup)[tested.index] 197 | tab.max <- length(x) 198 | tab <- lapply(tab, rep, length.out=tab.max) 199 | 200 | tested.names <- c("stroke", "strokeCol", "strokeLwd", "strokeLty", "strokeAlpha", 201 | "label", "popup")[tested.index] 202 | names(tab) <- tested.names 203 | 204 | tab$strokeCol[!stroke.logical] <- tab$strokeLwd[!stroke.logical] <- tab$strokeLty[!stroke.logical] <- 1 205 | tab$strokeAlpha[!stroke.logical] <- 0 206 | tab$strokeCol <- col2hexa(tab$strokeCol) 207 | 208 | legend$layer <- name 209 | tab$name <- name 210 | tab$legend <- legend 211 | tab$coords <- coordinates(x) 212 | 213 | if (any(as.numeric(tab$strokeAlpha)<0) || any(as.numeric(tab$strokeAlpha)>1)) 214 | stop("stroke.alpha must be comprise between 0 and 1") 215 | if (any(as.numeric(tab$strokeLwd)<0)) 216 | stop("stroke.lwd must be positive") 217 | 218 | if("label" %in% tested.names) 219 | tab$label <- paste("\"", as.character(tab$label), "\"", sep="") 220 | if("popup" %in% tested.names){ 221 | if(popup.rmd){ 222 | tab$popup <- sapply(as.vector(tab$popup), function(x) knitr::knit2html(output = NULL, text = x, 223 | options = c('fragment_only', 'base64_images'))) 224 | tab$popup <- gsub("\\n", "
", tab$popup) 225 | tab$popup <- gsub("\"", "\\\\\"", tab$popup) 226 | } 227 | tab$popup <- paste("\"", as.character(tab$popup), "\"", sep="") 228 | } 229 | class(tab) <- c("spllines") 230 | return(tab) 231 | } 232 | 233 | #'Define a Vector Data Layer 234 | #' 235 | #'@inheritParams spLayer.SpatialPoints 236 | #'@param holes a logical indicating whether to use the \code{hole} slots of the \code{SpatialPolygons} object. 237 | #' 238 | #'@method spLayer SpatialPolygons 239 | #'@export 240 | spLayer.SpatialPolygons <- function(x, name = NULL, 241 | stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = -1, stroke.alpha = 1, 242 | fill = TRUE, fill.col = 2, fill.alpha = 0.5, 243 | label = NULL, popup = "", popup.rmd = FALSE, holes = FALSE, legend = NULL, ...){ 244 | if(!inherits(x, "SpatialPolygons")) 245 | stop("x must be an object of class SpatialPolygons or SpatialPolygonsDataFrame") 246 | 247 | spLayerControl(name = name, legend = legend, 248 | stroke = stroke, stroke.col = stroke.col, stroke.lwd = stroke.lwd, stroke.lty = stroke.lty, stroke.alpha = stroke.alpha, 249 | fill = fill, fill.col = fill.col, fill.alpha = fill.alpha) 250 | 251 | tested.index <- !sapply(list(stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 252 | fill, fill.col, fill.alpha, label, popup), is.null) 253 | 254 | stroke.logical <- stroke 255 | fill.logical <- fill 256 | stroke <- paste("\"", tolower(as.character(stroke)), "\"", sep="") 257 | fill <- paste("\"", tolower(as.character(fill)), "\"", sep="") 258 | stroke.lty <- paste("\"", as.character(stroke.lty), "\"", sep="") 259 | 260 | tab <- list(stroke, stroke.col, stroke.lwd, stroke.lty, stroke.alpha, 261 | fill, fill.col, fill.alpha, label, popup)[tested.index] 262 | tab.max <- length(x) 263 | tab <- lapply(tab, rep, length.out=tab.max) 264 | 265 | tested.names <- c("stroke", "strokeCol", "strokeLwd", "strokeLty", "strokeAlpha", 266 | "fill", "fillCol", "fillAlpha", "label", "popup")[tested.index] 267 | names(tab) <- tested.names 268 | 269 | tab$strokeCol[!stroke.logical] <- tab$strokeLwd[!stroke.logical] <- tab$strokeLty[!stroke.logical] <- 1 270 | tab$strokeAlpha[!stroke.logical] <- 0 271 | tab$strokeCol <- col2hexa(tab$strokeCol) 272 | 273 | tab$fillCol[!fill.logical] <- 1 274 | tab$fillAlpha[!fill.logical] <- 0 275 | tab$fillCol <- col2hexa(tab$fillCol) 276 | 277 | legend$layer <- name 278 | tab$name <- name 279 | tab$legend <- legend 280 | tab$coords <- polycoords(x) 281 | if (holes){ 282 | tab$holes <- polyholes(x) 283 | tab$order <- polyorder(x) 284 | } else { 285 | tab$holes <- tab$order <- NULL 286 | } 287 | 288 | if (any(as.numeric(tab$strokeAlpha)<0) || any(as.numeric(tab$strokeAlpha)>1)) 289 | stop("stroke.alpha must be comprise between 0 and 1") 290 | if (any(as.numeric(tab$strokeLwd)<0)) 291 | stop("stroke.lwd must be positive") 292 | if (any(as.numeric(tab$fillAlpha)<0) || any(as.numeric(tab$fillAlpha)>1)) 293 | stop("fill.alpha must be comprise between 0 and 1") 294 | 295 | if("label" %in% tested.names) 296 | tab$label <- paste("\"", as.character(tab$label), "\"", sep="") 297 | if("popup" %in% tested.names){ 298 | if(popup.rmd){ 299 | tab$popup <- sapply(as.vector(tab$popup), function(x) knitr::knit2html(output = NULL, text = x, 300 | options = c('fragment_only', 'base64_images'))) 301 | tab$popup <- gsub("\\n", "
", tab$popup) 302 | tab$popup <- gsub("\"", "\\\\\"", tab$popup) 303 | } 304 | tab$popup <- paste("\"", as.character(tab$popup), "\"", sep="") 305 | } 306 | class(tab) <- c("splpolygons") 307 | return(tab) 308 | 309 | } 310 | 311 | #'Define a Raster Data Layer 312 | #' 313 | #'\code{spLayer.SpatialGridDataFrame} defines a new data layer from an object \code{SpatialGridDataFrame}. 314 | #' 315 | #'@param name a character string to name the layer. 316 | #'@param x a spatial object (see Details). 317 | #'@param layer which layer to select? 318 | #'@param cells.col a vector of any of the three kinds of \R color specifications giving a gradient to color the grid. 319 | #'@param cells.alpha a vector of numeric values in \eqn{[0, 1]} setting grid opacity. 320 | #'@param legend a legend object created with \code{\link{layerLegend}}. 321 | #'@param ... additional arguments to pass to the function. 322 | #' 323 | #'@method spLayer SpatialGridDataFrame 324 | #'@export 325 | spLayer.SpatialGridDataFrame <- function(x, name = NULL, layer, 326 | cells.col = heat.colors(12), cells.alpha = 1, 327 | legend = NULL, ...){ 328 | if(!inherits(x, "SpatialGridDataFrame")) 329 | stop("x must be an object of class SpatialGridDataFrame") 330 | spLayerControl(name = name, legend = legend) 331 | 332 | x <- x[layer] 333 | x.bbox <- bbox(x) 334 | 335 | if(is.na(proj4string(x))){ 336 | proj4string(x) <- CRS("+init=epsg:4326") 337 | warning("The coordinate system of the grid has not been recognized. It is assumed to be EPSG:4326") 338 | } 339 | 340 | x <- raster(x, layer = 1) 341 | x <- projectRaster(from = x, projectExtent(x, crs = CRS("+init=epsg:3857"))) 342 | x <- as(x, "SpatialGridDataFrame") 343 | 344 | cells.col <- col2hexa(cells.col, alpha.channel = TRUE, alpha = cells.alpha, charstring = FALSE) 345 | legend$layer <- name 346 | tab <- list(x = x, name = name, cells.col = cells.col, x.bbox = x.bbox, legend = legend) 347 | 348 | class(tab) <- c("splgrid") 349 | return(tab) 350 | } 351 | 352 | 353 | #' Testing user inputs 354 | #' 355 | #' This function tests arguments validity for the function \code{\link{spLayer}}. 356 | #' @inheritParams spLayer.SpatialPoints 357 | #' @param holes a logical indicating whether to use the \code{hole} slots of the \code{SpatialPolygons} object. 358 | #' 359 | spLayerControl <- function(name, size = 1, legend = legend, 360 | stroke = TRUE, stroke.col = 1, stroke.lwd = 1, stroke.lty = 1, stroke.alpha = 1, 361 | fill = TRUE, fill.col = 1, fill.alpha = 1, label = "", popup = "", holes = FALSE){ 362 | if(!is.null(name)){ 363 | if(is.vector(name) && length(name)==1){ 364 | name <- as.character(name) 365 | }else{ 366 | stop("name must be a single value character vector") 367 | } 368 | } 369 | if(!is.numeric(size)){ 370 | stop("size must be numeric") 371 | }else{ 372 | if(any(is.na(size))) 373 | stop(("Missing value for size not allowed")) 374 | if(any(size<0)) 375 | stop("size must be positive") 376 | } 377 | if(!is.null(legend)){ 378 | if(!inherits(legend, "layerlegend")){ 379 | stop("The legend is not valid. Objects passed with the 'legend' argument must be created with the 'layerLegend' function.") 380 | } 381 | } 382 | if(!is.logical(stroke)) 383 | stop("stroke must be set on TRUE or FALSE") 384 | 385 | if(!is.logical(fill)) 386 | stop("fill must be set on TRUE or FALSE") 387 | 388 | if(!is.logical(holes)) 389 | stop("holes must be set on TRUE or FALSE") 390 | } 391 | 392 | 393 | -------------------------------------------------------------------------------- /R/toGeoJSON.R: -------------------------------------------------------------------------------- 1 | #' Convert a spl object to GeoJSON format 2 | #' 3 | #' This function is used internally by \code{\link{writeMap}} to convert a given \code{spl} object to GeoJSON format. 4 | #' @param x a \code{spl} object. 5 | #' @param lightjson logical. Should GeoJSON code size be reduced by supressing extra whitespace characters and rounding numeric values? 6 | #' 7 | #' @return A character string of GeoJSON formatted code. 8 | #' 9 | toGeoJSON <- function(x, lightjson=F){ 10 | x.class <- class(x) 11 | x <- as.list(x) 12 | name.x <- safeVar(x["name"]) 13 | coords.x <- x$coords 14 | if(lightjson){ 15 | coords.x <- lapply(coords.x, function(x) lapply(x, round, digits=5)) 16 | } 17 | holes.x <- x$holes 18 | order.x <- x$order 19 | x <- x[!names(x) %in% c("name", "coords", "holes", "order", "legend")] 20 | props <- paste("\"", names(x), "\"", sep="") 21 | lix <- list() 22 | 23 | for(i in 1:length(x[[1]])){ 24 | lix[[i]] <- vector() 25 | for(j in 1:length(props)){ 26 | lix[[i]][j] <- paste("\t\t\t", props[j], ": ", x[[j]][i], sep="") 27 | } 28 | } 29 | 30 | lix <- lapply(lix, paste, collapse=",\n") 31 | 32 | if(x.class == "splpoints"||x.class == "splicons"){ 33 | coor <- coords2json(coords.x, x.class) 34 | res <- mapply(function(a, b) paste("\n\n{\"type\":\"Feature\",\n\"properties\": {\n", a, "},\n\"geometry\": {\n\"type\": \"Point\",\n\"coordinates\": ", b, "}}", collapse=",\n"), 35 | a=lix, b=coor) 36 | } 37 | 38 | if(x.class == "spllines"){ 39 | coor <- coords2json(coords.x, x.class) 40 | res <- mapply(function(a, b) paste("\n\n{\"type\":\"Feature\",\n\"properties\": {\n", a, "},\n\"geometry\": {\n\"type\": \"MultiLineString\",\n\"coordinates\": ", b, "}}", collapse=",\n"), 41 | a=lix, b=coor) 42 | } 43 | 44 | if(x.class == "splpolygons"){ 45 | coor <- coords2json(coords.x, x.class, holes.x, order.x) 46 | res <- mapply(function(a, b) paste("\n\n{\"type\":\"Feature\",\n\"properties\": {\n", a, "},\n\"geometry\": {\n\"type\": \"MultiPolygon\",\n\"coordinates\": ", b, "}}", collapse=",\n"), 47 | a=lix, b=coor) 48 | } 49 | 50 | res <- paste(res, collapse=",") 51 | if(lightjson){ 52 | res <- gsub(" ", "", res) 53 | res <- gsub("\n", "", res) 54 | res <- gsub("\t", "", res) 55 | } 56 | res <- paste("var ", name.x, " = [", res, "\n]", sep="") 57 | return(res) 58 | } 59 | -------------------------------------------------------------------------------- /R/toJS.R: -------------------------------------------------------------------------------- 1 | #' Generate Leaflet JS code for a given layer 2 | #' 3 | #' This function is used internally by \code{\link{writeMap}} to generate Leaflet JavaScript code for a given layer. 4 | #' @param x a \code{spl} or \code{basemap} object. 5 | #' @param url a character string giving the path for the raster files. 6 | #' 7 | #' @return A character string of JavaScript Code. 8 | toJS <- function(x, url=""){ # x is an spl or bm object 9 | 10 | if(is(x, "basemap")){ 11 | if(!is.null(x$URL.cr)){ 12 | credits <- paste("attribution: '", x$URL.cr, "',\n", sep="") 13 | } else { 14 | credits <- "" 15 | } 16 | res <- paste("var ", safeVar(x$name), "BaseMap = L.tileLayer('", x$URL, "', {\n", 17 | "opacity: ", x$alpha, ",\n", 18 | "minZoom: ", x$minZoom, ",\n", 19 | "maxZoom: ", x$maxZoom, ",\n", 20 | "tileSize: ", x$tileSize, ",\n", 21 | "tms: ", x$tms, ",\n", 22 | credits, 23 | "}).addTo(map);", sep="") 24 | } 25 | 26 | if(is(x, "splpoints")){ 27 | res <- paste("var ", safeVar(x$name), "Points = L.geoJson(", safeVar(x$name), ", { 28 | pointToLayer: function (feature, latlng) { 29 | return L.circleMarker(latlng); 30 | }, 31 | style: function (feature){ 32 | return { 33 | radius: feature.properties.size, 34 | stroke: feature.properties.stroke, 35 | color: feature.properties.strokeCol, 36 | weight: feature.properties.strokeLwd, 37 | dashArray: feature.properties.strokeLty, 38 | opacity: feature.properties.strokeAlpha, 39 | fill: feature.properties.fill, 40 | fillColor: feature.properties.fillCol, 41 | fillOpacity: feature.properties.fillAlpha 42 | }; 43 | }, 44 | onEachFeature: function(feature, layer){ 45 | if (feature.properties.popup) { 46 | layer.bindPopup(feature.properties.popup); 47 | } 48 | } 49 | }).addTo(map);", sep="") 50 | } 51 | 52 | if(is(x, "splicons")){ 53 | res <- paste("var ", safeVar(x$name), "Icons = L.geoJson(", safeVar(x$name), ", { 54 | pointToLayer: function (feature, latlng) { 55 | return L.marker(latlng, {icon: L.icon({iconUrl: feature.properties.png, iconSize: feature.properties.size})}); 56 | }, 57 | onEachFeature: function(feature, layer){ 58 | if (feature.properties.popup) { 59 | layer.bindPopup(feature.properties.popup); 60 | } 61 | } 62 | }).addTo(map);", sep="") 63 | } 64 | 65 | if(is(x, "spllines")){ 66 | res <- paste("var ", safeVar(x$name), "Lines = L.geoJson(", safeVar(x$name), ", { 67 | style: function (feature){ 68 | return { 69 | stroke: feature.properties.stroke, 70 | color: feature.properties.strokeCol, 71 | weight: feature.properties.strokeLwd, 72 | dashArray: feature.properties.strokeLty, 73 | opacity: feature.properties.strokeAlpha, 74 | }; 75 | }, 76 | onEachFeature: function(feature, layer){ 77 | if (feature.properties.popup) { 78 | layer.bindPopup(feature.properties.popup); 79 | } 80 | } 81 | }).addTo(map);", sep="") 82 | } 83 | 84 | if(is(x, "splpolygons")){ 85 | res <- paste("var ", safeVar(x$name), "Polygons = L.geoJson(", safeVar(x$name), ", { 86 | style: function (feature){ 87 | return { 88 | stroke: feature.properties.stroke, 89 | color: feature.properties.strokeCol, 90 | weight: feature.properties.strokeLwd, 91 | dashArray: feature.properties.strokeLty, 92 | opacity: feature.properties.strokeAlpha, 93 | fill: feature.properties.fill, 94 | fillColor: feature.properties.fillCol, 95 | fillOpacity: feature.properties.fillAlpha 96 | }; 97 | }, 98 | onEachFeature: function(feature, layer){ 99 | if (feature.properties.popup) { 100 | layer.bindPopup(feature.properties.popup); 101 | } 102 | } 103 | }).addTo(map);", sep="") 104 | } 105 | 106 | if(is(x, "splgrid")){ 107 | bb <- x$x.bbox 108 | res <- paste("var ", safeVar(x$name), "Raster = L.imageOverlay(\"", url, "\", [[", 109 | bb[2,1], ",", bb[1,1], "],[",bb[2,2], ",",bb[1,2], "]]", 110 | ").addTo(map);", sep="") 111 | } 112 | 113 | return(res) 114 | } 115 | -------------------------------------------------------------------------------- /R/ui.R: -------------------------------------------------------------------------------- 1 | #' Options settings for map interface 2 | #' 3 | #' Allow the user to choose which interface elements are displayed on the map and their positions. 4 | #' @param zoom a character string indicating if and how should the zoom control be displayed. 5 | #' This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}" 6 | #' @param layers a character string indicating if and how should the layers control be displayed. 7 | #' This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}" 8 | #' @param attrib a character string indicating if and how should the attribution control be displayed. 9 | #' This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}" 10 | #' @param attrib.text a character string for additionnal credits. HTML tags are accepted. 11 | #' 12 | #' @export 13 | #' @return An object of class \code{ui} which can be directly given as \code{interface} argument of \code{\link{writeMap}}. 14 | ui <- function(zoom=c("topleft", "topright", "bottomleft", "bottomright", "none"), 15 | layers=c("none", "topright", "topleft", "bottomleft", "bottomright"), 16 | attrib=c("bottomright", "topleft", "topright", "bottomleft", "none"), 17 | attrib.text=""){ 18 | res <- list(zoom=match.arg(zoom), 19 | layers=match.arg(layers), 20 | attrib=match.arg(attrib), 21 | attrib.text=attrib.text) 22 | class(res) <- "ui" 23 | return(res) 24 | } 25 | 26 | #' Generate user interface JS code 27 | #' 28 | #' This function is used internally by \code{\link{writeMap}} to generate JavaScript code 29 | #' related to the user interface. 30 | #' @param interface an \code{ui} object created with \code{\link{ui}}. 31 | #' @param ar a list of \code{basemap} and \code{spl} objects. 32 | uiJS <- function(interface, ar){ 33 | if(is.null(interface)){ 34 | interface <- ui() 35 | } 36 | if(!is(interface, "ui")){ 37 | stop("interface must be of class 'ui'") 38 | } 39 | if(interface$zoom != "none"){ 40 | zoomInterface <- paste("L.control.zoom({position:'", interface$zoom, "'}).addTo(map);", sep="") 41 | } else { 42 | zoomInterface <- "" 43 | } 44 | if(interface$attrib != "none"){ 45 | attribInterface <- paste("var attrib = L.control.attribution({prefix:false, position:'", interface$attrib, "'}).addTo(map);\n 46 | attrib.addAttribution(\"", interface$attrib.text,"\");", sep="") 47 | } else { 48 | attribInterface <- "" 49 | } 50 | 51 | if(interface$layers != "none"){ 52 | arNames <- xvarnames(ar) 53 | arNames.bl <- arNames[arNames$xclass == "basemap",] 54 | arNames.ol <- arNames[arNames$xclass != "basemap",] 55 | if(dim(arNames.bl)[1] == 0){ 56 | bl.js <- "var baseMaps = 1" 57 | }else{ 58 | bl.list <- paste("\"", arNames.bl$xname, "\" : ", arNames.bl$xvarname, sep="", collapse=",\n") 59 | bl.js <- paste("var baseMaps = {\n", bl.list, "\n};", sep="") 60 | } 61 | if(dim(arNames.ol)[1] == 0){ 62 | ol.js <- "var overlayMaps = 1" 63 | }else{ 64 | ol.list <- paste("\"", arNames.ol$xname, "\" : ", arNames.ol$xvarname, sep="", collapse=",\n") 65 | ol.js <- paste("var overlayMaps = {\n", ol.list, "\n};", sep="") 66 | } 67 | ctrl <- paste("L.control.layers(baseMaps, overlayMaps, {position:'", interface$layers, "'}).addTo(map);", sep="") 68 | layersInterface <- paste(bl.js, ol.js, ctrl, sep="\n") 69 | } else { 70 | layersInterface <- "" 71 | } 72 | 73 | res <- list(ui.1 = paste(zoomInterface, attribInterface, sep = "\n\n"), ui.2 = layersInterface) 74 | return(res) 75 | } -------------------------------------------------------------------------------- /R/utilities.R: -------------------------------------------------------------------------------- 1 | 2 | coords2json <- function(x, type, holes=NULL, order=NULL){ #x=coords; holes=booleans vector; type=class 3 | if(type=="splpoints"||type=="splicons"){ 4 | res <- paste("[", x[,1], ", ", x[,2], "]", sep="") 5 | } 6 | if(type=="spllines"){ 7 | res <- lapply(x, function(x) lapply(x, proclines)) 8 | res <- lapply(res, function(x) do.call("paste", c(x, sep=", "))) 9 | res <- lapply(res, function(x) paste("[", x, "]", sep="")) 10 | } 11 | if(type=="splpolygons"){ 12 | if(is.null(holes)){ 13 | res <- lapply(x, function(x) lapply(x, procpolys)) 14 | res <- lapply(res, function(x) do.call("paste", c(x, sep=", "))) 15 | res <- lapply(res, function(x) paste("[", x, "]", sep="")) 16 | } else { 17 | res <- lapply(x, function(x) lapply(x, procpolys)) 18 | res <- mapply(function(a, b) a[b], a=res, b=order) 19 | holes <- mapply(function(a, b) a[b], a=holes, b=order) 20 | res <- mapply(holify, a=holes, b=res) 21 | res <- lapply(res, function(x) do.call("paste", c(x, sep=", "))) 22 | res <- lapply(res, function(x) paste("[", x, "]", sep="")) 23 | } 24 | } 25 | return(res) 26 | } 27 | 28 | holify <- function(a, b){ 29 | for(i in 1:length(a)){ 30 | if (a[i]==T && i>1){ 31 | b[i-1] <- substr(b[i-1], 1, nchar(b[i-1])-1) 32 | b[i] <- substr(b[i], 2, nchar(b[i])) 33 | } 34 | } 35 | return(b) 36 | } 37 | 38 | polycoords <- function(x){ #Extrait les coordonnees d'un objet SpatialPolygons 39 | res <- x@polygons 40 | res <- lapply(res, function(x) x@Polygons) 41 | res <- lapply(res, function(x) lapply(x, coordinates)) 42 | return(res) 43 | } 44 | 45 | polyholes <- function(x){ #Extrait les slots 'hole' d'un objet SpatialPolygons 46 | res <- x@polygons 47 | res <- lapply(res, function(x) x@Polygons) 48 | res <- lapply(res, function(x) lapply(x, function(x) x@hole)) 49 | return(res) 50 | } 51 | 52 | polyorder <- function(x){ #Extrait les slots 'plotOrder' d'un objet SpatialPolygons 53 | res <- x@polygons 54 | res <- lapply(res, function(x) x@plotOrder) 55 | return(res) 56 | } 57 | 58 | proclines <- function(x) { 59 | res <- paste("[", x[,1], ", ",x[,2], "]", sep="", collapse=", ") 60 | res <- paste("[", res, "]", sep="") 61 | } 62 | 63 | procpolys <- function(x) { 64 | res <- paste("[", x[,1], ", ",x[,2], "]", sep="", collapse=", ") 65 | res <- paste("[[", res, "]]", sep="") 66 | } 67 | 68 | pngasp <- function(x){ #x is an sp bounding box. 69 | xlim <- x[1,] 70 | ylim <- x[2,] 71 | asp <- (diff(ylim)/diff(xlim))/cos((mean(ylim) * pi)/180) 72 | names(asp) <- NULL 73 | return(asp) 74 | } 75 | 76 | 77 | class2var <- function(x){ 78 | switch(x, 79 | "basemap"="BaseMap", 80 | "splpoints"="Points", 81 | "splicons"="Icons", 82 | "spllines"="Lines", 83 | "splpolygons"="Polygons", 84 | "splgrid"="Raster") 85 | } 86 | 87 | xvarnames <- function(x){ #x est une liste d'objets spl 88 | xclass <- sapply(x, function(x) return(class(x))) 89 | xname <- sapply(x, function(x) return(x$name)) 90 | xvarclass <- sapply(xclass, class2var) 91 | xvarname <- paste(safeVar(xname), xvarclass, sep="") 92 | res <- data.frame(xclass, xname, xvarname) 93 | return (res) 94 | } 95 | 96 | safeVar <- function(x){ 97 | x <- gsub("[^A-Za-z0-9]", "", x) 98 | test1 <- grepl("[0-9]", substr(x, 1, 1)) 99 | substr(x[test1], 1, 1) <- letters[as.numeric(substr(x[test1], 1, 1))+1] 100 | 101 | if(any(x == "")){ 102 | stop("Incorrect value for name") 103 | } 104 | return(x) 105 | } 106 | 107 | cleanDepsub <- function(x){ 108 | x <- paste(x, collapse="") 109 | x <- substr(x, 5, nchar(x)) 110 | x <- gsub("\\(", "", x) 111 | x <- gsub("\\)", "", x) 112 | x <- gsub(" ", "", x) 113 | x <- strsplit(x, ",") 114 | return(x) 115 | } 116 | 117 | #' Convert colors to hexadecimal format 118 | #' 119 | #' This function converts any color of the \R system to hexadecimal format. 120 | #' @param x a vector of any of the three kinds of \R color specifications. 121 | #' @param alpha.channel logical. Sould an alpha channel included in the output? Default is \code{FALSE}. 122 | #' @param alpha a vector of numeric values in \eqn{[0, 1]}. Recycled if necessary. 123 | #' @param charstring logical. Sould resulting elements be surrounded by quotation marks? Default is \code{TRUE}. 124 | #' 125 | #' @return A character vector of hexadecimal values. 126 | #' 127 | #' @seealso \code{\link[grDevices]{col2rgb}} for translating \R colors to RGB vectors. 128 | #' @export 129 | #' @keywords internal 130 | col2hexa <- function(x, alpha.channel=FALSE, alpha=1, charstring=TRUE){ 131 | col <- col2rgb(x) 132 | if(alpha.channel){ 133 | alpha <- as.integer(alpha*255) 134 | col <- rgb(red=col[1,], green=col[2,], blue=col[3,], alpha=alpha, maxColorValue = 255) 135 | } else { 136 | col <- rgb(red=col[1,], green=col[2,], blue=col[3,], maxColorValue = 255) 137 | } 138 | if(charstring){ 139 | col <- paste("\"", col, "\"", sep="") 140 | } 141 | return(col) 142 | } 143 | 144 | 145 | #' Basemap Tiles Servers 146 | #' 147 | #' Print a list of tiles servers ready-to-use with \code{\link{basemap}}. 148 | #' 149 | #' @param print.servers logical. Should the names of the servers be printed? 150 | #' @return Returns invisibly a matrix with servers names, urls and credits. 151 | #' @export 152 | bmSource <- function(print.servers=TRUE){ 153 | bm.source <- matrix(c( 154 | "mapquest.map", "http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.jpg", 155 | "mapquest.sat", "http://otile1.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg", 156 | "stamen.toner", "http://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.png", 157 | "stamen.toner.hybrid", "http://tile.stamen.com/toner-hybrid/{z}/{x}/{y}.png", 158 | "stamen.toner.labels", "http://tile.stamen.com/toner-labels/{z}/{x}/{y}.png", 159 | "stamen.toner.lines", "http://tile.stamen.com/toner-lines/{z}/{x}/{y}.png", 160 | "stamen.toner.background", "http://stamen-tiles-{s}.a.ssl.fastly.net/toner-background/{z}/{x}/{y}.png", 161 | "stamen.toner.lite", "http://stamen-tiles-{s}.a.ssl.fastly.net/toner-lite/{z}/{x}/{y}.png", 162 | "stamen.watercolor", "http://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.png", 163 | "cartodb.positron", "http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png", 164 | "cartodb.positron.nolab", "http://{s}.basemaps.cartocdn.com/light_nolabels/{z}/{x}/{y}.png", 165 | "cartodb.darkmatter", "http://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png", 166 | "cartodb.darkmatter.nolab", "http://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png" 167 | ), ncol=2, byrow=T) 168 | 169 | mapquest.tiles.cr <- "Tiles: MapQuest" 170 | stamen.tiles.cr <- "Tiles: Stamen Design" 171 | cartodb.tiles.cr <- "Tiles: CartoDB" 172 | osm.data.cr <- "Data: OSM" 173 | nasa.data.cr <- "Data: NASA..." 174 | 175 | 176 | mapquest.map.cr <- paste(mapquest.tiles.cr, osm.data.cr, sep=" | ") 177 | mapquest.sat.cr <- paste(mapquest.tiles.cr, nasa.data.cr, sep=" | ") 178 | stamen.cr <- paste(stamen.tiles.cr, osm.data.cr, sep=" | ") 179 | cartodb.cr <- paste(cartodb.tiles.cr, osm.data.cr, sep=" | ") 180 | vec.cr <- c(mapquest.map.cr, mapquest.sat.cr, rep(stamen.cr, 7), rep(cartodb.cr, 4)) 181 | bm.source <- cbind(bm.source, vec.cr) 182 | if(print.servers){ 183 | cat(paste(bm.source[,1], collapse="\n")) 184 | } 185 | invisible(bm.source) 186 | } 187 | 188 | #' Tiles Servers URL 189 | #' 190 | #' Take a tiles server name (as returned by \code{\link{bmSource}}) and return its url. 191 | #' 192 | #' @param x a character string of the name of the server. 193 | #' @return The url of the server. 194 | bmServer <- function(x){ 195 | bm.source <- bmSource(print.servers=FALSE) 196 | res <- bm.source[bm.source[,1]==x,2] 197 | if(length(res) == 0L){ 198 | res <- x 199 | } 200 | return(res) 201 | } 202 | 203 | 204 | #' Tiles Servers Attribution 205 | #' 206 | #' Take a tiles server url and return its attribution. 207 | #' 208 | #' @param x a character string of the url of the server. 209 | #' @return The attribution of the server. 210 | bmCredit <- function(x){ 211 | bm.source <- bmSource(print.servers=FALSE) 212 | res <- bm.source[bm.source[,2]==x,3] 213 | if(length(res) == 0L){ 214 | res <- NULL 215 | } 216 | return(res) 217 | } 218 | 219 | 220 | # Get the global bounding box of the data included in a map 221 | .getExtBox <- function(sppts, spico, splns, sppol, spgrid){ 222 | if(length(sppts) > 0){ 223 | sppts.bb <- t(sapply(sppts, function(x) c(min(x$coords[, 1]), max(x$coords[, 1]), 224 | min(x$coords[, 2]), max(x$coords[, 2])))) 225 | } else { 226 | sppts.bb <- rep(NA, 4) 227 | } 228 | 229 | if(length(spico) > 0){ 230 | spico.bb <- t(sapply(spico, function(x) c(min(x$coords[, 1]), max(x$coords[, 1]), 231 | min(x$coords[, 2]), max(x$coords[, 2])))) 232 | } else { 233 | spico.bb <- rep(NA, 4) 234 | } 235 | 236 | if(length(splns) > 0){ 237 | splns.bb <- t(sapply(splns, function(x){z <- do.call("rbind", unlist(x$coords, recursive=FALSE)); 238 | return(c(min(z[, 1]), max(z[, 1]), min(z[, 2]), max(z[, 2])))})) 239 | } else { 240 | splns.bb <- rep(NA, 4) 241 | } 242 | 243 | if(length(sppol) > 0){ 244 | sppol.bb <- t(sapply(sppol, function(x){z <- do.call("rbind", unlist(x$coords, recursive=FALSE)); 245 | return(c(min(z[, 1]), max(z[, 1]), min(z[, 2]), max(z[, 2])))})) 246 | } else { 247 | sppol.bb <- rep(NA, 4) 248 | } 249 | 250 | if(length(spgrid) > 0){ 251 | spgrid.bb <- t(sapply(spgrid, function(x) as.vector(x$x.bbox)[c(1,3,2,4)])) 252 | } else { 253 | spgrid.bb <- rep(NA, 4) 254 | } 255 | 256 | extbox <- rbind(sppts.bb, spico.bb, splns.bb, sppol.bb, spgrid.bb) 257 | extbox <- c(min(extbox[, 1], na.rm = TRUE), 258 | max(extbox[, 2], na.rm = TRUE), 259 | min(extbox[, 3], na.rm = TRUE), 260 | max(extbox[, 4], na.rm = TRUE)) 261 | return(extbox) 262 | } -------------------------------------------------------------------------------- /R/writemap.R: -------------------------------------------------------------------------------- 1 | #' Export and display the map 2 | #' 3 | #' This function combines all the elements specified by the user and write 4 | #' the corresponding HTML and Javascript code in a local directory. 5 | #' 6 | #' @param ... \code{basemap} and \code{spl} objects to embed into the map 7 | #' @param dir a character string giving the directory path to export the map. 8 | #' Default is the working directory. 9 | #' @param prefix a character string to add a prefix to file names. 10 | #' This allows multiple exportations in the same directory. 11 | #' @param width,height the width and height of the map, in pixels. 12 | #' @param setView a numeric vector of the form \code{c(x, y)} 13 | #' setting the initial geographical center of the map. 14 | #' @param setZoom a numeric value setting the initial map zoom. 15 | #' @param interface an \code{ui} object created with \code{\link{ui}} 16 | #' to customize the interface controls. 17 | #' @param lightjson logical. Should GeoJSON files size be reducedby supressing 18 | #' extra whitespace characters and rounding numeric values? Default is \code{FALSE}. 19 | #' This is currently not compatible with RMarkdown popups. 20 | #' @param directView a character string indicating if and how should the map be displayed. 21 | #' Default option "\code{viewer}" uses (if available) the RStudio HTML viewer to display the map, 22 | #' "\code{browser}" opens the map into the web browser and "\code{disabled}" disables direct display. 23 | #' @param leaflet.loc a character string specifying the location (directory) of the leaflet library. 24 | #' If set to "\code{online}" (default), the library is loaded from the leaflet 25 | #' official CDN and requires an internet connection. 26 | #' @param popup.style an optional character string of CSS to customize popups content properties (width, color, etc). 27 | #' 28 | #' @export 29 | writeMap <- function(..., dir=getwd(), prefix="", width=700, height=400, 30 | setView=NULL, setZoom=NULL, 31 | interface=NULL, lightjson=FALSE, 32 | directView=c("viewer", "browser", "disabled"), 33 | leaflet.loc="online", popup.style = NULL){ 34 | ar <- list(...) 35 | depsub <- deparse(substitute(list(...))) 36 | depsub <- unlist(cleanDepsub(depsub)) 37 | for(i in 1:length(ar)){ 38 | if(is.null(ar[[i]]$name)){ 39 | ar[[i]]$name <- depsub[i] 40 | } 41 | if(!is.null(ar[[i]]$legend)){ 42 | ar[[i]]$legend$layer <- depsub[i] 43 | ar[[i]]$legend$layer.name <- ar[[i]]$name 44 | if(is.null(ar[[i]]$legend$title)){ 45 | ar[[i]]$legend$title <- ar[[i]]$name 46 | } 47 | } 48 | } 49 | 50 | viewer <- getOption("viewer") 51 | user.view <- match.arg(directView) 52 | map.file <- paste(dir, "/", prefix,"_map.html", sep="") 53 | map.file.tmp <- paste(tempdir(), "/", prefix,"_map.html", sep="") 54 | 55 | writeMapInternal(ar=ar, dir=dir, prefix=prefix, width=width, height=height, setView=setView, 56 | setZoom=setZoom, interface=interface, 57 | lightjson=lightjson, leaflet.loc=leaflet.loc, popup.style = popup.style) 58 | 59 | if(user.view == "browser"){ 60 | browseURL(map.file) 61 | } 62 | if(user.view == "viewer"){ 63 | if(is.null(viewer)){ 64 | warning("Cannot render in HTML viewer pane (require RStudio v.>0.98.5). 65 | Use 'directView' argument to render into your browser.") 66 | } else { 67 | 68 | writeMapInternal(ar=ar, dir=tempdir(), prefix=prefix, width=width, 69 | height=height, setView=setView, 70 | setZoom=setZoom, interface=interface, 71 | lightjson=lightjson, leaflet.loc=leaflet.loc, popup.style = popup.style) 72 | if(leaflet.loc != "online"){ 73 | # file.copy(from=paste(leaflet.loc, "/leaflet.css", sep=""), to=tempdir(), overwrite=T) 74 | # file.copy(from=paste(leaflet.loc, "/leaflet.js", sep=""), to=tempdir(), overwrite=T) 75 | # file.copy(from=paste(leaflet.loc, "/images", sep=""), to=tempdir(), overwrite=T) 76 | warning("Cannot render in HTML viewer pane with a local copy of Leaflet.") 77 | } 78 | viewer(map.file.tmp) 79 | } 80 | } 81 | } 82 | 83 | 84 | 85 | 86 | writeMapInternal <- function(ar, dir, prefix, width, height, setView, setZoom, 87 | interface, lightjson, leaflet.loc, popup.style){ 88 | 89 | ar.valid.class <- sapply(ar, function(x) is(x, "basemap") || is(x, "splpoints") || is(x, "splicons") || is(x, "spllines") || is(x, "splpolygons") || is(x, "splgrid")) 90 | if (any(ar.valid.class==FALSE)){ 91 | stop("Invalid data format") 92 | } 93 | ar.names <- sapply(ar, function(x) return(safeVar(x$name))) 94 | if(any(duplicated(ar.names))){ 95 | stop("Elements with duplicated names: ", 96 | paste(ar.names[duplicated(ar.names) | duplicated(ar.names, fromLast = TRUE)], collapse=", ") 97 | ) 98 | } 99 | 100 | data.dir <- paste(dir, "/", prefix,"_data", sep="") 101 | if(!file.exists(data.dir)) 102 | dir.create(data.dir) 103 | icons.dir <- paste0(data.dir, "/", prefix, "_icons") 104 | if(!file.exists(icons.dir)) 105 | dir.create(icons.dir) 106 | icons.legend.dir <- paste0(icons.dir, "/", prefix, "_legend_icons") 107 | if(!file.exists(icons.legend.dir)) 108 | dir.create(icons.legend.dir) 109 | 110 | #Include html+css code 111 | inc.encoding <- incEncoding(code = "UTF-8") 112 | inc.leaflet <- incLeaflet(loc = leaflet.loc) 113 | inc.data <- incData(prefix = prefix) 114 | init.map0 <- initMap0(height = height, width = width) 115 | init.map1 <- initMap1(setView, setZoom) 116 | if(is.null(popup.style)){ 117 | popup.style <- incPopupCSS(height = height, width = width) 118 | } else { 119 | popup.style <- paste0(".leaflet-popup-content {", popup.style, "}") 120 | } 121 | inc.extra.css <- paste("", sep = "\n\n") 126 | 127 | #Interface Controls 128 | ui.js <- uiJS(interface = interface, ar = ar) 129 | ui.js.1 <- ui.js$ui.1 130 | ui.js.2 <- ui.js$ui.2 131 | legend.js <- lapply(ar[sapply(ar, function(x) !is.null(x$legend))], function(x) processLegend(x$legend, icons.legend.dir = icons.legend.dir, prefix = prefix)) 132 | legend.js <- paste0(legend.js, collapse = "\n\n") 133 | 134 | # Base Map 135 | bm <- ar[sapply(ar, function(x) is(x, "basemap"))] 136 | bm.js <- lapply(bm, toJS) 137 | bm.js <- do.call("paste", c(bm.js, sep = "\n\n")) 138 | 139 | # Points 140 | sppts <- ar[sapply(ar, function(x) is(x, "splpoints"))] 141 | sppts.json <- lapply(sppts, toGeoJSON, lightjson = lightjson) 142 | sppts.json <- do.call("paste", c(sppts.json, sep = "\n\n\n\n")) 143 | out <- file(paste0(data.dir, "/", prefix, "_datapoints.js"), open = "w") 144 | cat(iconv(sppts.json, to = "UTF-8"), file = out) 145 | close(con = out) 146 | rm(out) 147 | sppts.js <- lapply(sppts, toJS) 148 | sppts.js <- do.call("paste", c(sppts.js, sep = "\n\n")) 149 | 150 | # Icons 151 | spico <- ar[sapply(ar, function(x) is(x, "splicons"))] 152 | icons.list <- lapply(spico, function(x) x$png) 153 | icons.list <- levels(as.factor(do.call("c", icons.list))) 154 | file.copy(from = icons.list, to = icons.dir) 155 | spico <- lapply(spico, function(x) { 156 | x$png <- paste("\"", prefix, "_data", "/", prefix, "_icons", "/", 157 | gsub("(.*\\/)([^.]+\\.[[:alnum:]]+$)","\\2", x$png), "\"", 158 | sep="") 159 | return(x) 160 | }) 161 | spico.json <- lapply(spico, toGeoJSON, lightjson = lightjson) 162 | spico.json <- do.call("paste", c(spico.json, sep="\n\n\n\n")) 163 | out <- file(paste0(data.dir, "/", prefix, "_dataicons.js"), open = "w") 164 | cat(iconv(spico.json, to = "UTF-8"), file = out) 165 | close(con = out) 166 | rm(out) 167 | spico.js <- lapply(spico, toJS) 168 | spico.js <- do.call("paste", c(spico.js, sep = "\n\n")) 169 | 170 | # Lines 171 | splns <- ar[sapply(ar, function(x) is(x, "spllines"))] 172 | splns.json <- lapply(splns, toGeoJSON, lightjson = lightjson) 173 | splns.json <- do.call("paste", c(splns.json, sep = "\n\n\n\n")) 174 | out <- file(paste0(data.dir, "/", prefix, "_datalines.js"), open = "w") 175 | cat(iconv(splns.json, to = "UTF-8"), file = out) 176 | close(con = out) 177 | rm(out) 178 | splns.js <- lapply(splns, toJS) 179 | splns.js <- do.call("paste", c(splns.js, sep = "\n\n")) 180 | 181 | # Polygons 182 | sppol <- ar[sapply(ar, function(x) is(x, "splpolygons"))] 183 | sppol.json <- lapply(sppol, toGeoJSON, lightjson = lightjson) 184 | sppol.json <- do.call("paste", c(sppol.json, sep = "\n\n\n\n")) 185 | out <- file(paste0(data.dir, "/", prefix, "_datapolygons.js"), open = "w") 186 | cat(iconv(sppol.json, to = "UTF-8"), file = out) 187 | close(con = out) 188 | rm(out) 189 | sppol.js <- lapply(sppol, toJS) 190 | sppol.js <- do.call("paste", c(sppol.js, sep= "\n\n")) 191 | 192 | #Rasters 193 | spgrid <- ar[sapply(ar, function(x) is(x, "splgrid"))] 194 | raster.dir <- paste(data.dir, "/", prefix, "_rasters", sep = "") 195 | if(!file.exists(raster.dir)) 196 | dir.create(raster.dir) 197 | spgrid.js <- lapply(spgrid, function(x){ 198 | if(!capabilities("png")){ 199 | warning("The png function is not operational on this system.") 200 | } 201 | url <- paste(raster.dir, "/", prefix, "_", safeVar(x$name), ".png", sep = "") 202 | spgrid.js <- toJS(x, paste(prefix, "_data", "/", prefix, "_rasters", "/", prefix, "_", safeVar(x$name), ".png", sep = "")) 203 | png(url, bg = "transparent", width = 1200, height = round(1200 * pngasp(x$x.bbox))) 204 | par(mar = c(0, 0, 0, 0), xaxs = "i", yaxs = "i") 205 | image(x$x, col = x$cells.col, asp = 1/cos((mean(x$x.bbox[1, ]) * pi)/180)) 206 | dev.off() 207 | return(spgrid.js) 208 | }) 209 | 210 | if(is.null(setView)){ 211 | extbox <- .getExtBox(sppts, spico, splns, sppol, spgrid) 212 | init.map1 <- paste0(init.map1, "\n", 213 | "map.fitBounds([[", extbox[3], ",", extbox[1],"], [", extbox[4], ",", extbox[2], "]]);") 214 | } 215 | 216 | # Compile 217 | map.file <- paste(dir, "/", prefix, "_map.html", sep="") 218 | write(paste(inc.encoding, inc.leaflet, inc.extra.css, inc.data, init.map0, 219 | "", 222 | sep="\n\n"), map.file) 223 | 224 | } 225 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [![R-CMD-check](https://github.com/fkeck/rleafmap/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/fkeck/rleafmap/actions/workflows/R-CMD-check.yaml) 4 | 5 | 6 | # rleafmap 7 | ## Interactive maps with R and Leaflet 8 | rleafmap is an R package to display spatial data with interactive maps powered by Leaflet. 9 | 10 | ## Install 11 | 12 | To install the package you can use devtools: 13 | 14 | devtools::install_github("fkeck/rleafmap") 15 | 16 | ## Getting started 17 | Here is a [presentation](http://www.francoiskeck.fr/rleafmap/docs/rleafmap_rencontreR/index_EN.html) of the package (use fullscreen to avoid display problems). 18 | 19 | Check the website of the package [here](http://www.francoiskeck.fr/rleafmap/). 20 | -------------------------------------------------------------------------------- /_data/_dataicons.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /_data/_datalines.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /_data/_datapoints.js: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /_map.html: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 52 | 53 | 54 | 55 | 56 | 57 | 58 |
59 | 60 | 112 | -------------------------------------------------------------------------------- /data/campsites.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fkeck/rleafmap/e5c0efe1004286487b530dc23909adcd2dfd510b/data/campsites.RData -------------------------------------------------------------------------------- /data/hotels.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fkeck/rleafmap/e5c0efe1004286487b530dc23909adcd2dfd510b/data/hotels.RData -------------------------------------------------------------------------------- /data/velov.RData: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fkeck/rleafmap/e5c0efe1004286487b530dc23909adcd2dfd510b/data/velov.RData -------------------------------------------------------------------------------- /man/basemap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/basemap.R 3 | \name{basemap} 4 | \alias{basemap} 5 | \title{Define a Tile Basemap Layer} 6 | \usage{ 7 | basemap( 8 | URL, 9 | name = NULL, 10 | alpha = 1, 11 | minZoom = 0, 12 | maxZoom = 18, 13 | tileSize = 256, 14 | tms = FALSE 15 | ) 16 | } 17 | \arguments{ 18 | \item{URL}{a character string giving the tile server url or a the name of a pre-configured server.} 19 | 20 | \item{name}{a character string to name the layer.} 21 | 22 | \item{alpha}{a numeric value in \eqn{[0, 1]} setting the layer opacity.} 23 | 24 | \item{minZoom, maxZoom}{numeric values setting the minimum and maximum zoom level.} 25 | 26 | \item{tileSize}{a numeric value setting tile size (width and height in pixels, assuming tiles are square).} 27 | 28 | \item{tms}{logical. If \code{TRUE}, inverses Y axis numbering for tiles (for TMS services)} 29 | } 30 | \value{ 31 | An object of class \code{basemap} which can be directly used in \code{\link{writeMap}}. 32 | } 33 | \description{ 34 | Define a new basemap layer from a tile server. 35 | } 36 | \details{ 37 | \code{URL} should have the form \code{'http://{s}.somedomain.com/somepath/{z}/{x}/{y}.png'} 38 | with \code{{s}} a facultative subdomain, \code{{z}} the zoom level and \code{{x}}, \code{{y}} the coordinates. 39 | \pkg{rleafmap} comes with a list of pre-configured servers. Names of these servers are returned 40 | by the function \code{bmSource}. 41 | } 42 | \examples{ 43 | \dontrun{ 44 | #A simple map with two nice basemaps. 45 | bm1 <- basemap("mapquest.map") 46 | bm2 <- basemap("stamen.watercolor") 47 | writeMap(bm1, bm2) 48 | } 49 | } 50 | \seealso{ 51 | \code{\link{spLayer}} to define data layers. 52 | } 53 | -------------------------------------------------------------------------------- /man/bmCredit.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{bmCredit} 4 | \alias{bmCredit} 5 | \title{Tiles Servers Attribution} 6 | \usage{ 7 | bmCredit(x) 8 | } 9 | \arguments{ 10 | \item{x}{a character string of the url of the server.} 11 | } 12 | \value{ 13 | The attribution of the server. 14 | } 15 | \description{ 16 | Take a tiles server url and return its attribution. 17 | } 18 | -------------------------------------------------------------------------------- /man/bmServer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{bmServer} 4 | \alias{bmServer} 5 | \title{Tiles Servers URL} 6 | \usage{ 7 | bmServer(x) 8 | } 9 | \arguments{ 10 | \item{x}{a character string of the name of the server.} 11 | } 12 | \value{ 13 | The url of the server. 14 | } 15 | \description{ 16 | Take a tiles server name (as returned by \code{\link{bmSource}}) and return its url. 17 | } 18 | -------------------------------------------------------------------------------- /man/bmSource.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{bmSource} 4 | \alias{bmSource} 5 | \title{Basemap Tiles Servers} 6 | \usage{ 7 | bmSource(print.servers = TRUE) 8 | } 9 | \arguments{ 10 | \item{print.servers}{logical. Should the names of the servers be printed?} 11 | } 12 | \value{ 13 | Returns invisibly a matrix with servers names, urls and credits. 14 | } 15 | \description{ 16 | Print a list of tiles servers ready-to-use with \code{\link{basemap}}. 17 | } 18 | -------------------------------------------------------------------------------- /man/campsites.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rleafmap-package.R 3 | \docType{data} 4 | \name{campsites} 5 | \alias{campsites} 6 | \title{French Campsites} 7 | \format{ 8 | a \code{SpatialPolygonsDataFrame} with geometries of the 96 french departements (epsg:4326) and 11 variables. 9 | \itemize{ 10 | \item DEP.CODE The code number of each department. 11 | \item DEP.NAME The name of each department. 12 | \item CHF.NAME The name of the main (administrative) city of each department. 13 | \item REGION.NAME The name of the administrative french region of each department. 14 | \item N.CAMPSITES The number of campsites. 15 | \item N.5, N.4, N.3, N.2, N.1 The number of campsites for each ranking categories (i.e. stars). 16 | \item PITCHES The number of camp pitches for each department. 17 | } 18 | } 19 | \source{ 20 | \itemize{ 21 | \item Institut National de l'Information Geographique et Forestiere (2014) 22 | \item ATOUT FRANCE - Agence de developpement touristique de la France (2014). 23 | } 24 | } 25 | \usage{ 26 | data(campsites) 27 | } 28 | \description{ 29 | This dataset gives the number of ranked campsites and the number of tent pitches for each department of metropolitan France. 30 | } 31 | \keyword{datasets} 32 | -------------------------------------------------------------------------------- /man/chunkerize.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/chunkerize.R 3 | \name{chunkerize} 4 | \alias{chunkerize} 5 | \title{Multiple code chunks} 6 | \usage{ 7 | chunkerize( 8 | FUN, 9 | arg.names, 10 | arg.values, 11 | type = "block", 12 | echo = FALSE, 13 | warning = FALSE, 14 | error = FALSE, 15 | message = TRUE, 16 | fig.width = 4, 17 | fig.height = 4, 18 | fig.align = "center", 19 | options = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{FUN}{the function to use for the chunks.} 24 | 25 | \item{arg.names}{a character vector giving the argument names of \code{FUN} to set.} 26 | 27 | \item{arg.values}{a vector giving the values or object names to assign to 28 | each argument given with \code{arg.names} (they must match in order). 29 | Object names must be backquoted or quoted. 30 | Lists names marked with a star (e.g. \code{"*L1"} for \code{L1}) 31 | indicate their elements will be used sequentially in chunks.} 32 | 33 | \item{type}{the type of chunk to produce. Can be "\code{block}", "\code{inline}" or "\code{none}".} 34 | 35 | \item{echo}{logical indicating whether to include R source code in the result.} 36 | 37 | \item{warning}{logical indicating whether to print warnings in the result.} 38 | 39 | \item{error}{logical indicating whether to stop on errors.} 40 | 41 | \item{message}{logical indicating whether to print messages in the result.} 42 | 43 | \item{fig.width, fig.height}{numeric value setting width and height of the plots in inches.} 44 | 45 | \item{fig.align}{character string setting the alignment of the plots. Can be "\code{left}", "\code{right}" and "\code{center}".} 46 | 47 | \item{options}{a character string to specify the knitr options. 48 | This will overwrite the options set with the other arguments.} 49 | } 50 | \value{ 51 | a character vector of R code chunks which can be evaluated by \pkg{knitr}. 52 | } 53 | \description{ 54 | This function creates multiple code chunks from a function and along arguments marked with a star (*). 55 | Each of these special arguments is a list. 56 | The nth code chunk will use the nth element of each marked list (recycled if necessary) as argument. 57 | } 58 | -------------------------------------------------------------------------------- /man/col2hexa.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{col2hexa} 4 | \alias{col2hexa} 5 | \title{Convert colors to hexadecimal format} 6 | \usage{ 7 | col2hexa(x, alpha.channel = FALSE, alpha = 1, charstring = TRUE) 8 | } 9 | \arguments{ 10 | \item{x}{a vector of any of the three kinds of \R color specifications.} 11 | 12 | \item{alpha.channel}{logical. Sould an alpha channel included in the output? Default is \code{FALSE}.} 13 | 14 | \item{alpha}{a vector of numeric values in \eqn{[0, 1]}. Recycled if necessary.} 15 | 16 | \item{charstring}{logical. Sould resulting elements be surrounded by quotation marks? Default is \code{TRUE}.} 17 | } 18 | \value{ 19 | A character vector of hexadecimal values. 20 | } 21 | \description{ 22 | This function converts any color of the \R system to hexadecimal format. 23 | } 24 | \seealso{ 25 | \code{\link[grDevices]{col2rgb}} for translating \R colors to RGB vectors. 26 | } 27 | \keyword{internal} 28 | -------------------------------------------------------------------------------- /man/hotels.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rleafmap-package.R 3 | \docType{data} 4 | \name{hotels} 5 | \alias{hotels} 6 | \title{French Hotels} 7 | \format{ 8 | a \code{SpatialPolygonsDataFrame} with geometries of the 96 french departements (epsg:4326) and 12 variables. 9 | \itemize{ 10 | \item DEP.CODE The code number of each department. 11 | \item DEP.NAME The name of each department. 12 | \item CHF.NAME The name of the main (administrative) city of each department. 13 | \item REGION.NAME The name of the french region (administrative) of each department. 14 | \item N.HOTELS The number of hotels. 15 | \item N.5, N.4, N.3, N.2, N.1 The number of hotels for each ranking categories (i.e. stars). 16 | \item ROOMS The number of hotel's rooms for each department. 17 | \item CAPACITY The total capacity (beds) for each department. 18 | } 19 | } 20 | \source{ 21 | \itemize{ 22 | \item Institut National de l'Information Geographique et Forestiere (2014) 23 | \item ATOUT FRANCE - Agence de developpement touristique de la France (2014). 24 | } 25 | } 26 | \usage{ 27 | data(hotels) 28 | } 29 | \description{ 30 | This dataset gives the number of hotels, number of rooms and capacity for each department of metropolitan France. 31 | } 32 | \keyword{datasets} 33 | -------------------------------------------------------------------------------- /man/layerLegend.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/legend.R 3 | \name{layerLegend} 4 | \alias{layerLegend} 5 | \title{Data layer legend} 6 | \usage{ 7 | layerLegend( 8 | style, 9 | labels = "", 10 | title = NULL, 11 | position = "bottomright", 12 | png = NULL, 13 | size = 5, 14 | png.width = NULL, 15 | png.height = NULL, 16 | stroke.col = 1, 17 | stroke.lwd = 1, 18 | stroke.lty = -1, 19 | stroke.alpha = 1, 20 | fill.col = 2, 21 | fill.alpha = 0.5, 22 | cells.range = c(1, 10), 23 | cells.col = heat.colors(12), 24 | cells.alpha = 1 25 | ) 26 | } 27 | \arguments{ 28 | \item{style}{the style of legend to generate. 29 | Can be one of "\code{points}", "\code{lines}", "\code{polygons}", "\code{icons}", "\code{gradient}".} 30 | 31 | \item{labels}{a vector to label each element of the legend.} 32 | 33 | \item{title}{a title which will appear above the legend. 34 | If \code{NULL} (default), it will inherit the name of the data layer during the compilation of the map. 35 | If \code{NA}, the legend will appear without title.} 36 | 37 | \item{position}{a character string indicating where should the legend be displayed. 38 | This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}"} 39 | 40 | \item{png}{character vector giving the paths for the PNG icons. If \code{NULL} (default), circles are drawn.} 41 | 42 | \item{size}{a numerical vector giving the size of points (radius in pixels).} 43 | 44 | \item{png.width, png.height}{numerical vectors giving the PNG icons dimensions on the map (in pixels).} 45 | 46 | \item{stroke.col}{a vector of any of the three kinds of \R color specifications to set strokes color.} 47 | 48 | \item{stroke.lwd}{a numerical vector to set strokes width.} 49 | 50 | \item{stroke.lty}{a character vector that defines the strokes dash patterns (See Details).} 51 | 52 | \item{stroke.alpha}{a vector of numeric values in \eqn{[0, 1]} setting strokes opacity.} 53 | 54 | \item{fill.col}{a vector of any of the three kinds of \R color specifications to set fill colors.} 55 | 56 | \item{fill.alpha}{a vector of numeric values in \eqn{[0, 1]} setting fill opacity.} 57 | 58 | \item{cells.range}{range of gradient values.} 59 | 60 | \item{cells.col}{a vector of any of the three kinds of \R color specifications giving the colors of the gradient.} 61 | 62 | \item{cells.alpha}{a vector of numeric values in \eqn{[0, 1]} setting the gradient opacity.} 63 | } 64 | \value{ 65 | an object \code{layerlegend} which can be passed to an \code{spLayer*} function through the \code{legend} argument. 66 | } 67 | \description{ 68 | This function creates a legend object that can be attached to a data layer. 69 | } 70 | -------------------------------------------------------------------------------- /man/printspl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genmeths.R 3 | \name{print.splpoints} 4 | \alias{print.splpoints} 5 | \alias{print.splicons} 6 | \alias{print.spllines} 7 | \alias{print.splpolygons} 8 | \alias{print.splgrid} 9 | \title{Printing spl object} 10 | \usage{ 11 | \method{print}{splpoints}(x, ...) 12 | 13 | \method{print}{splicons}(x, ...) 14 | 15 | \method{print}{spllines}(x, ...) 16 | 17 | \method{print}{splpolygons}(x, ...) 18 | 19 | \method{print}{splgrid}(x, ...) 20 | } 21 | \arguments{ 22 | \item{x}{an \code{spl} object.} 23 | 24 | \item{...}{additional arguments. Not used.} 25 | } 26 | \description{ 27 | Print spl objects 28 | } 29 | -------------------------------------------------------------------------------- /man/rleafmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rleafmap-package.R 3 | \docType{package} 4 | \name{rleafmap} 5 | \alias{rleafmap} 6 | \title{rleafmap} 7 | \description{ 8 | Display spatial data with interactive maps powered by the open- 9 | source JavaScript library 'Leaflet' (see ). Maps can be 10 | rendered in a web browser or displayed in the HTML viewer pane of 'RStudio'. 11 | This package is designed to be easy to use and can create complex maps with 12 | vector and raster data, web served map tiles and interface elements. 13 | } 14 | -------------------------------------------------------------------------------- /man/spLayer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer} 4 | \alias{spLayer} 5 | \title{Define a Data Layer} 6 | \usage{ 7 | spLayer(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a spatial object as defined in the package \pkg{sp}.} 11 | 12 | \item{...}{additional arguments to pass to the function.} 13 | } 14 | \description{ 15 | Define a new data layer from an object sp. 16 | } 17 | \examples{ 18 | \dontrun{ 19 | #POINTS 20 | data(velov) 21 | vv <- spLayer(velov, stroke=F, popup=velov$NAME) 22 | 23 | #POLYGONS 24 | data(campsites) 25 | gcol <- rev(heat.colors(5)) 26 | gcut <- cut(mapdep$N.CAMPSITES, breaks=c(-1, 20, 40, 60, 80, 1000)) 27 | cs <- spLayer(campsites, fill.col=as.numeric(gcut)) 28 | bm1 <- basemap("mapquest.map") 29 | 30 | writeMap(bm1, cs, vv) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /man/spLayer.SpatialGridDataFrame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer.SpatialGridDataFrame} 4 | \alias{spLayer.SpatialGridDataFrame} 5 | \title{Define a Raster Data Layer} 6 | \usage{ 7 | \method{spLayer}{SpatialGridDataFrame}( 8 | x, 9 | name = NULL, 10 | layer, 11 | cells.col = heat.colors(12), 12 | cells.alpha = 1, 13 | legend = NULL, 14 | ... 15 | ) 16 | } 17 | \arguments{ 18 | \item{x}{a spatial object (see Details).} 19 | 20 | \item{name}{a character string to name the layer.} 21 | 22 | \item{layer}{which layer to select?} 23 | 24 | \item{cells.col}{a vector of any of the three kinds of \R color specifications giving a gradient to color the grid.} 25 | 26 | \item{cells.alpha}{a vector of numeric values in \eqn{[0, 1]} setting grid opacity.} 27 | 28 | \item{legend}{a legend object created with \code{\link{layerLegend}}.} 29 | 30 | \item{...}{additional arguments to pass to the function.} 31 | } 32 | \description{ 33 | \code{spLayer.SpatialGridDataFrame} defines a new data layer from an object \code{SpatialGridDataFrame}. 34 | } 35 | -------------------------------------------------------------------------------- /man/spLayer.SpatialLines.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer.SpatialLines} 4 | \alias{spLayer.SpatialLines} 5 | \title{Define a Vector Data Layer} 6 | \usage{ 7 | \method{spLayer}{SpatialLines}( 8 | x, 9 | name = NULL, 10 | stroke = TRUE, 11 | stroke.col = 1, 12 | stroke.lwd = 1, 13 | stroke.lty = -1, 14 | stroke.alpha = 1, 15 | label = NULL, 16 | popup = "", 17 | popup.rmd = FALSE, 18 | legend = NULL, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{x}{a spatial object (see Details).} 24 | 25 | \item{name}{a character string to name the layer.} 26 | 27 | \item{stroke}{logical. Should a stroke be drawn along lines and polygons?} 28 | 29 | \item{stroke.col}{a vector of any of the three kinds of \R color specifications to set strokes color.} 30 | 31 | \item{stroke.lwd}{a numerical vector to set strokes width.} 32 | 33 | \item{stroke.lty}{a character vector that defines the strokes dash patterns (See Details).} 34 | 35 | \item{stroke.alpha}{a vector of numeric values in \eqn{[0, 1]} setting strokes opacity.} 36 | 37 | \item{label}{a reserved argument (in development).} 38 | 39 | \item{popup}{a character vector giving contents for popups. HTML tags are accepted.} 40 | 41 | \item{popup.rmd}{a logical indicating whether the popups should be processed as R Markdown with \pkg{knitr}. Default \code{FALSE}.} 42 | 43 | \item{legend}{a legend object created with \code{\link{layerLegend}}.} 44 | 45 | \item{...}{additional arguments to pass to the function.} 46 | } 47 | \description{ 48 | Define a Vector Data Layer 49 | } 50 | -------------------------------------------------------------------------------- /man/spLayer.SpatialPoints.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer.SpatialPoints} 4 | \alias{spLayer.SpatialPoints} 5 | \title{Define a Vector Data Layer} 6 | \usage{ 7 | \method{spLayer}{SpatialPoints}( 8 | x, 9 | name = NULL, 10 | png = NULL, 11 | size = 5, 12 | png.width = 15, 13 | png.height = 15, 14 | stroke = TRUE, 15 | stroke.col = 1, 16 | stroke.lwd = 1, 17 | stroke.lty = -1, 18 | stroke.alpha = 1, 19 | fill = TRUE, 20 | fill.col = 2, 21 | fill.alpha = 0.5, 22 | label = NULL, 23 | popup = "", 24 | popup.rmd = FALSE, 25 | legend = NULL, 26 | ... 27 | ) 28 | } 29 | \arguments{ 30 | \item{x}{a spatial object (see Details).} 31 | 32 | \item{name}{a character string to name the layer.} 33 | 34 | \item{png}{character vector giving the paths for the PNG icons. If \code{NULL} (default), circles are drawn.} 35 | 36 | \item{size}{a numerical vector giving the size of points (radius in pixels).} 37 | 38 | \item{png.width, png.height}{numerical vectors giving the PNG icons dimensions on the map (in pixels).} 39 | 40 | \item{stroke}{logical. Should a stroke be drawn along lines and polygons?} 41 | 42 | \item{stroke.col}{a vector of any of the three kinds of \R color specifications to set strokes color.} 43 | 44 | \item{stroke.lwd}{a numerical vector to set strokes width.} 45 | 46 | \item{stroke.lty}{a character vector that defines the strokes dash patterns (See Details).} 47 | 48 | \item{stroke.alpha}{a vector of numeric values in \eqn{[0, 1]} setting strokes opacity.} 49 | 50 | \item{fill}{logical. Should points and polygons be filled?} 51 | 52 | \item{fill.col}{a vector of any of the three kinds of \R color specifications to set fill colors.} 53 | 54 | \item{fill.alpha}{a vector of numeric values in \eqn{[0, 1]} setting fill opacity.} 55 | 56 | \item{label}{a reserved argument (in development).} 57 | 58 | \item{popup}{a character vector giving contents for popups. HTML tags are accepted.} 59 | 60 | \item{popup.rmd}{a logical indicating whether the popups should be processed as R Markdown with \pkg{knitr}. Default \code{FALSE}.} 61 | 62 | \item{legend}{a legend object created with \code{\link{layerLegend}}.} 63 | 64 | \item{...}{additional arguments to pass to the function.} 65 | } 66 | \description{ 67 | \itemize{ 68 | \item \code{spLayer.SpatialPoints} defines a new data layer from an object \code{SpatialPoints} or \code{SpatialPointsDataFrame} 69 | \item \code{spLayer.SpatialLines} defines a new data layer from an object \code{SpatialLines} or \code{SpatialLinesDataFrame} 70 | \item \code{spLayer.SpatialPolygons} defines a new data layer from an object \code{SpatialPolygons} or \code{SpatialPolygonsDataFrame} 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /man/spLayer.SpatialPolygons.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer.SpatialPolygons} 4 | \alias{spLayer.SpatialPolygons} 5 | \title{Define a Vector Data Layer} 6 | \usage{ 7 | \method{spLayer}{SpatialPolygons}( 8 | x, 9 | name = NULL, 10 | stroke = TRUE, 11 | stroke.col = 1, 12 | stroke.lwd = 1, 13 | stroke.lty = -1, 14 | stroke.alpha = 1, 15 | fill = TRUE, 16 | fill.col = 2, 17 | fill.alpha = 0.5, 18 | label = NULL, 19 | popup = "", 20 | popup.rmd = FALSE, 21 | holes = FALSE, 22 | legend = NULL, 23 | ... 24 | ) 25 | } 26 | \arguments{ 27 | \item{x}{a spatial object (see Details).} 28 | 29 | \item{name}{a character string to name the layer.} 30 | 31 | \item{stroke}{logical. Should a stroke be drawn along lines and polygons?} 32 | 33 | \item{stroke.col}{a vector of any of the three kinds of \R color specifications to set strokes color.} 34 | 35 | \item{stroke.lwd}{a numerical vector to set strokes width.} 36 | 37 | \item{stroke.lty}{a character vector that defines the strokes dash patterns (See Details).} 38 | 39 | \item{stroke.alpha}{a vector of numeric values in \eqn{[0, 1]} setting strokes opacity.} 40 | 41 | \item{fill}{logical. Should points and polygons be filled?} 42 | 43 | \item{fill.col}{a vector of any of the three kinds of \R color specifications to set fill colors.} 44 | 45 | \item{fill.alpha}{a vector of numeric values in \eqn{[0, 1]} setting fill opacity.} 46 | 47 | \item{label}{a reserved argument (in development).} 48 | 49 | \item{popup}{a character vector giving contents for popups. HTML tags are accepted.} 50 | 51 | \item{popup.rmd}{a logical indicating whether the popups should be processed as R Markdown with \pkg{knitr}. Default \code{FALSE}.} 52 | 53 | \item{holes}{a logical indicating whether to use the \code{hole} slots of the \code{SpatialPolygons} object.} 54 | 55 | \item{legend}{a legend object created with \code{\link{layerLegend}}.} 56 | 57 | \item{...}{additional arguments to pass to the function.} 58 | } 59 | \description{ 60 | Define a Vector Data Layer 61 | } 62 | -------------------------------------------------------------------------------- /man/spLayer.default.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayer.default} 4 | \alias{spLayer.default} 5 | \title{Define a Vector Data Layer} 6 | \usage{ 7 | \method{spLayer}{default}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a spatial object as defined in the package \pkg{sp}.} 11 | 12 | \item{...}{additional arguments to pass to the function.} 13 | } 14 | \description{ 15 | Define a Vector Data Layer 16 | } 17 | -------------------------------------------------------------------------------- /man/spLayerControl.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/splayer.R 3 | \name{spLayerControl} 4 | \alias{spLayerControl} 5 | \title{Testing user inputs} 6 | \usage{ 7 | spLayerControl( 8 | name, 9 | size = 1, 10 | legend = legend, 11 | stroke = TRUE, 12 | stroke.col = 1, 13 | stroke.lwd = 1, 14 | stroke.lty = 1, 15 | stroke.alpha = 1, 16 | fill = TRUE, 17 | fill.col = 1, 18 | fill.alpha = 1, 19 | label = "", 20 | popup = "", 21 | holes = FALSE 22 | ) 23 | } 24 | \arguments{ 25 | \item{name}{a character string to name the layer.} 26 | 27 | \item{size}{a numerical vector giving the size of points (radius in pixels).} 28 | 29 | \item{legend}{a legend object created with \code{\link{layerLegend}}.} 30 | 31 | \item{stroke}{logical. Should a stroke be drawn along lines and polygons?} 32 | 33 | \item{stroke.col}{a vector of any of the three kinds of \R color specifications to set strokes color.} 34 | 35 | \item{stroke.lwd}{a numerical vector to set strokes width.} 36 | 37 | \item{stroke.lty}{a character vector that defines the strokes dash patterns (See Details).} 38 | 39 | \item{stroke.alpha}{a vector of numeric values in \eqn{[0, 1]} setting strokes opacity.} 40 | 41 | \item{fill}{logical. Should points and polygons be filled?} 42 | 43 | \item{fill.col}{a vector of any of the three kinds of \R color specifications to set fill colors.} 44 | 45 | \item{fill.alpha}{a vector of numeric values in \eqn{[0, 1]} setting fill opacity.} 46 | 47 | \item{label}{a reserved argument (in development).} 48 | 49 | \item{popup}{a character vector giving contents for popups. HTML tags are accepted.} 50 | 51 | \item{holes}{a logical indicating whether to use the \code{hole} slots of the \code{SpatialPolygons} object.} 52 | } 53 | \description{ 54 | This function tests arguments validity for the function \code{\link{spLayer}}. 55 | } 56 | -------------------------------------------------------------------------------- /man/summarymaplayer.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/genmeths.R 3 | \name{summary.basemap} 4 | \alias{summary.basemap} 5 | \alias{summary.splpoints} 6 | \alias{summary.splicons} 7 | \alias{summary.spllines} 8 | \alias{summary.splpolygons} 9 | \alias{summary.splgrid} 10 | \alias{summary.ui} 11 | \title{Summary of map elements} 12 | \usage{ 13 | \method{summary}{basemap}(object, ...) 14 | 15 | \method{summary}{splpoints}(object, ...) 16 | 17 | \method{summary}{splicons}(object, ...) 18 | 19 | \method{summary}{spllines}(object, ...) 20 | 21 | \method{summary}{splpolygons}(object, ...) 22 | 23 | \method{summary}{splgrid}(object, ...) 24 | 25 | \method{summary}{ui}(object, ...) 26 | } 27 | \arguments{ 28 | \item{object}{a map layer, \code{basemap}, \code{spl} or \code{ui} object.} 29 | 30 | \item{...}{additional arguments. Not used.} 31 | } 32 | \description{ 33 | Get a summary of a map element. 34 | } 35 | -------------------------------------------------------------------------------- /man/toGeoJSON.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toGeoJSON.R 3 | \name{toGeoJSON} 4 | \alias{toGeoJSON} 5 | \title{Convert a spl object to GeoJSON format} 6 | \usage{ 7 | toGeoJSON(x, lightjson = F) 8 | } 9 | \arguments{ 10 | \item{x}{a \code{spl} object.} 11 | 12 | \item{lightjson}{logical. Should GeoJSON code size be reduced by supressing extra whitespace characters and rounding numeric values?} 13 | } 14 | \value{ 15 | A character string of GeoJSON formatted code. 16 | } 17 | \description{ 18 | This function is used internally by \code{\link{writeMap}} to convert a given \code{spl} object to GeoJSON format. 19 | } 20 | -------------------------------------------------------------------------------- /man/toJS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/toJS.R 3 | \name{toJS} 4 | \alias{toJS} 5 | \title{Generate Leaflet JS code for a given layer} 6 | \usage{ 7 | toJS(x, url = "") 8 | } 9 | \arguments{ 10 | \item{x}{a \code{spl} or \code{basemap} object.} 11 | 12 | \item{url}{a character string giving the path for the raster files.} 13 | } 14 | \value{ 15 | A character string of JavaScript Code. 16 | } 17 | \description{ 18 | This function is used internally by \code{\link{writeMap}} to generate Leaflet JavaScript code for a given layer. 19 | } 20 | -------------------------------------------------------------------------------- /man/ui.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ui.R 3 | \name{ui} 4 | \alias{ui} 5 | \title{Options settings for map interface} 6 | \usage{ 7 | ui( 8 | zoom = c("topleft", "topright", "bottomleft", "bottomright", "none"), 9 | layers = c("none", "topright", "topleft", "bottomleft", "bottomright"), 10 | attrib = c("bottomright", "topleft", "topright", "bottomleft", "none"), 11 | attrib.text = "" 12 | ) 13 | } 14 | \arguments{ 15 | \item{zoom}{a character string indicating if and how should the zoom control be displayed. 16 | This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}"} 17 | 18 | \item{layers}{a character string indicating if and how should the layers control be displayed. 19 | This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}"} 20 | 21 | \item{attrib}{a character string indicating if and how should the attribution control be displayed. 22 | This must be one of "\code{topleft}", "\code{topright}", "\code{bottomleft}", "\code{bottomright}", "\code{none}"} 23 | 24 | \item{attrib.text}{a character string for additionnal credits. HTML tags are accepted.} 25 | } 26 | \value{ 27 | An object of class \code{ui} which can be directly given as \code{interface} argument of \code{\link{writeMap}}. 28 | } 29 | \description{ 30 | Allow the user to choose which interface elements are displayed on the map and their positions. 31 | } 32 | -------------------------------------------------------------------------------- /man/uiJS.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ui.R 3 | \name{uiJS} 4 | \alias{uiJS} 5 | \title{Generate user interface JS code} 6 | \usage{ 7 | uiJS(interface, ar) 8 | } 9 | \arguments{ 10 | \item{interface}{an \code{ui} object created with \code{\link{ui}}.} 11 | 12 | \item{ar}{a list of \code{basemap} and \code{spl} objects.} 13 | } 14 | \description{ 15 | This function is used internally by \code{\link{writeMap}} to generate JavaScript code 16 | related to the user interface. 17 | } 18 | -------------------------------------------------------------------------------- /man/velov.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/rleafmap-package.R 3 | \docType{data} 4 | \name{velov} 5 | \alias{velov} 6 | \title{Velo'v stations} 7 | \format{ 8 | a \code{SpatialPointsDataFrame} with the location and name of the 349 Velov stations (epsg:4326). 9 | } 10 | \source{ 11 | OpenStreetMap (14/04/2014) 12 | } 13 | \usage{ 14 | data(velov) 15 | } 16 | \description{ 17 | Stations of the bicycle sharing system of the city of Lyon (France). 18 | } 19 | \keyword{datasets} 20 | -------------------------------------------------------------------------------- /man/writeMap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/writemap.R 3 | \name{writeMap} 4 | \alias{writeMap} 5 | \title{Export and display the map} 6 | \usage{ 7 | writeMap( 8 | ..., 9 | dir = getwd(), 10 | prefix = "", 11 | width = 700, 12 | height = 400, 13 | setView = NULL, 14 | setZoom = NULL, 15 | interface = NULL, 16 | lightjson = FALSE, 17 | directView = c("viewer", "browser", "disabled"), 18 | leaflet.loc = "online", 19 | popup.style = NULL 20 | ) 21 | } 22 | \arguments{ 23 | \item{...}{\code{basemap} and \code{spl} objects to embed into the map} 24 | 25 | \item{dir}{a character string giving the directory path to export the map. 26 | Default is the working directory.} 27 | 28 | \item{prefix}{a character string to add a prefix to file names. 29 | This allows multiple exportations in the same directory.} 30 | 31 | \item{width, height}{the width and height of the map, in pixels.} 32 | 33 | \item{setView}{a numeric vector of the form \code{c(x, y)} 34 | setting the initial geographical center of the map.} 35 | 36 | \item{setZoom}{a numeric value setting the initial map zoom.} 37 | 38 | \item{interface}{an \code{ui} object created with \code{\link{ui}} 39 | to customize the interface controls.} 40 | 41 | \item{lightjson}{logical. Should GeoJSON files size be reducedby supressing 42 | extra whitespace characters and rounding numeric values? Default is \code{FALSE}. 43 | This is currently not compatible with RMarkdown popups.} 44 | 45 | \item{directView}{a character string indicating if and how should the map be displayed. 46 | Default option "\code{viewer}" uses (if available) the RStudio HTML viewer to display the map, 47 | "\code{browser}" opens the map into the web browser and "\code{disabled}" disables direct display.} 48 | 49 | \item{leaflet.loc}{a character string specifying the location (directory) of the leaflet library. 50 | If set to "\code{online}" (default), the library is loaded from the leaflet 51 | official CDN and requires an internet connection.} 52 | 53 | \item{popup.style}{an optional character string of CSS to customize popups content properties (width, color, etc).} 54 | } 55 | \description{ 56 | This function combines all the elements specified by the user and write 57 | the corresponding HTML and Javascript code in a local directory. 58 | } 59 | -------------------------------------------------------------------------------- /rleafmap.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | BuildType: Package 16 | PackageInstallArgs: --no-multiarch --with-keep.source 17 | --------------------------------------------------------------------------------