Centered map shows up (but still get an exception).
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 23 May 2018 21:48:33 +0000 (23:48 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 23 May 2018 21:48:33 +0000 (23:48 +0200)
wrmap.js

index 69196e31a7b74bdca8d0376d66bd43cd77438e33..a3a707bd0daa36ae8cb434e6063aaa256d2e7bcd 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -11,9 +11,11 @@ OpenLayers.Popup.WrInfo = OpenLayers.Class(OpenLayers.Popup.FramedCloud, {
 
        CLASS_NAME: "OpenLayers.Popup.WrInfo"
 });
+*/
 
 
 function init_wrmap(i, jq_map) {
+       /*
        // define constants
        var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
        var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
@@ -34,21 +36,22 @@ function init_wrmap(i, jq_map) {
                parentElement.append(element);
                return element;
        }
+       */
 
 
        // extract geojson from map element and clear map element's content
        jq_map = $(jq_map);
        var ext_path = jq_map.attr('data-ext-path'); // e.g. '/mediawiki/extensions/wrmap'
        var img_path = ext_path + '/img';
-       OpenLayers.ImgPath = ext_path + '/openlayers/img/'; // e.g. '/mediawiki/extensions/wrmap/openlayers/img/'
+       //OpenLayers.ImgPath = ext_path + '/openlayers/img/'; // e.g. '/mediawiki/extensions/wrmap/openlayers/img/'
        var json_string = jq_map.children().last().text();
        jq_map.empty(); // once parsed, remove geojson string from the map element.
-       var format_json = new OpenLayers.Format.JSON();
-       var json_js = format_json.read(json_string);
-       var format_geojson = new OpenLayers.Format.GeoJSON();
-       var features_all = format_geojson.read(json_js);
+       var json_js = JSON.parse(json_string);
+       // var format_geojson = new OpenLayers.Format.GeoJSON();
+       // var features_all = format_geojson.read(json_js);
 
        // extract, tranform and split features to layers
+       /*
        var features_path = new Array();
        var features_point = new Array();
        for (var i = 0; i != features_all.length; ++i) {
@@ -57,19 +60,18 @@ function init_wrmap(i, jq_map) {
                if (feature.geometry instanceof OpenLayers.Geometry.Point) features_point.push(feature);
                else features_path.push(feature);
        }
-
+       */
 
        // background layer
        // ----------------
-       // // Google (since about 19th of November 2015 this doesn't work anymore - white background)
-       // // see https://github.com/openlayers/openlayers/issues/1450
-       var layer_map = new OpenLayers.Layer.Google("Google Physical", {
-               type: google.maps.MapTypeId.TERRAIN
+
+       // OSM map
+       var layer_map = new ol.layer.Tile({
+               source: new ol.source.OSM()
        });
 
-       // // Alternative: OSM map
-       // var layer_map = new OpenLayers.Layer.OSM();
-       
+
+       /*
        // Microsoft Bing Maps
        // var layer_map = new OpenLayers.Layer.Bing({
        //      type: "Road",
@@ -232,7 +234,7 @@ function init_wrmap(i, jq_map) {
                rendererOptions: {yOrdering: true}
        });
 
-
+*/
        // map itself
        // ----------
        var lon = json_js.properties.lon;
@@ -245,6 +247,7 @@ function init_wrmap(i, jq_map) {
        if (height === undefined) height = 450;  // default: 450 pixel
        jq_map.width(width);
        jq_map.height(height);
+       /*
        var map = new OpenLayers.Map(jq_map.context, {
                projection: EPSG3857,
                displayProjection: EPSG4326,
@@ -254,8 +257,21 @@ function init_wrmap(i, jq_map) {
                center: new OpenLayers.LonLat(lon, lat).transform(EPSG4326, EPSG3857),
                zoom: zoom
        });
+       */
+
+       var map = new ol.Map({
+               target: jq_map.context,
+               layers: [
+                       layer_map
+               ],
+               view: new ol.View({
+                       center: ol.proj.fromLonLat([lon, lat]),
+                       zoom: zoom
+               })
+       });
 
 
+       /*
        // add features
        // if this would be done before the layer is added to the map, the features are not added
        layer_path.addFeatures(features_path); 
@@ -340,14 +356,12 @@ function init_wrmap(i, jq_map) {
                        feature.popup = null;
                }
        }));
-}
 */
+}
 
 function init_wrmaps() {
-       /*
        var jq_maps = $('.wrmap'); // all wrmap <div> elements
        jq_maps.each(init_wrmap);
-       */
 }