在传单R-Map中防止缩小?

时间:2016-02-22 14:29:44

标签: r zoom leaflet

我用传单R-package制作了传单地图。

结果如下: enter image description here

我对它非常满意,但是当我将它嵌入网站并使用我的笔记本电脑向下滚动文章时,我经常会意外缩小地图,然后看起来像这样:

enter image description here

用户必须放大,看看地图的间隙部分,这真让我烦恼。

有没有办法冻结地图的一部分,就像你可以像往常一样放大但不能缩小比图像更像?我尝试在我的代码中设置View但你仍然可以缩小,所以我删除了那部分。

    mymap <- leaflet() %>% 

addProviderTiles("Esri.WorldGrayCanvas") %>%
addPolygons(data = dortmund, 
            fillColor = ~palette(student1$Anteil),  ## we want the polygon filled with 
            ## one of the palette-colors
            ## according to the value in student1$Anteil
            fillOpacity = 0.6,         ## how transparent do you want the polygon to be?
            color = "darkgrey",       ## color of borders between districts
            weight = 1.5,            ## width of borders
            popup = popup1,         ## which popup?
            group="<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>")%>%  
            ## which group?
            ## the group's name has to be the same as later in "baseGroups", where we define 
            ## the groups for the Layerscontrol. Because for this layer I wanted a specific 
            ## color and size, the group name includes some font arguments.  

## for the second layer we mix things up a little bit, so you'll see the difference in the map!
addPolygons(data = dortmund, 
            fillColor = ~palette(student2$Anteil), 
            fillOpacity = 0.2, 
            color = "white", 
            weight = 2.0, 
            popup = popup2, 
            group="2014")%>%
addLayersControl(
    baseGroups = c("<span style='color: #7f0000; font-size: 11pt'><strong>2000</strong></span>", ## group 1
                   "2014" ## group 2
    ),
    options = layersControlOptions(collapsed = FALSE))%>% ## we want our control to be seen right away
addLegend(position = 'topleft', ## choose bottomleft, bottomright, topleft or topright
           colors = c('#fee0d2',
                      '#fcbba1',
                      '#fc9272',
                      '#fb6a4a',
                      '#ef3b2c',
                      '#cb181d',
                      '#a50f15',
                      '#67000d'), 
           labels = c('0%',"","","","","","",'26%'),  ## legend labels (only min and max)
           opacity = 0.6,      ##transparency 
           title = "relative<br>amount")   ## title of the legend

原谅我糟糕的英语技巧。如果回答我的问题很重要,请在此处填写完整的代码:http://journocode.com/2016/01/28/your-first-choropleth-map/

非常感谢

1 个答案:

答案 0 :(得分:11)

用以下内容替换你的addProviderTiles(设置你想要的最大和最小缩放级别:

function loadXmlFile(path) {
    var xmlDoc;

    if (loadXmlFile.cache === undefined) {
        loadXmlFile.cache =  { };
    }

    if (loadXmlFile.cache[path] === undefined) {
        try {
            xmlDoc = new ActiveXObject("MSXML2.DOMDocument.6.0");
        }
        catch (e) {
            try {
                xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
            }
            catch (e2) {
                xmlDoc = new XMLHttpRequest();

                xmlDoc.responseType = "application/xml";
            }
        }

        try {
            xmlDoc.open("GET", path, false);
            xmlDoc.send();

            loadXmlFile.cache[path] = xmlDoc.responseXML;
        }
        catch (ex) {
            xmlDoc.async = false;
            xmlDoc.load(path);

            loadXmlFile.cache[path] = xmlDoc;
        }
    }

    return loadXmlFile.cache[path];
}

function xslTransformTo(xsl, xml, wrapper) {
    if (typeof xml.transformNode != "undefined") {
        wrapper.innerHTML = xml.transformNode(xsl);
    }
    else if (typeof XSLTProcessor != "undefined") {
        xsltProcessor = new XSLTProcessor();

        xsltProcessor.importStylesheet(xsl);

        wrapper.appendChild(xsltProcessor.transformToFragment(xml, document));
    }
}