如何在openlayer 6.4.3中将tilegrid添加到平铺层

问题描述

添加了2层OSM和我的区域层(使用MapProxy和Mapnik生成的图块)。我的代码是:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="https://openlayers.org/en/v6.4.3/css/ol.css" type="text/css">

    <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL"></script>
    <script src="https://openlayers.org/en/v6.4.3/build/ol.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.1/proj4.js"></script>
    <style>
      html,body,.map {
        margin: 0;
        padding: 0;
        width: 100%;
        height: 100%;
      }
    </style>
  </head>
  <body>
    <div id="map" class="map"></div>
    <script>
proj4.defs("epsg:32643","+proj=utm +zone=43 +datum=wgs84 +units=m +no_defs");
ol.proj.proj4.register(proj4);

var map = new ol.Map({
  target: 'map',layers: [
    new ol.layer.Tile({
      source: new ol.source.OSM()
    }),new ol.layer.Tile({
            source: new ol.source.XYZ({
             url: "http://127.0.0.1:8080/tms/1.0.0/district/distgrid" + "/{z}/{x}/{-y}.png",tileGrid: new ol.tilegrid.TileGrid({
                extent: [291627,904686,958569,1426831],tileSize: [512,256],}),projection: "epsg:32643",})
  ],view: new ol.View({
    projection: "epsg:32643",units:"m",zoom:0,maxZoom:12,minZoom:0
  })
});
map.getView().setZoom(map.getView().getZoom() - 6);
    </script>
  </body>
</html>

当我添加 tileGrid时出现问题:new ol.tilegrid.TileGrid({... 我遇到错误 Uncaught TypeError:e undefined 。如果我删除

enter image description here

。实际上,我不需要OSM层,只是添加了参考,图片显示 5 一个群集已添加到地图中,但上面的代码中未包含。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)