]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - wrmap.js
Now a status message ('Die Landkarte wird geladen...') is shown at startup instead...
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / wrmap.js
index c10144368ea4206723629ed7fc696c090aefd00a..f6b23ec17177ec27394e547ce8a9e10bb2581239 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -1,20 +1,21 @@
 "use strict";
 
 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
+
+       // extract geojson from map element and clear map element's content
        jq_map = $(jq_map);
-       var jq_map_script = jq_map.children();
        OpenLayers.ImgPath = jq_map.attr('data-img-path'); // e.g. "/mediawiki/extensions/wrmap/openlayers/img/"
-       var json_string = jq_map_script.text();
-       jq_map_script.detach();
-
-       
-       // extract, tranform and split features to layers
-       var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat 
-       var EPSG3857 = new OpenLayers.Projection("EPSG:3857"); // google
+       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);
+
+       // 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) {
@@ -89,8 +90,8 @@ function init_wrmap(i, jq_map) {
                                                // the following context functions should only be available in the rule that uses them,
                                                // but the rule dependent contexts are ignored by OpenLayers (I think that's a bug)
                                                getCondition: function(feature) {
-                                                       if (feature.condition === undefined) return 0;
-                                                       return feature.condition;
+                                                       if (feature.attributes.condition === undefined) return 0;
+                                                       return feature.attributes.condition;
                                                },
                                                getSymbol: function(feature) {
                                                        var name = feature.attributes.type;
@@ -134,7 +135,8 @@ function init_wrmap(i, jq_map) {
                                                getTitle: function(feature) {
                                                        var title = '';
                                                        if (feature.attributes.type != 'point') {
-                                                               title = feature.attributes.type; // TODO: First letter uppercase
+                                                               title = feature.attributes.type;
+                                                               title = title.charAt(0).toUpperCase() + title.slice(1); // First letter uppercase
                                                                if (feature.attributes.name !== undefined) title += ': ';
                                                        }
                                                        if (feature.attributes.name !== undefined) title += feature.attributes.name;
@@ -167,6 +169,13 @@ function init_wrmap(i, jq_map) {
        var lon = json_js.properties.lon;
        var lat = json_js.properties.lat;
        var zoom = json_js.properties.zoom;
+       var width = json_js.properties.width;
+       var height = json_js.properties.height;
+       if (zoom === undefined) zoom = 10; // default zoom
+       if (width === undefined) width = '100%'; // default width
+       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,