How to add tilegrid to tile layer in openlayer 6.4.3

1.2k Views Asked by At

I have added 2 layers OSM & my district layer(tiles generated using MapProxy & Mapnik). My code is :

<!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>

The problem when I add the tileGrid: new ol.tilegrid.TileGrid({... I am getting error Uncaught TypeError: e is undefined. If I remove tilegrid and give projection only I am getting map as below.enter image description here. Actually I don't want OSM layer, I just added for reference. And the 5 showing in the picture is a cluster added to the map,which is not included in the code above.

0

There are 0 best solutions below