Atlaslog
Atlaslog / Examples / OpenLayers / Mapguide Untiled
OpenLayers · Runnable Example

Mapguide Untiled

Runnable OpenLayers example: Mapguide Untiled. Open the live demo, read the complete source, and copy the file into your project. No build step or API key.

Open standalone → Chinese notes All OpenLayers examples
/demos/openlayers-mapguide-untiled.htmlLIVE
single HTML file · CDN dependencies onlyinterface may contain Chinese labels

Source

demos/openlayers-mapguide-untiled.html
<!--
  示例:整幅影像图层
  要点:ol.source.ImageStatic 只取一张图覆盖全范围,不走瓦片金字塔
  依赖:OpenLayers 10.3.1 · jsDelivr CDN
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta name="robots" content="noindex,follow">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>整幅影像图层</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ol@10.3.1/ol.css">
<style>
  html,body{height:100%;margin:0}
  body{display:flex;flex-direction:column;overflow:hidden;
       font:13px/1.6 -apple-system,"Segoe UI","PingFang SC",sans-serif;color:#16181d}
  .bar{flex:0 0 auto;padding:8px 12px;background:#f6f7f9;border-bottom:1px solid #e3e6ea;
       display:flex;gap:14px;align-items:center;font-size:12px;color:#58606e;flex-wrap:wrap}
  .bar label{display:flex;gap:5px;align-items:center;cursor:pointer}
  .bar b{color:#16181d;font-weight:600}
  #map{flex:1 1 auto;min-height:0;background:#eef0f3}
</style>
</head>
<body>
<div class="bar">
  <label><input type="checkbox" id="cbGrid"> 叠加瓦片边界对照</label>
  <span>影像请求次数:<b id="req">1</b> 次(整幅一次性取回)</span>
</div>
<div id="map"></div>
<script src="https://cdn.jsdelivr.net/npm/ol@10.3.1/dist/ol.js"></script>
<script>
(function () {
  'use strict';
  if (!window.ol) {
    document.getElementById('map').textContent = 'OpenLayers 加载失败,请检查 cdn.jsdelivr.net 是否可访问';
    return;
  }

  var bbox = [116.24, 39.80, 116.58, 40.02];
  var extent = ol.proj.transformExtent(bbox, 'EPSG:4326', 'EPSG:3857');

  /* 一张 1024×1536 的整幅影像,缩放时由浏览器拉伸,放大后必然变糊 */
  var url = (function () {
    var W = 1024, H = 1536;
    var c = document.createElement('canvas');
    c.width = W; c.height = H;
    var ctx = c.getContext('2d');

    ctx.fillStyle = '#eef2e6';
    ctx.fillRect(0, 0, W, H);

    for (var i = 0; i < 160; i++) {
      var x = (i * 137) % W, y = (i * 291) % H;
      var w = 40 + (i * 53) % 120, h = 30 + (i * 37) % 90;
      ctx.fillStyle = i % 3 ? 'rgba(180,196,168,0.55)' : 'rgba(150,168,140,0.6)';
      ctx.fillRect(x, y, w, h);
    }

    ctx.strokeStyle = '#9dc8e3';
    ctx.lineWidth = 22;
    ctx.beginPath();
    ctx.moveTo(0, H * 0.35);
    ctx.bezierCurveTo(W * 0.35, H * 0.28, W * 0.6, H * 0.55, W, H * 0.42);
    ctx.stroke();

    ctx.fillStyle = '#3d4a3a';
    ctx.font = '600 28px sans-serif';
    ctx.fillText('整幅影像 1 : 20000', 32, 56);
    ctx.font = '400 22px sans-serif';
    ctx.fillText('单次请求覆盖 116.24–116.58°E / 39.80–40.02°N', 32, 92);

    ctx.strokeStyle = 'rgba(40,60,40,0.35)';
    ctx.lineWidth = 2;
    ctx.strokeRect(1, 1, W - 2, H - 2);

    return c.toDataURL('image/png');
  })();

  var imageLayer = new ol.layer.Image({
    source: new ol.source.ImageStatic({
      url: url,
      imageExtent: extent,
      projection: 'EPSG:3857'
    })
  });

  var gridLayer = new ol.layer.Tile({
    visible: false,
    opacity: 0.7,
    source: new ol.source.XYZ({
      attributions: '瓦片边界示意',
      tileUrlFunction: function (tc) {
        var c = document.createElement('canvas');
        c.width = c.height = 256;
        var ctx = c.getContext('2d');
        ctx.strokeStyle = 'rgba(180,35,24,0.85)';
        ctx.lineWidth = 2;
        ctx.strokeRect(1, 1, 254, 254);
        ctx.fillStyle = 'rgba(180,35,24,0.9)';
        ctx.font = '600 12px monospace';
        ctx.fillText(tc[0] + '/' + tc[1] + '/' + tc[2], 8, 20);
        return c.toDataURL('image/png');
      }
    })
  });

  var map = new ol.Map({
    target: 'map',
    layers: [new ol.layer.Tile({ source: new ol.source.XYZ({url: 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}', attributions: 'Tiles © Esri'}) }), imageLayer, gridLayer],
    view: new ol.View({ center: ol.proj.fromLonLat([116.41, 39.91]), zoom: 11, maxZoom: 19 }),
    controls: ol.control.defaults.defaults({ rotate: false })
  });

  document.getElementById('cbGrid').addEventListener('change', function () {
    gridLayer.setVisible(this.checked);
  });
})();
</script>
</body>
</html>
Language: the code and this page are in English; the full tutorial and API notes for this example are in Chinese. The demo itself is the authoritative version — it runs exactly as shown.

More OpenLayers examples

OpenLayers · EXAMPLEMarker Pulse OpenLayers · EXAMPLEMeasure OpenLayers · EXAMPLEMeasure Style