The icons of inns, busstops, carparks, ... are shown now.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 9 Aug 2013 20:10:13 +0000 (20:10 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Fri, 9 Aug 2013 20:10:13 +0000 (20:10 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/mediawiki_extensions/wrmap/trunk@1504 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrmap.body.php
wrmap.js

index f6ed44545c53ea81e11eeb47334934994aa16f60..77d3f93e27c9fd3dc1d129f52ce3a6a863d18582 100644 (file)
@@ -1,12 +1,6 @@
 <?php
 
 // get value of key or default value if key does not exist
-function array_get($key, $array, $default) {
-       if (array_key_exists($key, $array)) return $array[$key];
-       return $default;
-}
-
-
 // gets coordinates and returns an array of lon/lat coordinate pairs, e.g.
 // 47.12 N 11.87 E
 // 47.13 N 11.70 E
@@ -56,36 +50,34 @@ function sledruns_to_json_features() {
 
 // convert XML to geojson (http://www.geojson.org/geojson-spec.html)
 // Returns an array of features
+// TODO: Error reporting
 function xml_to_json_features($input) {
        libxml_use_internal_errors(true); // without that, we get PHP Warnings if the $input is not well-formed
        $xml = new SimpleXMLElement($input); // input
        $json_features = array(); // output
+       $point_type = array('gasthaus' => 'inn', 'haltestelle' => 'busstop', 'parkplatz' => 'carpark', 'achtung' => 'attention', 'punkt' => 'point');
        $line_type = array('rodelbahn' => 'sledrun', 'gehweg' => 'walk', 'alternative' => 'alternative', 'lift' => 'lift', 'linie' => 'line');
        foreach ($xml as $feature) {
                // point
-               if (in_array($feature->getName(), array('gasthaus', 'haltestelle', 'parkplatz', 'punkt'))) {
-                       $wiki = array_get('wiki', $feature, null);
-                       $name = array_get('name', $feature, null);
+               if (in_array($feature->getName(), array_keys($point_type))) {
+                       $properties = array('type' => $point_type[$feature->getName()]);
+                       if (array_key_exists('wiki', $feature)) $properties['wiki'] = $feature['wiki'];
+                       if (array_key_exists('name', $feature)) $properties['name'] = $feature['name'];
                        $json_feature = array(
                                'type' => 'feature',
                                'geometry' => array(
                                        'type' => 'Point',
                                        'coordinates' => geo_to_coordinates($feature)[0]
                                ),
-                               'properties' => array(
-                                       'type' => $feature->getName(),
-                                       'name' => $name,
-                                       'wiki' => $wiki
-                               )
+                               'properties' => $properties
                        );
                        $json_features[] = $json_feature;
                }
                // line
                if (in_array($feature->getName(), array_keys($line_type))) {
-                       $properties = array();
+                       $properties = array('type' => $line_type[$feature->getName()]);
                        if (array_key_exists('farbe', $feature)) $properties['strokeColor'] = $feature['farbe'];
                        if (array_key_exists('dicke', $feature)) $properties['strokeWidth'] = $feature['dicke'];
-                       $properties['type'] = $line_type[$feature->getName()];
                        $json_feature = array(
                                'type' => 'feature',
                                'geometry' => array(
index c3567b5d8d9ab9378f393d3af26ef8b21000db7a..14c8a5ec55bc3dad2efa79b54c4a6d7233dd24c2 100644 (file)
--- a/wrmap.js
+++ b/wrmap.js
@@ -71,11 +71,38 @@ function init_wrmap(i, jq_map) {
        
        // point layer
        // -----------
+       var POINT_NAME = {'inn': 'Gasthaus', 'busstop': 'Haltestelle', 'carpark': 'Parkplatz', 'attention': 'Achtung', 'point': 'Punkt'};
        var layer_point = new OpenLayers.Layer.Vector("Point", {
+               styleMap: new OpenLayers.StyleMap(new OpenLayers.Style({
+                               externalGraphic: '/vorlagen/${getExternalGraphic}',
+                               graphicWidth: 20,
+                               graphicHeight: 34,
+                               graphicXOffset: -10,
+                               graphicYOffset: -33,
+                               title: '${getTitle}'
+                       }, {
+                               context: {
+                                       getExternalGraphic: function(feature) {
+                                               if (feature.attributes.type == 'point') return 'gmap.png';
+                                               var name = POINT_NAME[feature.attributes.type];
+                                               if (name !== undefined) return 'gmap' + name + '.png';
+                                               return 'gmap.png'; // should not happen
+                                       },
+                                       getTitle: function(feature) {
+                                               var title = '';
+                                               if (feature.attributes.type != 'point') {
+                                                       title = POINT_NAME[feature.attributes.type];
+                                                       if (feature.attributes.name !== undefined) title += ': ';
+                                               }
+                                               if (feature.attributes.name !== undefined) title += feature.attributes.name;
+                                               return title;
+                                       }
+                               }
+                       })),
                rendererOptions: {yOrdering: true}
        });
 
-       
+
        // sledrun layer
        // ------------
        var layer_sledrun = new OpenLayers.Layer.Vector("Sledrun", {