openlayers捕获zoomchanged,改变vector的protocol

来源:互联网 发布:淘宝售前客服兼职 编辑:程序博客网 时间:2024/05/22 09:04
 $("div").remove(".olLayerGoogleCopyright");

                $("div").remove(".olLayerGooglePoweredBy&gmnoprint");

以上两句可以去掉google的logo


//以下事件注册后,可以捕获map的zoomchanged事件,在事件中修改vector图层的请求地址

然后调用refresh(),可重新请求并重新绘制该图层,不需要重新注册图层的事件

                gmap.events.on({
                    moveend: function(e) {
                        //                        for (att in e) {
                        //                            alert(att+":"+e[att]);

                        //                        }

                        if (e.zoomChanged) {
                            alert("currentzoom:" + map.zoom);
                            //ajax异步请求,传递缩放级别和当前城市,得到json地址,
                            hotspot.protocol = new OpenLayers.Protocol.HTTP({
                                url: "../data/test.json",
                                format: new OpenLayers.Format.GeoJSON()
                            });
                            hotspot.refresh();


                            /*以下方法是通过删除图层,在新建图层,需要重新注册事件
                            hotspot.destroy();                            
                            hotspot = new OpenLayers.Layer.Vector("Lines", {
                            strategies: [new OpenLayers.Strategy.Fixed()],
                            protocol: new OpenLayers.Protocol.HTTP({
                            url: "../data/test.json",
                            format: new OpenLayers.Format.GeoJSON()
                            })
                            , styleMap: styles
                            // ,maxExtent: new OpenLayers.Bounds(1549471.9221, 6403610.94, 1550001.32545, 6404015.8)
                            });
                            map.addLayer(hotspot);
                          
                            */
                        }
                    }
                });
原创粉丝点击