Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use leaflet advanced interactive features

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail how to use the advanced interactive features of leaflet. The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to use the advanced interactive features of leaflet" can help you solve your doubts.

In the project of making high-quality online data map, leaflet, combined with extended HTML performance, can present very humanized dynamic effects. If it can combine decorators such as css, shiny and interactive framework, it is almost competent for the production of common dynamic interactive websites.

Library ("sp")

Library ("leaflet")

Options (stringsAsFactors = FALSE,check.names = FALSE)

Lock the directory:

Setwd ("D:/R/mapdata/State")

Import American map material (including data)

States% # sets the visual center of the rendering

AddProviderTiles ("MapBox", options = providerTileOptions (

Id = "mapbox.light", # add map layer

AccessToken = Sys.getenv ('MAPBOX_ACCESS_TOKEN')

M% >% addPolygons () # Map rendering

# Sub-box and setting color plate:

Bins% addPolygons (

FillColor = ~ pal (density)

Weight = 2

Opacity = 1

Color = "white"

DashArray = "3"

FillOpacity = 0.7

Highlight = highlightOptions (# set highlight property

Weight = 5

Color = "# 666"

DashArray = ""

FillOpacity = 0.7

BringToFront = TRUE))

# set mouse click events:

Labels% lapply (htmltools::HTML) # converted to HTML format tags

M% addPolygons (

FillColor = ~ pal (density)

Weight = 2

Opacity = 1

Color = "white"

DashArray = "3"

FillOpacity = 0.7

Highlight = highlightOptions (

Weight = 5

Color = "# 666"

DashArray = ""

FillOpacity = 0.7

BringToFront = TRUE

),

Label = labels

LabelOptions = labelOptions (# tag option setting (parameter category HTML attribute)

Style=list ("font-weight" = "normal", padding= "3px 8px")

Textsize= "15px"

Direction= "auto")

); m

# add legend:

M% >% addLegend (pal = pal, values = ~ density, opacity = 0.7, title = NULL

Position = "bottomright")

The following is the complete code for the case:

# From http://leafletjs.com/examples/choropleth/us-states.js

(data source, js format remember to save to geojson format)

Bins lapply (htmltools::HTML)

Leaflet (states)% >%

SetView (- 96,37.8,4)% >%

AddProviderTiles ("MapBox", options = providerTileOptions (

Id = "mapbox.light"

AccessToken = Sys.getenv ('MAPBOX_ACCESS_TOKEN'))% >%

AddPolygons (

FillColor = ~ pal (density)

Weight = 2

Opacity = 1

Color = "white"

DashArray = "3"

FillOpacity = 0.7

Highlight = highlightOptions (

Weight = 5

Color = "# 666"

DashArray = ""

FillOpacity = 0.7

BringToFront = TRUE)

Label = labels

LabelOptions = labelOptions (

Style = list ("font-weight" = "normal", padding = "3px 8px")

Textsize = "15px"

Direction = "auto"))% >%

AddLegend (pal = pal, values = ~ density, opacity = 0.7, title = NULL

Position = "bottomright")

After reading this, the article "how to use the advanced interactive features of leaflet" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about the article, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report