Changeset 33217 for main


Ignore:
Timestamp:
2019-06-24T16:41:04+12:00 (5 years ago)
Author:
wy59
Message:
  1. Undoing the change to doc.pm committed in revision 33185: not storing all combinations of precision for Lat and Long in CoordShorts. Instead, Dr Bainbridge fixed up map-scripts.js to ensure that the requested precision (num decimal places) for Lat and Lng in a CoordShort are now the same. The chosen precision for both is set to whichever of the two is more zoomed out, which work out to be whichever of the two has fewer decimal places. 2. Dr Bainbridge and Martin set min-height when mapEnabled to ensure the footer didn't interfere in the map. 3. classifier-scripts' httpRequest() renamed to httpBrowseRequest() and map's getSubClassifier() renamed to httpMapBrowseRequest().
Location:
main/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/doc.pm

    r33185 r33217  
    11111111    #    }
    11121112
    1113    
    1114     # for every GPS.mapOverlay/sectionID (but sadly not for every doc, let alone every collection),
    1115     # we use a map to ensure uniqueness of CoordShorts for optimisation purposes
    1116     # That way we don't end up with the same CoordShort values a large number of times in the index
    1117     # We only get any savings with GPS.mapOverlay when using this map, not for "Latitude" and "Longitude" metadata
    1118     my $unique_coordshort_map = {};
    1119 
    1120 
    11211113    #If the metadata value is either a latitude or a longitude value then we want to save a shortened version for spacial searching purposes
    11221114    if ($field =~ m/^(.+\.)?Latitude$/ || $field =~ m/^(.+\.)?Longitude$/)
     
    11531145           
    11541146            #Only add the metadata if it has not already been added
    1155             my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no side-effects.)
     1147            my $metaMap = $self->get_metadata_hashmap($section); # metaMap not used and called function has no apparent side-effects,
     1148                                                                 # but this line appears important for ensuring uniqueness of (Latitude, value) meta
     1149                                                                 # in the section. Also for LatShort, Longitude, LngShort.
    11561150        }
    11571151       
     
    11591153            # if we are dealing with Longitude meta, we should 1. have Latitude meta too; 2. already have processed Latitude meta
    11601154            # in that case, add both Lat and Lng of this section as a Coordinate meta
    1161             my $latitude = $self->get_metadata_element ($section, "Latitude");         
    1162             # TODO: would like all Longitude info together followed by all Coordinate info, but the following will add all coord info meta and end of this function will add Longitude meta
    1163             $self->processCoordinate($section, $latitude, $value, $unique_coordshort_map); # value is Longitude
     1155            my $latitude = $self->get_metadata_element ($section, "Latitude");
     1156            my $longitude = $value;
     1157            # TODO: would like all Longitude meta placed together, followed by all Coordinate meta,
     1158            # but the following will add all such coord meta to the doc object and the end of this function will add Longitude meta
     1159            $self->processCoordinate($section, $latitude, $longitude);
    11641160        }
    11651161    }
    11661162
    11671163    elsif($field eq "GPS.mapOverlay") { # then the value is a JSON string
    1168    
    1169         # TODO: How can we prevent GPS.mapOverlay from being processed 4 or so times by buildcol.pl??
    1170         # Once for each pass (dummy, sidx, didx for lucene, info db pass)
    1171    
     1164
    11721165      if($cmd_line_mode eq "buildcol") {
    11731166       #my $metaMap = $self->get_metadata_hashmap($section); ## TODO: Check if necessary to avoid duplication of <Coordinate> meta in index\text\<coll>.jdb
     
    11771170   
    11781171       
    1179         print STDERR "GPS.mapOverlay before decode, val: " . $value . "\n";
     1172        print STDERR "GPS.mapOverlay before decoding, val = " . $value . "\n";
    11801173       
    11811174        # TODO html decode?
     
    11831176        $value =~ s@&#093;@]@g;
    11841177        $value =~ s@&quot;@"@g;
    1185         print STDERR "GPS.mapOverlay after decode, val: " . $value . "\n";
     1178        print STDERR "GPS.mapOverlay after decoding, val = " . $value . "\n";
    11861179
    11871180        my $json_array = decode_json $value;
     
    11971190                #print STDERR "Found a circle:\n" . &printShape($json, $shape);
    11981191       
    1199                 # Work out bounding box
     1192                # work out bounding box
    12001193                # want the inverse of this useful page:
    12011194                # https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters
    1202                 # https://www.geodatasource.com/developers/javascript       
    1203                
    1204                            
    1205                 # for now, just process the circle centre
    1206                 #my $centre = $shape->{"center"};               
    1207                 #$self->processLatOrLng($section_ptr, "Latitude", $centre->{"lat"});
    1208                 #$self->processLatOrLng($section_ptr, "Longitude", $centre->{"lng"});
    1209 
     1195                # https://www.geodatasource.com/developers/javascript               
    12101196               
    12111197                # Dr Bainbridge wants us to use: https://gis.stackexchange.com/questions/5821/calculating-latitude-longitude-x-miles-from-point
    1212                 # But we're using the rule of thumb here, since for N,E,S,W it works out the same:
     1198                # Since for N,E,S,W the following works out the same as above link, we're using the rule of thumb in the following:
    12131199                # https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters
    12141200                # which states
     
    12291215
    12301216                # our latitude and longitude values are in degrees. But cos and sin etc in perl and generally all prog languages
    1231                 # all expect their angle to be in radians. So need to convert from degree to radians before we can take the cose of it.
     1217                # all expect their angle to be in radians. So need to convert from degree to radians before we can take the cos of it.
    12321218                my $centre_lat_radians = $self->degreesToRadians($centre_lat);
    12331219                my $cos_in_radians = cos($centre_lat_radians);             
     
    12381224                print STDERR "### lng_west  $lng_west\n";
    12391225
    1240 
    1241 
    12421226                my $cos_lat = cos($centre_lat);             
    12431227                print STDERR "cos $centre_lat is $cos_lat\n";
    12441228
    1245                 $self->processCoordinate($section, $lat_north, $lng_east, $unique_coordshort_map);
    1246                 $self->processCoordinate($section, $lat_south, $lng_east, $unique_coordshort_map);
    1247                 $self->processCoordinate($section, $lat_south, $lng_west, $unique_coordshort_map);
    1248                 $self->processCoordinate($section, $lat_north, $lng_west, $unique_coordshort_map);
     1229                $self->processCoordinate($section, $lat_north, $lng_east);
     1230                $self->processCoordinate($section, $lat_south, $lng_east);
     1231                $self->processCoordinate($section, $lat_south, $lng_west);
     1232                $self->processCoordinate($section, $lat_north, $lng_west);
    12491233           
    12501234            }
     
    12521236                print STDERR "@@ MARKER FOUND WITH LAT: " . $shape->{"position"}->{"lat"} . "\n";
    12531237                print STDERR "@@ MARKER FOUND WITH LNG: " . $shape->{"position"}->{"lng"} . "\n";
    1254                 $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"}, $unique_coordshort_map);               
     1238                $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"});               
    12551239            }
    12561240            elsif ($type eq "polyline" || $type eq "polygon") {
    12571241                my $path_array = $shape->{"path"};
    12581242                foreach my $position (@$path_array) {                                   
    1259                     $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"}, $unique_coordshort_map);
     1243                    $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"});
    12601244                }
    12611245            }
     
    12631247       
    12641248                my $bounds = $shape->{"bounds"};
    1265                 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"east"}, $unique_coordshort_map);
    1266                 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"east"}, $unique_coordshort_map);
    1267                 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"west"}, $unique_coordshort_map);
    1268                 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"west"}, $unique_coordshort_map);
     1249                $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"east"});
     1250                $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"east"});
     1251                $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"west"});
     1252                $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"west"});
    12691253            }   
    12701254       
     
    12721256       #}
    12731257      }
    1274 
    1275       # We haven't yet written out any Coordshort meta! Write those out now,
    1276       # since we've now finally ensured they're all unique CoordShort meta for this GPS.mapOverlay at least.
    1277       foreach my $coordshort (keys %$unique_coordshort_map) {
    1278 
    1279         #print STDERR "@@@@ creating new coordshort: $coordshort\n";
    1280         push (@{$section_ptr->{'metadata'}}, ["CoordShort", $coordshort ]);
    1281       }
    1282      
    12831258    } # end GPS.mapOverlay meta
    12841259
     
    13111286        my $pretty_print_shape = $json->pretty->encode( $shape );
    13121287        print STDERR "Shape: $pretty_print_shape\n";
    1313         #&printShape($shape);
    1314     }
    1315    
    1316 }
    1317 
    1318 # Beware: this method now ONLY writes out the Coordinate meta, but not the CoordShorts
    1319 # At method's end, the CoordShorts are stored in the $unique_coordshort_map (for optimisation),
    1320 # ready to be added to the doc section's meta once all Coordinates in a GPS.mapOverlay are done being processed.
     1288    }
     1289   
     1290}
     1291
     1292# For the (lat, lng) coordinate given,
     1293# attaches Coordinate and multiple CoordShort (different precision level) metadata to the doc object
    13211294sub processCoordinate {
    13221295    my $self = shift (@_);
    1323     my ($section, $latitude, $longitude, $unique_coordshort_map) = @_;
     1296    my ($section, $latitude, $longitude) = @_;
    13241297
    13251298    my $section_ptr = $self->_lookup_section($section);
     
    13501323    }   
    13511324   
    1352     # We have to deal with 0 decimal places for either lat or lng, or no dec places for only one of them
    1353     # And we have to store all combinations of lats and lngs as CoordShort.
    1354    
    1355     #my $name = "CoordShort";
    1356     #push (@{$section_ptr->{'metadata'}}, [$name, "$latBeforeDec$lat_direction $lngBeforeDec$lng_direction"]);
    1357 
    1358     my @lat_array = ("$latBeforeDec$lat_direction");
    1359     my @lng_array = ("$lngBeforeDec$lng_direction");
    1360 
     1325
     1326    my $name = "CoordShort";
     1327    push (@{$section_ptr->{'metadata'}}, [$name, "$latBeforeDec$lat_direction $lngBeforeDec$lng_direction"]);
     1328       
    13611329    for(my $i = 2; $i <= 4; $i++)
    13621330    {
     
    13641332        my $lngDecPlaces = (length($lngAfterDec) >= $i) ? substr($lngAfterDec, 0, $i) : "";
    13651333
    1366         push(@lat_array, $latBeforeDec . $lat_direction. $latDecPlaces) unless $latDecPlaces eq "";
    1367         push(@lng_array, $lngBeforeDec . $lng_direction. $lngDecPlaces) unless $lngDecPlaces eq "";
    1368 
    1369         #push (@{$section_ptr->{'metadata'}}, [$name,
    1370         #       $latBeforeDec . $lat_direction. $latDecPlaces . " " . $lngBeforeDec . $lng_direction. $lngDecPlaces]);
     1334        push (@{$section_ptr->{'metadata'}}, [$name,
     1335                $latBeforeDec . $lat_direction. $latDecPlaces . " " . $lngBeforeDec . $lng_direction. $lngDecPlaces]);
    13711336       
    1372     }       
    1373        
    1374     for(my $i = 0; $i < scalar(@lat_array); $i++) {
    1375         for(my $j = 0; $j < scalar(@lng_array); $j++) {
    1376             #push (@{$section_ptr->{'metadata'}}, [$name, $lat_array[$i] . " " . $lng_array[$j] ]);
    1377             my $coordshort = $lat_array[$i] . " " . $lng_array[$j];
    1378             $unique_coordshort_map->{$coordshort} = "1"; # just store it
    1379            
    1380             #print STDERR "@@@@ pushed new value: " . $coordshort . " into map\n";
    1381            
    1382         }
    1383     }
    1384    
    1385    
     1337    }
    13861338       
    13871339    #Only add the metadata if it has not already been added
    1388     #my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no side-effects.)
     1340    #my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no apparent side-effects.)
    13891341}
    13901342
  • main/trunk/greenstone3/web/interfaces/default/js/classifier_scripts.js

    r33187 r33217  
    5353    else
    5454    {
    55         httpRequest(sectionID);
     55        httpBrowseRequest(sectionID);
    5656    }
    5757}
     
    114114}
    115115
    116 function httpRequest(sectionID)
     116function httpBrowseRequest(sectionID)
    117117{
    118118    if(!inProgress[sectionID])
     
    156156            updateOpenClassifiers();           
    157157            if(typeof mapEnabled !== 'undefined'){
    158                 getSubClassifier(sectionID);
     158                httpMapBrowseRequest(sectionID);
    159159            }
    160160        })
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js

    r33187 r33217  
    3535        {
    3636            mapEnabled = true;
     37            var resultsArea = $('#resultsArea');
     38            if (resultsArea.length > 0){
     39                resultsArea.css('min-height','500px');
     40            }
    3741            for(var i = 0; i < jsonNodes.length; i++)
    3842            {
     
    167171    {
    168172        lngDelta = (1 / Math.pow(10, i));
     173        // Want the grid superimposed on the map to be 5 or fewer steps,
     174        // where delta is the grid size to make it so
     175        // and precision is the number of decimal places.
    169176        if((lngDistance / lngDelta) <= 5 || lngDelta == 1)
    170177        {
     
    172179            break;
    173180        }
    174     }
    175 
     181    }   
     182   
    176183    if(latDelta == 0.1){latDelta = 1; latPrecision = 0; }
    177184    if(lngDelta == 0.1){lngDelta = 1; lngPrecision = 0; }
     185   
     186   
     187    // Want consistent precision for both lat and lng.
     188    // So we choose the most conservative (whichever is more zoomed out) for both
     189    if(latPrecision < lngPrecision) {
     190        lngPrecision = latPrecision;
     191    } else if (lngPrecision < latPrecision) {
     192        latPrecision = lngPrecision;
     193    }
    178194   
    179195    /*
     
    778794}
    779795
    780 function getSubClassifier(sectionID)
    781 {
     796function httpMapBrowseRequest(sectionID)
     797{
     798    // Make ajax call to retrieve jsonNodes for section ID, and draw shapes on the map.
    782799    var url = gs.xsltParams.library_name + "?a=b&rt=s&s=ClassifierBrowse&c=" + gs.cgiParams.c + "&cl=" + sectionID + "&excerptid=jsonNodes";
    783800    $.ajax(url)
Note: See TracChangeset for help on using the changeset viewer.