Proxywms 2056 Rancher

In this example below you will see how to do a Proxywms 2056 Rancher with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by loicgasser, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright loicgasser ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Proxywms 2056 Rancher</title>
  
  
  <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/ol3/3.6.0/ol.css'>

      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div id="map" class="map"></div>
<div id="context"></div>
  <script src='https://openlayers.org/en/v3.15.1/build/ol-debug.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4.js'></script>
<script src='https://epsg.io/2056.js?download'></script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/loicgasser/proxywms-2056-rancher-vxorwX */
#map {
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
}
#context {
  right: 0px;
  top: 0px;
  padding: 5px;
  background-color: black;
  opacity: 0.8;
  position: absolute;
  color: white;
  font-size: 24px;
}

/*Downloaded from https://www.codeseek.co/loicgasser/proxywms-2056-rancher-vxorwX */
var origin = [2420000, 1350000];
var resolutions = [
4000, 3750, 3500, 3250, 3000, 2750, 2500, 2250, 2000, 1750, 1500, 1250, 1000, 750, 650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1.5, 1, 0.5
];
var projectionExtent = [2420000, 1030000, 2900000, 1350000];
var projection = ol.proj.get('EPSG:2056');
projection.setExtent(projectionExtent);
var tileGrid = new ol.tilegrid.WMTS({
  matrixIds: $.map(resolutions, function(r, i) { return i + ''; }),
  origin: origin,
  resolutions: resolutions
});
var wmtsGetTileUrlTemplate = 'https://tod.dev.bgdi.ch/1.0.0/{Layer}/default/{Time}/2056/{TileMatrix}/{TileCol}/{TileRow}.{Format}';
var getWmtsGetTileUrl = function(layer, format) {
  return wmtsGetTileUrlTemplate
      .replace('{Layer}', layer)
      .replace('{Format}', format);
};
var olSource = new ol.source.WMTS({
  dimensions: {
    'Time': 'current'
  },
  projection: 'EPSG:2056',
  requestEncoding: 'REST',
  tileGrid: tileGrid,
  url: getWmtsGetTileUrl('ch.swisstopo.pixelkarte-farbe', 'png'),
  crossOrigin: 'anonymous'
});
var olLayer = new ol.layer.Tile({
  source: olSource,
  extent: olSource.getProjection().getExtent()
});
var map = new ol.Map({
  layers: [
  olLayer
  ],
  target: 'map',
  view: new ol.View({
    resolutions: [
    650, 500, 250, 100, 50, 20, 10, 5, 2.5, 2, 1, 0.5, 0.25, 0.1
    ],
    extent: projection.getExtent(),
    projection: projection,
    center: [2700000, 1200000],
    zoom: 2
  })
});

Comments