Layer Controls for OpenLayers 3

  There is no default layer control control provided in the control of openlayers3.

  But there are already built wheels on git, and you can use them directly. Address https://github.com/walkermatt/ol3-layerswitcher

  Directly refer to the downloaded js file and css file

<link rel="stylesheet" type="text/css" href="../static/css/ol3-layerswitcher.css">
 <script src="../static/js/ol3-layerswitcher.js"></script>

 

And add the following two lines of code to the main.js file:

var layerSwitcher = new ol.control.LayerSwitcher();
map.addControl(layerSwitcher);

 

  After the control is loaded, as shown in the figure, the displayed layer name is the value of the title when adding the layer;

  Controls are added.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324492288&siteId=291194637