$width_s = (isset($properties['width'])) ? (string) $properties['width'] . 'px' : '100%';
$height_s = (isset($properties['height']) ? (string) $properties['height'] : 450) . 'px';
$output = "<div class=\"wrmap\" style=\"width: $width_s; height: $height_s; border-style:none;\" data-img-path=\"$wgExtensionAssetsPath/wrmap/openlayers/img/\">";
- $output .= "<script type=\"application/json\">";
$output .= htmlspecialchars($json_string, ENT_NOQUOTES);
- $output .= "</script>";
$output .= "</div>\n";
return $output;
function init_wrmap(i, jq_map) {
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();
-
+ var json_string = jq_map.text();
+ jq_map.empty(); // once parsed, remove geojson string from the map element.
// extract, tranform and split features to layers
var EPSG4326 = new OpenLayers.Projection("EPSG:4326"); // lon/lat
coordinates.
-For transmitting the map to javascript, geojson is used in a <script> block. This way,
-an extra request is avoided. The geojson format used here consists of a single
+For transmitting the map to javascript, geojson is used in the <div> element of the map.
+This way, an extra request is avoided. The geojson format used here consists of a single
"FeatureCollection" (representing the <wrmap>) containing the sub-elements of wrmap
as features.
The features have an properties key that has a hash as values with the properties of