地图缩放到一定级别时,切换图标显示。
// OpenLayers 的 地图
hwo.zoomBase = 11;
hwo.zoomOld = 7;
hwo.zoomChange = function () {
var s, v;
var z = this.map.getView().getZoom();
if (z >= this.zoomBase && this.zoomOld < this.zoomBase) {
this.zoomOld = z;
// 大图标
for (s in this.list.subs) {
v = this.list.subs[s];
this.map.removeOverlay(v.mapSmallDoe.view);
this.map.addOverlay(v.mapBigDoe.view);
}
} else if (this.zoomOld >= this.zoomBase && z < this.zoomBase) {
this.zoomOld = z;
// 小图标
for (s in this.list.subs) {
v = this.list.subs[s];
this.map.removeOverlay(v.mapBigDoe.view);
this.map.addOverlay(v.mapSmallDoe.view);
}
}
};
hwo.map = new hw.Ol.Map({
layers: [
new hw.Ol.layer.Tile({
source: new hw.Ol.source.OSM()
})
],
target: "map",
view: new hw.Ol.View({
projection: "EPSG:3857",
zoom: hwo.zoomOld,
center: hw.utOlproj([116, 38.5])
})
});
hwo.map.on("moveend", hw.bind (hwo, hwo.zoomChange));