[Bast-commits] r3207 - in trunk/PhotoOp: lib/PhotoOp/Model root
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Tue Apr 24 11:35:12 GMT 2007
Author: castaway
Date: 2007-04-24 11:35:08 +0100 (Tue, 24 Apr 2007)
New Revision: 3207
Added:
trunk/PhotoOp/lib/PhotoOp/Model/Image.pm
trunk/PhotoOp/root/googlemaps.tt
trunk/PhotoOp/root/openlayers.tt
Log:
Add TT files for googlemaps and openlayers, add Model::Image
Added: trunk/PhotoOp/lib/PhotoOp/Model/Image.pm
===================================================================
--- trunk/PhotoOp/lib/PhotoOp/Model/Image.pm (rev 0)
+++ trunk/PhotoOp/lib/PhotoOp/Model/Image.pm 2007-04-24 10:35:08 UTC (rev 3207)
@@ -0,0 +1,96 @@
+package PhotoOp::Model::Image;
+use warnings;
+use strict;
+use Image::ExifTool;
+## no importing file() and path()
+use Path::Class ();
+
+my $tool = Image::ExifTool->new;
+
+sub new
+{
+ $|++; # DEBUG
+ my ($class, $args) = @_;
+ my $self = bless($args || {}, $class);
+
+ $self->{file} = Path::Class::file($self->{file})
+ unless ref $self->{file} and
+ $self->{file}->isa('Path::Class');
+
+ $self->{tags} = $tool->ImageInfo(''.$self->{file}, '*',
+ {CoordFormat => '%.8f',
+ DateFormat => '%Y:%m:%d %H:%M:%S',
+ Unknown => 2});
+ for my $tag (keys %{$self->{tags}}) {
+ $self->{tags}{$tag} =~ s/^\s+//;
+ $self->{tags}{$tag} =~ s/\s+$//;
+ }
+ if (defined $self->{tags}{GPSLatitude}) {
+ $self->{lat} = $self->{tags}{GPSLatitude}+0;
+ $self->{lon} = $self->{tags}{GPSLongitude}+0;
+ $self->{lat} *= -1 if $self->{tags}{GPSLatitudeRef} eq 'South';
+ $self->{lon} *= -1 if $self->{tags}{GPSLongitudeRef} eq 'West';
+ }
+
+ return $self;
+}
+
+sub file {
+ my ($self) = @_;
+
+ print STDERR "Image::file from ", join(" // ", caller), "\n";
+
+ return $self->{file};
+}
+
+sub get_tags
+{
+ my ($self, @tags) = @_;
+
+ # FIXME: Possibly instead of getting all tags at the top, we should
+ # lazily get them here, possibly even prefetching the simple ones.
+ return (@{$self->{tags}}{@tags});
+}
+
+sub thumbnail {
+ my ($self) = @_;
+
+ return $self->{thumbnail} if exists $self->{thumbnail};
+
+ $self->{thumbnail} = $tool->ImageInfo($self->{file}->stringify, 'ThumbnailImage');
+
+ return $self->{thumbnail};
+}
+
+sub siblingaccessor {
+ my ($self, $type) = @_;
+ return $self->{$type} if (exists $self->{$type});
+ return $self->find_siblings->{$type};
+}
+
+sub leftimage {siblingaccessor(@_, 'leftimage' )};
+sub rightimage {siblingaccessor(@_, 'rightimage')};
+sub leftpath {siblingaccessor(@_, 'leftpath' )};
+sub rightpath {siblingaccessor(@_, 'rightpath' )};
+
+sub find_siblings
+{
+ my ($self) = @_;
+
+ my ($left, $right, $prev);
+ foreach my $d (sort $self->{file}->dir->children)
+ {
+ $left = $prev if($d eq $self->{file} && $prev);
+ $right = $d if($prev && $prev eq $self->{file});
+ $prev = $d;
+ last if($left && $right);
+ }
+
+ ## Create new image objects of left and right.
+ $self->{leftpath} = $left;
+ $self->{rightpath} = $right;
+ $self->{leftimage} = ref($self)->new({file => $left}) if(!$left->is_dir);
+ $self->{rightimage} = ref($self)->new({file => $right}) if(!$right->is_dir);
+
+ return $self;
+}
Property changes on: trunk/PhotoOp/lib/PhotoOp/Model/Image.pm
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/PhotoOp/root/googlemaps.tt
===================================================================
--- trunk/PhotoOp/root/googlemaps.tt (rev 0)
+++ trunk/PhotoOp/root/googlemaps.tt 2007-04-24 10:35:08 UTC (rev 3207)
@@ -0,0 +1,20 @@
+[% MACRO simplemap(lat,lon) BLOCK %]
+ <script type="text/javascript">
+ function map_load_g() {
+ var map = new GMap2(document.getElementById("map_g"));
+ var point = new GLatLng([%lat%], [%lon%]);
+ map.setCenter(point, 14);
+ map.addOverlay(new GMarker(point));
+ map.addControl(new GLargeMapControl());
+ map.addControl(new GMapTypeControl());
+ map.addControl(new GOverviewMapControl());
+
+ GEvent.addListener(map, "click", function(marker, point) {
+ var mylat = document.getElementById("mapclicklat");
+ mylat.innerHTML = point.lat();
+ var mylng = document.getElementById("mapclicklong");
+ mylng.innerHTML = point.lng();
+ });
+ }
+ </script>
+[% END %]
\ No newline at end of file
Property changes on: trunk/PhotoOp/root/googlemaps.tt
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/PhotoOp/root/openlayers.tt
===================================================================
--- trunk/PhotoOp/root/openlayers.tt (rev 0)
+++ trunk/PhotoOp/root/openlayers.tt 2007-04-24 10:35:08 UTC (rev 3207)
@@ -0,0 +1,41 @@
+[% MACRO openlayer(lat, lon) BLOCK %]
+ <script defer='defer' type="text/javascript">
+ var map = new OpenLayers.Map('map_ol', { controls: [] });
+ var wms = new OpenLayers.Layer.WMS('Openstreetmap',
+ 'http://labs.metacarta.com/wms-c/Basic.py?', {layers: 'osm-map'} );
+ map.addLayer(wms);
+ map.addLayer(new OpenLayers.Layer.Google('Google Street'));
+// map.addLayer(new OpenLayers.Layer.Google('Google Satellite', {type: G_SATELLITE_MAP}));
+// map.addLayer(new OpenLayers.Layer.Google('Google Hybrid', {type: G_HYBRID_MAP}));
+ map.addLayer(new OpenLayers.Layer.WorldWind('WorldWind'));
+
+ map.addControl(new OpenLayers.Control.LayerSwitcher());
+ map.addControl(new OpenLayers.Control.PanZoomBar());
+ map.addControl(new OpenLayers.Control.MousePosition());
+// map.zoomToMapExtent();
+
+ var markersLayer = new OpenLayers.Layer.Markers("Current Location");
+ var marker = new OpenLayers.Marker(
+ new OpenLayers.LonLat([% lon %], [% lat %]),
+ new OpenLayers.Icon(
+ "http://openlayers.org/api/img/marker.png",
+ new OpenLayers.Size(10,15)
+ ));
+ markersLayer.addMarker(marker);
+ map.addLayer(markersLayer);
+
+ map.setCenter(marker.lonlat,12);
+
+ OpenLayers.Event.observe($('map_ol'),
+ "dblclick",
+ mapclicked.bindAsEventListener(map));
+ function mapclicked(e) {
+ var point = map.getLonLatFromPixel(e.xy);
+ var mylat = document.getElementById("mapclicklat");
+ mylat.innerHTML = point.lat();
+ var mylng = document.getElementById("mapclicklong");
+ mylng.innerHTML = point.lon();
+ alert("Lat: " + lonlat.lat + " (Pixel.x:" + e.xy.x + ")" + "\n" + "Lon: " + lonlat.lon + " (Pixel.y:" + e.xy.y + ")" );
+ };
+ </script>
+[% END %]
Property changes on: trunk/PhotoOp/root/openlayers.tt
___________________________________________________________________
Name: svn:executable
+ *
More information about the Bast-commits
mailing list