传单中的javascript地图如何刷新 [英] javascript map in leaflet how to refresh

查看:75
本文介绍了传单中的javascript地图如何刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用传单API在javascript中有一个基本的geoJson程序。

i have a basic geoJson program in javascript by using leaflet API.

<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>

问题是如何在地图上自动刷新Layer的内容。

the problem is how would i automatically refresh the content of Layer on the map.

此处示例

             function clicked(){

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

        }

        indiaLayer.on('click', clicked);   

当用户点击indiaLayer时,fillOpacity变量会改变,但不反映在地图上,这是理解的因为我没有刷新地图。我不知道怎么做。

when user click on indiaLayer , the fillOpacity variable changes but doesn't reflect back on map which is understood since i am not refreshing the map. I don't know how to do it.

请帮助

P / s:这些是indiaLayer对象上可用的函数(即单击此对象内部) function ...用于此目的的那个或者没有用于)

P/s: these are the functions available on indiaLayer object (i.e. this object inside clicked function...which one to use for this purpose or there exist none)

你可以在 Leaflef文档这是v.0.7.7的链接,这是本例中最接近的可用链接。

You can check the list of methods available of GEOJson in the Leaflef documentation This is the link to v.0.7.7, which is the closest available to used in this example.

推荐答案

上次我使用

map._onResize(); 

这有助于我刷新地图。也许有点破解,但是,它有效。

and that help me refresh map. Maybe a little hack, but, it work.

在你的代码中将是area._onResize()

In your code will be area._onResize()

PS:也许你应该尝试改变设置新的不透明度值的方法 - 尝试更改

P.S: Maybe you should try change the way to set new opacity value - try change

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

到那个

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

这篇关于传单中的javascript地图如何刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆