diff --git a/data/System/OpenLayersPlugin.txt b/data/System/OpenLayersPlugin.txt index bb069d8..afdadaa 100644 --- a/data/System/OpenLayersPlugin.txt +++ b/data/System/OpenLayersPlugin.txt @@ -1,3 +1,4 @@ +%META:TOPICINFO{author="BaseUserMapping_333" comment="" date="1319162198" format="1.1" version="2"}% %META:TOPICPARENT{name="Plugins"}% ---+ !OpenLayers Plugin @@ -16,29 +17,107 @@ clashes with other extensions that may try to use the same name. *BAD* * Set EXAMPLE = Example setting - * Set FORMAT = %d-%m-%y + * Set FORMAT = %d-%m-%y *Good* * Set EMPTYPLUGIN_EXAMPLE = Example setting - * Set EMPTYPLUGIN_FORMAT = %d-%m-%y - + * Set EMPTYPLUGIN_FORMAT = %d-%m-%y +!OpenLayersMap renders a map using the !OpenLayer javascript library. +---++ Syntax + +=%OPENLAYERSMAP{mapwidth="800" mapheight="600"}%= + +render a [[http://www.demis.nl][DEMIS]] world map + +| *Parameter* | *Description* | *Example* | *Default* | +| =mapwidth= | the width of the map div | | full screen width | +| =mapheight= | the height of the map div | | =600= | +| =viewport= | the longitude,latitude of the viewport | | =159,-38= | +| =viewportzoom= | the default zoom level of viewport, -1 = no zoom. Values range from 1...n-1 (n = mapnumzoomlevels) | | =-1= | +| =layers= | comma separated list of user assigned layerID's. (see below) e.g. ="BaseLayer,Overlay,Environmental"= | | If no layers exist the default Demis map is rendered | +| =layerid_type="WW"=
=layerid_type="WMS"=
=layerid_type="KML"=
=layerid_type="GOOGLE"= | (per layer option) the layer type., e.g. Environmental_type="WMS" | | | +| =layerid_url= | (per layer option) the url for the map server | | | +| =layerid_name= | (per layer option) the display name for the layer | Global Administrative Areas | layerid listed in =layers= | +| =layerid_serverparams= | (per layer option) the parameters that are passed to the map server |e.g. layers: 'ALA:world',srs: 'EPSG:4326',format: 'image/png' | | +| =layerid_clientoptions= | (per layer option) the client options used by the OpenLayers javascript library when rendering the layer in the client's browser, these are not sent to the map server. | =visibility:false, wrapDateLine:true= | | +| =layerid_isbaselayer= | (per layer option) is the layer a base layer on which | | ="on"= | +| =layerid_layeropacity= | (per layer option) the opacity of the layer if =isbaselayer="off"= . Base layers are not semi-transparent | | ="0.5"= | +| =layerid_tilesize= | (per layer option) the tile size to request from the map server | | ="512"= | +| =layerid_zoomlevels= | (per layer option) the width of the map div | | ="11"= | + + +Example + + +%OPENLAYERSMAP{ + mapwidth="600" + layers="myBase,myOverlay" + viewport="159,-32" + viewportzoom="-1" + + myBase_type="WW" + myBase_url="http://www2.demis.nl/wms/ww.ashx?" + myBase_name="Demis World" + myBase_serverparams="T:'WorldMap'" + myBase_clientoptions="tileSize: new OpenLayers.Size(512,512), wrapDateLine:true" + myBase_tilesize="45" + myBase_zoomlevels="11" + + myOverlay_type="WMS" + myOverlay_isbaselayer="off" + myOverlay_layeropacity="0.4" + myOverlay_url="http://spatial.ala.org.au/geoserver/ALA/wms" + myOverlay_name="Global Administrative Areas - World Boundary" + myOverlay_serverparams="layers: 'ALA:world',srs: 'EPSG:4326',format: 'image/png'" + myOverlay_clientoptions="visibility:false, wrapDateLine:true" +}% + + +Preview +%OPENLAYERSMAP{ + mapwidth="600" + layers="myBase,myOverlay" + viewport="159,-32" + viewportzoom="-1" + + myBase_type="WW" + myBase_url="http://www2.demis.nl/wms/ww.ashx?" + myBase_name="Demis World" + myBase_serverparams="T:'WorldMap'" + myBase_clientoptions="tileSize: new OpenLayers.Size(512,512), wrapDateLine:true" + myBase_tilesize="45" + myBase_zoomlevels="11" + + myOverlay_type="WMS" + myOverlay_isbaselayer="off" + myOverlay_layeropacity="0.4" + myOverlay_url="http://spatial.ala.org.au/geoserver/ALA/wms" + myOverlay_name="Global Administrative Areas - World Boundary" + myOverlay_serverparams="layers: 'ALA:world',srs: 'EPSG:4326',format: 'image/png'" + myOverlay_clientoptions="visibility:false, wrapDateLine:true" +}% + + +
+ + ---++ Installation + %$INSTALL_INSTRUCTIONS% ---++ Plugin Info | Author: | Foswiki:Main.PaulAlexander | -| Copyright: | © 2011, [[http://taxonomy.org.au][Taxonomy Research & Information Network]], Foswiki Contributors %BR%\ - This plugin uses [[http://openlayers.org][OpenLayers]] javascript, which is Copyright (c) !OpenLayers Contributors, see [[%ATTACHURLPATH%/scripts/api/2/doc/authors.txt][authors.txt]] | +| Copyright: | © 2011, [[http://taxonomy.org.au][Taxonomy Research & Information Network]], Foswiki Contributors %BR%\ This plugin uses [[http://openlayers.org][OpenLayers]] javascript, which is Copyright (c) !OpenLayers Contributors, see [[%ATTACHURLPATH%/scripts/api/2/doc/authors.txt][authors.txt]] | | License: | This Foswiki plugin is licensed under the GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License Version 3]])%BR% \ - This plugin uses [[http://openlayers.org][OpenLayers]] javascript, which is licensed under the [[%ATTACHURLPATH%/scripts/api/2/license.txt][2-clause BSD License]], which in turn includes code licensed under the [[%ATTACHURLPATH%/scripts/api/2/doc/licenses/APACHE-2.0.txt][Apache 2.0]] and [[%ATTACHURLPATH%/scripts/api/2/doc/licenses/MIT-LICENSE.txt][MIT]] licenses. See [[%ATTACHURLPATH%/scripts/api/2/OpenLayers.js][OpenLayers.js]] for full copyright headers and notices. | +This plugin uses [[http://openlayers.org][OpenLayers]] javascript, which is licensed under the [[%ATTACHURLPATH%/scripts/api/2/license.txt][2-clause BSD License]], which in turn includes code licensed under the [[%ATTACHURLPATH%/scripts/api/2/doc/licenses/APACHE-2.0.txt][Apache 2.0]] and [[%ATTACHURLPATH%/scripts/api/2/doc/licenses/MIT-LICENSE.txt][MIT]] licenses. See [[%ATTACHURLPATH%/scripts/api/2/OpenLayers.js][OpenLayers.js]] for full copyright headers and notices. | | Release: | %$RELEASE% | | Version: | %$VERSION% | -| Change History: |   | +| Change History: | | | XX Mmm 20XX (1.0) | Description of change | | Home: | http://foswiki.org/Extensions/%TOPIC% | | Support: | http://foswiki.org/Support/%TOPIC% | diff --git a/lib/Foswiki/Plugins/OpenLayersPlugin.pm b/lib/Foswiki/Plugins/OpenLayersPlugin.pm index bd94bfe..dc53979 100644 --- a/lib/Foswiki/Plugins/OpenLayersPlugin.pm +++ b/lib/Foswiki/Plugins/OpenLayersPlugin.pm @@ -28,7 +28,7 @@ use Foswiki::Plugins (); # For the API version # extension. our $VERSION = '$Rev$'; -our $RELEASE = '0.1.1'; +our $RELEASE = '1.1.1'; # Short description of this plugin # One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic: @@ -59,6 +59,7 @@ sub initPlugin { "ZonePlugin not installed/enabled...disabling OpenLayersPlugin"); return 0; } + require Foswiki::Plugins::JQueryPlugin; $pubUrlPath = Foswiki::Func::getPubUrlPath(); # $hostUrL = Foswiki::Func::getUrlHost(); @@ -110,25 +111,41 @@ sub _OPENLAYERSMAP { # $params->{_DEFAULT} will be 'hamburger' # $params->{sideorder} will be 'onions' - my $mapElement = $params->{mapelement} || 'openlayersmap'; + my @mapMetadata; - my $mapHeight = $params->{mapheight} || '600'; - my $mapWidth = $params->{mapwidth} || '800'; + my $mapHeight = $params->{mapheight}; + $mapHeight = '600' unless defined $mapHeight; + $mapHeight = $mapHeight.'px'; + push @mapMetadata, "mapHeight:$mapHeight"; + + my $mapWidth = $params->{mapwidth}; + $mapWidth = 'my800' unless defined $mapWidth; + $mapWidth = $mapWidth.'px'; + push @mapMetadata, "mapHeight:$mapWidth"; + + my $mapViewPort = $params->{viewport}; + $mapViewPort = '159,-32' unless defined $mapViewPort; + push @mapMetadata, "mapViewPort:$mapViewPort"; + + my $mapViewPortZoom = $params->{viewportzoom}; + $mapViewPortZoom = '1' unless defined $mapViewPortZoom; + push @mapMetadata, "mapViewPortZoom:$mapViewPortZoom"; my $mapControls = $params->{mapcontrols} || 'ArgParser,Attribution,Navigation,PanZoom'; my $mapControlsArray = $params->{mapcontrolsarray} || 'navigation_control,new OpenLayers.Control.PanZoomBar({}),new OpenLayers.Control.LayerSwitcher({}),new OpenLayers.Control.Permalink(),new OpenLayers.Control.MousePosition({})' ; my $navigationOptions = $params->{navigation} || 'DragPan,ZoomBox,Handler.Click,Handler.Wheel'; my $wheelNavigation = $params->{wheelnavigation} || 'disableWheelNavigation:false'; my $mapcontrolGraticule = $params->{graticule} || 'off'; - my $layerSwitcher = $params->{layerswitcher} || 'on'; +# my $layerSwitcher = $params->{layerswitcher} || 'on'; - my $mapMaxResolution = $params->{mapmaxresolution} || 'auto'; - my $mapMinResolution = $params->{mapminzoomlevel} || 'auto'; + my $mapMaxResolution = $params->{mapmaxresolution} || '45/512'; + my $mapMinResolution = $params->{mapminresulution} || 'auto'; my $mapNumZoomlLevels = $params->{mapnumzoomlevels} || '16'; my $mapMaxScale = $params->{mapmaxscale} || '23'; my $mapMinScale = $params->{mapminscale} || '23'; my $mapProjection = $params->{mapprojection} || 'EPSG:4326'; - my $mapUnits = $params->{mapUnits} || 'degrees'; + my $mapUnits = $params->{mapunits} || 'degrees'; +# my $mapFractionalZoom = $params->{fractionalzoom} || 'on'; my $baseLayerName = $params->{name} || 'Base Layer'; my $baseLayerMinZoomLevel = $params->{baselayerminzoomlevel} || '23'; @@ -156,200 +173,244 @@ sub _OPENLAYERSMAP { my $wmsLayerOpacity = $params->{wmslayeropacity} || 'opacity: .5'; - # sanatize params - - my @mapMetadata = ( - "mapElement: $mapElement", - "mapHeight: $mapHeight", - "mapWidth: $mapWidth", - "mapMaxResolution: $mapMaxResolution", - "mapMinResolution: $mapMinResolution", - "mapNumZoomlLevels: $mapNumZoomlLevels", - "mapMaxScale: $mapMaxScale", - "mapMinScale: $mapMinScale", - "mapProjection: $mapProjection", - "mapUnits: $mapUnits", - ); + my $mapFractionalZoom = $params->{fractionalzoom}; + $mapFractionalZoom = 'on' unless defined $mapFractionalZoom; + $mapFractionalZoom = ($mapFractionalZoom eq 'on')?'true':'false'; + push @mapMetadata, "mapFractionalZoom:$mapFractionalZoom"; Foswiki::Func::addToZone( "script", - "OpenLayersPlugin", - "" + "OPENLAYERSPLUGIN::OPENLAYERMAP::OPENLAYERS", + "", + "OPENLAYERSPLUGIN" ); -# Foswiki::Func::addToZone( -# "script", -# "Googkle_API_3.2", -# "" -# ); - - + Foswiki::Func::addToZone( + "script", + "OPENLAYERSPLUGIN", + "" + ); + my @layerList = (); + my @jsFragments; + my @layerScripts; + my @scriptVariable; + my @createMap; + my $isGoogleLayer; + my $mapLayerSwitcher; my $mapLayers = $params->{layers}; + if ($mapLayers) { foreach my $layerID (split(/\s*,\s*/, $mapLayers)) { push @layerList, $layerID; } - my $mapLayerSwitcher = $params->{layerswitcher}; - $mapLayerSwitcher = 'on' unless defined $mapLayerSwitcher; - $mapLayerSwitcher = ($mapLayerSwitcher eq 'on')?'true':'false'; - push @jsFragment, "mapLayerSwitcher:$mapLayerSwitcher"; + push @createMap, <<"HERE"; + var mapOptions = { maxResolution: $mapMaxResolution, numZoomLevels: $mapNumZoomlLevels, fractionalZoom: $mapFractionalZoom}; + var map = new OpenLayers.Map(mapOptions); +HERE + + $mapLayerSwitcher = $params->{layerswitcher}; + $mapLayerSwitcher = 'off' unless defined $mapLayerSwitcher; + $mapLayerSwitcher = ($mapLayerSwitcher eq 'on')?'true':'false'; + push @mapMetadata, "mapLayerSwitcher:$mapLayerSwitcher"; + if ($mapLayerSwitcher) { + push @createMap, 'map.addControl(new OpenLayers.Control.LayerSwitcher({}));'; } - my @jsFragments; foreach my $layerID (@layerList) { my @jsFragment; + my @layerScript; + # layer ID push @jsFragment, "layerID:'$layerID'"; # layer type my $layerType = $params->{$layerID.'_type'}; - push @jsFragment, "layerType:$layerType" if defined $layerType; # layer server url my $layerURL = $params->{$layerID.'_url'}; - push @jsFragment, "layerURL:$layerURL" if defined $layerURL; # layer name my $layerName = $params->{$layerID.'_name'}; - push @jsFragment, "layerName:$layerName" if defined $layerName; + $layerName = $layerID unless defined $layerName; # server params my $serverParams = $params->{$layerID.'_serverparams'}; - push @jsFragment, "serverParams:$serverParams" if defined $serverParams; # client options my $clientOptions = $params->{$layerID.'_clientoptions'}; - push @jsFragment, "clientOptions:$clientOptions" if defined $clientOptions; # is base layer my $isBaseLayer = $params->{$layerID.'_isbaselayer'}; $isBaseLayer = 'on' unless defined $isBaseLayer; $isBaseLayer = ($isBaseLayer eq 'on')?'true':'false'; - push @jsFragment, "isbaselayer:$isBaseLayer"; + + # layer opacity + my $layerOpacity = $params->{$layerID.'_layeropacity'}; + $layerOpacity = '0.5' unless defined $layerOpacity; # tile size my $tileSize = $params->{$layerID.'_tilesize'}; - push @jsFragment, "tileSize:$tileSize" if defined $tileSize; # zoom levels my $zoomLevels = $params->{$layerID.'_zoomlevels'}; - push @jsFragment, "zoomlevels:$zoomLevels" if defined $zoomLevels; + if ($layerType eq 'WMS') { + push @layerScript, <<"HERE"; + var wmslayer$layerID = new OpenLayers.Layer.WMS( "$layerName", + "$layerURL", + {$serverParams}, {$clientOptions}); + wmslayer$layerID.setIsBaseLayer($isBaseLayer); + map.addLayers([wmslayer$layerID]); +HERE + if ($isBaseLayer eq 'false') { + push @layerScript, "\t\twmslayer$layerID.setOpacity($layerOpacity);\n"; + } + } elsif ($layerType eq 'WW') { + push @layerScript, <<"HERE"; +var wwlayer$layerID = new OpenLayers.Layer.WorldWind( "$layerName", + "$layerURL", $tileSize, $zoomLevels, + {$serverParams}, {$clientOptions}); +map.addLayers([wwlayer$layerID]); +HERE + } elsif ($layerType eq 'GOOGLE') { + $isGoogleLayer = 'true'; + push @layerScript, <<"HERE"; + var googlelayer$layerID = new OpenLayers.Layer.Google( + 'Google Layer', + {} + ); + map.addLayers([googlelayer$layerID]); +HERE + } elsif ($layerType eq 'KML') { + push @layerScript, '/* KML Layer */'; + } elsif ($layerType eq 'VECTOR') { + push @layerScript, <<"HERE"; +var vectorlayer$layerID = new OpenLayers.Layer.Vector("$layerName", + {$clientOptions}); +map.addControl(new OpenLayers.Control.EditingToolbar(vectorlayer$layerID)); +map.addLayers([vectorlayer$layerID]); +HERE + } - # jsFragment + # javascript Fragments push @jsFragments, '{ '.join(', ', @jsFragment).'}'; - } - + # layer scripts + push @layerScripts, @layerScript; - push @mapMetadata, 'jsFragments: ['.join(",\n", @jsFragments).']'; - - - Foswiki::Func::addToZone( - "script", - "OpenLayersPlugin/Javascript", - "" - - . <<"HERE" -" + ); + } - } - -HERE + my $scriptVariable = ""; + Foswiki::Func::addToZone( + "script", + "OPENLAYERSPLUGIN::OPENLAYERSMAP::$mapElement", + "$scriptVariable", + "OPENLAYERSPLUGIN" ); - my $mapMetadata = '{'.join(",\n", @mapMetadata)."}\n"; +# my $mapMetadata = ""; +# Foswiki::Func::addToZone( +# "script", +# "OPENLAYERSPLUGIN::OPENLAYERSMAP::META$mapElement", +# "$mapMetadata", +# "OPENLAYERSPLUGIN" +# ); - Foswiki::Func::addToZone('script', "OpenLayersPlugin/Javascript::$mapElement", $mapMetadata); - return "
"; + return "$mapDiv"; } @@ -365,7 +426,7 @@ NOTE: Please extend that file, not this notice. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. For +of the License, or (at your option) any later version.e For more details read LICENSE in the root of this distribution. This program is distributed in the hope that it will be useful, diff --git a/lib/Foswiki/Plugins/OpenLayersPlugin/MANIFEST b/lib/Foswiki/Plugins/OpenLayersPlugin/MANIFEST index 98925b9..667864b 100644 --- a/lib/Foswiki/Plugins/OpenLayersPlugin/MANIFEST +++ b/lib/Foswiki/Plugins/OpenLayersPlugin/MANIFEST @@ -1831,5 +1831,5 @@ pub/System/OpenLayersPlugin/scripts/api/2/tools/release.sh 0775 pub/System/OpenLayersPlugin/scripts/api/2/tools/shrinksafe.py 0775 pub/System/OpenLayersPlugin/scripts/api/2/tools/toposort.py 0775 pub/System/OpenLayersPlugin/scripts/api/2/tools/update_dev_dir.sh 0775 -test/unit/EmptyPlugin/EmptyPluginSuite.pm 0664 -test/unit/EmptyPlugin/EmptyPluginTests.pm 0664 +test/unit/OpenLayersPlugin/OpenLayersPluginSuite.pm 0664 +test/unit/OpenLayersPlugin/OpenLayersPluginTests.pm 0664 diff --git a/test/unit/EmptyPlugin/EmptyPluginSuite.pm b/test/unit/OpenLayersPlugin/OpenLayersPluginSuite.pm similarity index 100% rename from test/unit/EmptyPlugin/EmptyPluginSuite.pm rename to test/unit/OpenLayersPlugin/OpenLayersPluginSuite.pm diff --git a/test/unit/EmptyPlugin/EmptyPluginTests.pm b/test/unit/OpenLayersPlugin/OpenLayersPluginTests.pm similarity index 100% rename from test/unit/EmptyPlugin/EmptyPluginTests.pm rename to test/unit/OpenLayersPlugin/OpenLayersPluginTests.pm