How to load layers depending on zoom level?

后端 未结 2 597
北恋
北恋 2021-02-05 23:59

I want to control the zoom in OpenLayers.

When the zoom is 3 I want to load KML1 and when the zoom is 4 i want to load KML2.

Could you please advise me how I can

2条回答
  •  野性不改
    2021-02-06 00:11

    a way to accomplish that is to register an event on event "zoomend" on your map with something like

    map.events.register(type, obj, listener);
    

    You can find more info there: http://dev.openlayers.org/releases/OpenLayers-2.11/doc/apidocs/files/OpenLayers/Map-js.html

    Maybe you should also load both of your kml and then hide / show the correct layer depend on the zoom level.

提交回复
热议问题