Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
小册子中的javascript映射如何刷新_Javascript_Jquery_Leaflet - Fatal编程技术网

小册子中的javascript映射如何刷新

小册子中的javascript映射如何刷新,javascript,jquery,leaflet,Javascript,Jquery,Leaflet,我有一个基本的geoJson程序,通过使用传单API使用javascript <html> <head> <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" /> <script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script> <scri

我有一个基本的geoJson程序,通过使用传单API使用javascript

<html>
<head>

<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
<script src="india.js" type="text/javascript"></script>

</head>


<body>
<div id = "map1" style="width: 1100px; height: 400px"> </div>

<script>

var area = L.map('map1', {center: [27.8800,78.0800], zoom: 4 });

L.tileLayer('http://a.tiles.mapbox.com/v3/raj333.map-gugr5h08/{z}/{x}/{y}.png').addTo(area);

var indiaLayer= L.geoJson(india, {style: {weight: 2,
        opacity: 1,
        color: 'white',
        dashArray: '3',
        fillOpacity: 0.1}});

        area.addLayer(indiaLayer);

        function clicked(){

        this.options.style.fillOpacity = 0.8;
            //how to refresh layer in the given map

        }

        indiaLayer.on('click', clicked);                
</script>
</body>
</html>
当用户单击indiaLayer时,fillOpacity变量会发生变化,但不会反映在地图上,这是可以理解的,因为我没有刷新地图。我不知道怎么做

请帮忙

p/s:这些是indiaLayer对象上可用的函数(即单击函数中的此对象…用于此目的的是哪一个,或者不存在)

您可以在中查看GEOJson的可用方法列表,这是到v.0.7.7的链接,这是本例中最接近的可用方法。

上次我使用的

map._onResize(); 
这有助于我刷新地图。也许有点小技巧,但是,它很管用

在您的代码中将显示区域。_onResize()

附言:也许你应该尝试改变设置新不透明度值的方式-尝试改变

function clicked(){
    this.options.style.fillOpacity = 0.8;
 }
到那

function clicked(){
    this.setStyle({fillOpacity: 0.2});
 }

map.\u onResize()
-这是一种黑客行为,不能保证它在未来的版本中不会被删除。

area.fitBounds(area.getBounds())

刚刚修改了我的答案。我希望它能有所帮助,如果您不介意的话,我还有一个查询,例如,我将我的geoJson层声明为var indiaLayer=L.geoJson(india,{style:{weight:2,opacity:1,color:'#F7BE81',dashArray:'10',fillOpacity:0.2});现在,如果我想访问函数clicked()中的L.geoJson的第一个参数,就像这样发出警报(this._layers.22.feature.id);firebug抛出一个syntex错误;丢失的你能查一下吗?也许你的代码中有语法错误。不管怎样,没有密码我什么都说不出来。尝试使用源代码创建新问题,但我认为在执行此操作之前,您应该仔细检查代码。实际上,如果地图的大小没有更改,invalidateSize将不起作用。在文档中:“检查地图容器大小是否更改,如果更改,则更新地图”我的问题是在这种情况下:我的地图最初是隐藏的,当我显示它时,它没有初始化(并非所有的分幅都已加载)。在我添加了这个方法调用之后,这个问题得到了解决。因此,我认为它无论如何都会进行一些更新。
invalidateSize
在打开标记弹出窗口时无法很好地定位它们,当它们已被openOp询问“问题是如何自动刷新地图上图层的内容。示例here@ImportanceOfBeingErnest复习前请阅读问题和答案。
function clicked(){
    this.setStyle({fillOpacity: 0.2});
 }
map.invalidateSize();