From: <lph...@us...> - 2011-11-29 23:34:05
|
Revision: 39051 http://tikiwiki.svn.sourceforge.net/tikiwiki/?rev=39051&view=rev Author: lphuberdeau Date: 2011-11-29 23:33:59 +0000 (Tue, 29 Nov 2011) Log Message: ----------- [MOD] Allow arg variable-like syntax in appframe page inclusion, render map on set coordinates when using the map plugin Modified Paths: -------------- trunk/lib/jquery_tiki/tiki-maps.js trunk/lib/wiki-plugins/wikiplugin_appframe.php trunk/lib/wiki-plugins/wikiplugin_map.php Modified: trunk/lib/jquery_tiki/tiki-maps.js =================================================================== --- trunk/lib/jquery_tiki/tiki-maps.js 2011-11-29 23:08:36 UTC (rev 39050) +++ trunk/lib/jquery_tiki/tiki-maps.js 2011-11-29 23:33:59 UTC (rev 39051) @@ -82,6 +82,20 @@ return layers; } + function parseCoordinates(value) { + var matching = value.match(/^(-?[0-9]*(\.[0-9]+)?),(-?[0-9]*(\.[0-9]+)?)(,(.*))?$/); + + if (matching) { + var lat = parseFloat(matching[3]); + var lon = parseFloat(matching[1]); + var zoom = matching[6] ? parseInt(matching[6], 10) : 0; + + return {lat: lat, lon: lon, zoom: zoom}; + } + + return null; + } + $.fn.createMap = function () { this.each(function () { var id = $(this).attr('id'), container = this, desiredControls; @@ -312,7 +326,7 @@ } var field = $(container).data('target-field'); - var central = null; + var central = null, useMarker = true; if (field) { field = $($(container).closest('form')[0][field]); @@ -321,15 +335,7 @@ field: field }); var value = field.val(); - var matching = value.match(/^(-?[0-9]*(\.[0-9]+)?),(-?[0-9]*(\.[0-9]+)?)(,(.*))?$/); - - if (matching) { - var lat = parseFloat(matching[3]); - var lon = parseFloat(matching[1]); - var zoom = matching[6] ? parseInt(matching[6], 10) : 0; - - central = {lat: lat, lon: lon, zoom: zoom}; - } + central = parseCoordinates(value); } if ($(container).data('marker-filter')) { @@ -369,6 +375,13 @@ }); } + var provided = $(container).data('geo-center'); + + if (provided) { + central = parseCoordinates(provided); + useMarker = false; + } + if (central) { var lonlat = new OpenLayers.LonLat(central.lon, central.lat).transform( new OpenLayers.Projection("EPSG:4326"), @@ -376,11 +389,13 @@ ); map.setCenter(lonlat, central.zoom); - $(container).addMapMarker({ - lon: central.lon, - lat: central.lat, - unique: 'selection' - }); + if (useMarker) { + $(container).addMapMarker({ + lon: central.lon, + lat: central.lat, + unique: 'selection' + }); + } } if (jqueryTiki.googleStreetView) { Modified: trunk/lib/wiki-plugins/wikiplugin_appframe.php =================================================================== --- trunk/lib/wiki-plugins/wikiplugin_appframe.php 2011-11-29 23:08:36 UTC (rev 39050) +++ trunk/lib/wiki-plugins/wikiplugin_appframe.php 2011-11-29 23:33:59 UTC (rev 39051) @@ -180,6 +180,14 @@ return null; } + $keys = array(); + $replacements = array(); + foreach ($params as $key => $value) { + $keys[] = "{{{$key}}}"; + $replacements = $value; + } + $info['data'] = str_replace($keys, $replacements, $info['data']); + return "~/np~{$info['data']}~np~"; } Modified: trunk/lib/wiki-plugins/wikiplugin_map.php =================================================================== --- trunk/lib/wiki-plugins/wikiplugin_map.php 2011-11-29 23:08:36 UTC (rev 39050) +++ trunk/lib/wiki-plugins/wikiplugin_map.php 2011-11-29 23:33:59 UTC (rev 39051) @@ -43,6 +43,12 @@ 'description' => tra('Height of the map in pixels'), 'filter' => 'int', ), + 'center' => array( + 'requied' => false, + 'name' => tr('Center'), + 'description' => tr('Center and zoom level of the map display.'), + 'filter' => 'text', + ), 'mapfile' => array( 'required' => false, 'name' => tra('MapServer File'), @@ -100,9 +106,18 @@ $controls = array_intersect($params['controls'], wp_map_available_controls()); $controls = implode(',', $controls); + $center = null; + if (isset($params['center'])) { + $geolib = TikiLib::lib('geo'); + if ($coords = $geolib->parse_coordinates($params['center'])) { + $center = ' data-geo-center="' . smarty_modifier_escape($geolib->build_location_string($coords)) . '" '; + } + } + TikiLib::lib('header')->add_map(); $scope = smarty_modifier_escape(wp_map_getscope($params)); - return "<div class=\"map-container\" data-marker-filter=\"$scope\" data-map-controls=\"{$controls}\" style=\"width: {$width}; height: {$height};\"></div>"; + + return "<div class=\"map-container\" data-marker-filter=\"$scope\" data-map-controls=\"{$controls}\" style=\"width: {$width}; height: {$height};\" $center></div>"; } function wp_map_getscope($params) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |