Changing the map's projection
In the next example, called ch06_projection
, we close our basic WebGIS client with a final control, which is able to change the map's projection dynamically. First, as we will need the PROJ4JS
library for this example, we include it in the HTML file:
<script type="text/javascript" src="../../js/proj4js-2.3.10/proj4.js"></script>
Next, we style the control with CSS:
.notification-bar #projection { text-align: center; } .notification-bar #projection select { background: none; border: none; outline: 0; }
The scheme is the same as the one in the previous example. We will strip the natural look of the select
element, which will contain the possible projection options. Next, we start building the control by creating two options for the two default projections:
ol.control.Projection = function (opt_options) { var options = opt_options || {}; var _this = this; var projSwitcher = document.createElement('select'); var webMercator...