显示与隐藏
index.html
<!DOCTYPE html>
<html>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>图层 - 显示与隐藏</title>
  <link rel="icon" href="/examples/static/resource/image/favicon.png" />
  <style type="text/css">
    html,body{margin:0px;height:100%;width:100%}
    .container{width:100%;height:100%}
    .pane{line-height:28px;color:#fff;z-index:1000;position:absolute;top:20px;right:20px}
    .pane a{display:block;color:#fff;text-align:center;padding:0 10px;min-width:28px;min-height:28px;float:left;background:#34495e}
    .pane a:hover{background:#1bbc9b}
    .pane a + a{border-left:1px solid #425568}
  </style>
  <link rel="stylesheet" href="//rd.sz-map.com/libs/gm/gl/gl.min.css">
  <script type="text/javascript" src="//rd.sz-map.com/libs/gm/gl/gl.min.js"></script>
  <body>
    
    <div id="map" class="container"></div>
    <div class="pane">
      <a href="javascript:void(0);" onclick="showLayer();">显示</a>
      <a href="javascript:void(0);" onclick="hideLayer()">隐藏</a>
    </div>

    <script>
      function initMap() {
        this.map = new GL.Map('map', {
          center: '120.650847,31.3092434',
          zoomControl: false,
          scaleControl: false
        });
      
        var crs = {"resolutions":[0.0009765664903423653,0.0004882832451711827,0.00024414162258559134,0.00012207081129279567,0.00006103540564766688,0.000030517702822564394,0.000015258851412551242,0.000007629425705006574,0.000003814712853772333,0.00000190735154359766],"origin":"119.75,32.25"};
        var options = {"maxBounds":"119.89,30.75;121.406,32.08","preview":"/examples/static/images/preview.png"};
      
        var baseLayer = GL.LayerLookup.createGaeaTiledLayer(
          'http://119.3.130.139/tiles/vector_pc/_alllayers',
          Object.assign({}, options, {zIndex: 3}),
          crs
        );
        this.map.addBaseLayer(baseLayer);
      
        addOverlay();
      }
      
      function addOverlay() {
        this.vectorLayer = new GL.VectorLayer('vectorLayer');
        this.map.addLayer(this.vectorLayer);
      
        this.text = new GL.Text('120.74434,31.2691366', 'I\'m a Text');
        this.vectorLayer.addOverlay(this.text);
      
        this.point = new GL.Point(
          this.map.getCenter(),
          new GL.Icon.Smart('/examples/static/icons/0003.png', [36, 36])
        );
        this.point.bindLabel('I\'m a Point');
        this.vectorLayer.addOverlay(this.point);
      
        this.polyline = new GL.Polyline(
          '120.4240266,31.2978477;120.5144571,31.2960899'
        );
        this.polyline.bindLabel('I\'m a polyline');
        this.vectorLayer.addOverlay(this.polyline);
      
        this.polygon = new GL.Polygon(
          '120.5240266,31.2978477;120.7144571,31.2860899;120.6541053,31.246285'
        );
        this.polygon.bindLabel('I\'m a polygon');
        this.vectorLayer.addOverlay(this.polygon);
      }
      
      function showLayer() {
        this.vectorLayer.show();
      }
      
      function hideLayer() {
        this.vectorLayer.hide();
      }
      
      GL.init(initMap, '/examples/static/conf.json');

    </script>
  </body>
</html>
已复制!