1

I used OpenLayer2, Mapproxy, Mapnik and tilecache for generating map. I added TMS layers in openlayer2. Now I want to upgrade my openlayer, for that I chose latest version ol6. How do I add a TMS layer in ol6.

My openlayer 2 js is like this

var layer = new OpenLayers.Layer.TMS('District', 'http://127.0.0.1:8080/tms/', {layername: 'district/distgrid', type: 'png', isBaseLayer:true,transitionEffect:"resize" });
map.addLayer(layer);
Adithya
  • 1,687
  • 3
  • 19
  • 34

1 Answers1

2

In OpenLayers TMS layers are tile layers using a XYZ source:

import TileLayer from 'ol/layer/Tile';
import XYZ from 'ol/source/XYZ';

const layer = new TileLayer({
  source: new XYZ({
    url: 'https://{a-c}.tile.openstreetmap.org/{z}/{x}/{y}.png'
  })
});

However, I am not sure about the properties you have provided (please check the docs). Read also this answer.

pzaenger
  • 11,381
  • 3
  • 45
  • 46
  • I can't import TileLayer or anything, getting error. Is the 'ol/layer' the folder path or syntax ? when I use new ***ol.layer.Tile*** there is no error. Can I use that ? – Adithya Aug 17 '20 at 12:21
  • Take a look at _node_modules/ol/layer/Tile.js_. This should be the import path (minus the extension). – pzaenger Aug 17 '20 at 12:33
  • 1
    Oh, my bad. Do you use JavaScript or TypeScript? If first, than `new ol.layer.Tile` should be fine. – pzaenger Aug 17 '20 at 15:31
  • thanks alot..it worked..I have a doubt, I gave tile url like http://127.0.0.1:8080/tms/1.0.0/district/distgrid" + "/{z}/{x}/{-y}.png. Is it okay to gave 1.0.0 in url? anyway its working now – Adithya Aug 18 '20 at 05:05
  • Your URL is totally fine. Glad I could help :) – pzaenger Aug 18 '20 at 09:33