Changeset 33185


Ignore:
Timestamp:
2019-06-21T20:37:49+12:00 (5 years ago)
Author:
wy59
Message:
  1. Corrections to map-scripts.js code (e.g. a var had been omitted from a declaration). Reinstated Dr Bainbridge's setting of the bounds during updateMap, as his way preserved the cumulative bounds we were building up and the recently committed 'improvement' had actually tossed this important bit of code away. 3. Major change to doc.pm to store all combinations of Lat and Lng components of CoordShort, since each Lat and Lng can have a different number of decimal places. We need to store all possible combinations since searching requires that, as searching can and does in fact have unequal number of dec places for coordinates (that end up using CoordShort) on occasion. Without this fix, shapes of nearby docs/subsections don't get returned in such cases.
Location:
main/trunk
Files:
2 edited

Legend:

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

    r33171 r33185  
    11101110    #   print STDERR " Tried converting to utf8: $value\n";
    11111111    #    }
     1112
     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
    11121120
    11131121    #If the metadata value is either a latitude or a longitude value then we want to save a shortened version for spacial searching purposes
     
    11531161            my $latitude = $self->get_metadata_element ($section, "Latitude");         
    11541162            # 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
    1155             $self->processCoordinate($section, $latitude, $value); # value is Longitude
     1163            $self->processCoordinate($section, $latitude, $value, $unique_coordshort_map); # value is Longitude
    11561164        }
    11571165    }
     
    11591167    elsif($field eq "GPS.mapOverlay") { # then the value is a JSON string
    11601168   
    1161         # TODO:
    1162         # If we already have Coordinate meta for this section of the document (as can happen during buildcol.pl),
    1163         # let's ASSUME this means we've already processed GPS.mapOverlay meta into Coordinate meta for this section (can have happened during import.pl)
    1164         # to avoid adding duplicate Coordinates meta, which then end up duplicated in the index
    1165         # Of course, the assumption is not always true! We could have an image with embedded Lat and Lng meta,
    1166         # and the same image doc's section could have GPS.mapOverlay meta (from shapes) added via the doc editor.
    1167         # This very function would then have converted Lat/Lng into Coordinate meta (just in the if stmt above) and added it to the section.
    1168         # And then by the time we process this section's GPS.mapOverlay meta here, we would notice the section has Coordinate meta already,
    1169         # and therefore skip converting the GPS.mapOverlay meta into Coordinate meta! What to dooooo?
    1170         # So the return statement immediately below is a temporary solution, until we find a better one that will always work.
     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   
    11711172      if($cmd_line_mode eq "buildcol") {
    11721173       #my $metaMap = $self->get_metadata_hashmap($section); ## TODO: Check if necessary to avoid duplication of <Coordinate> meta in index\text\<coll>.jdb
     
    11761177   
    11771178       
    1178         print STDERR "GPS.mapOverlay before val: " . $value . "\n";
     1179        print STDERR "GPS.mapOverlay before decode, val: " . $value . "\n";
    11791180       
    11801181        # TODO html decode?
     
    11821183        $value =~ s@&#093;@]@g;
    11831184        $value =~ s@&quot;@"@g;
    1184         print STDERR "GPS.mapOverlay after val: " . $value . "\n";
     1185        print STDERR "GPS.mapOverlay after decode, val: " . $value . "\n";
    11851186
    11861187        my $json_array = decode_json $value;
     
    11961197                #print STDERR "Found a circle:\n" . &printShape($json, $shape);
    11971198       
    1198                 # work out bounding box
    1199                 # SCARY!
     1199                # Work out bounding box
    12001200                # want the inverse of this useful page:
    12011201                # https://stackoverflow.com/questions/639695/how-to-convert-latitude-or-longitude-to-meters
     
    12431243                print STDERR "cos $centre_lat is $cos_lat\n";
    12441244
    1245                 $self->processCoordinate($section, $lat_north, $lng_east);
    1246                 $self->processCoordinate($section, $lat_south, $lng_east);
    1247                 $self->processCoordinate($section, $lat_south, $lng_west);
    1248                 $self->processCoordinate($section, $lat_north, $lng_west);
     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);
    12491249           
    12501250            }
     
    12521252                print STDERR "@@ MARKER FOUND WITH LAT: " . $shape->{"position"}->{"lat"} . "\n";
    12531253                print STDERR "@@ MARKER FOUND WITH LNG: " . $shape->{"position"}->{"lng"} . "\n";
    1254                 $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"});               
     1254                $self->processCoordinate($section, $shape->{"position"}->{"lat"}, $shape->{"position"}->{"lng"}, $unique_coordshort_map);               
    12551255            }
    12561256            elsif ($type eq "polyline" || $type eq "polygon") {
    12571257                my $path_array = $shape->{"path"};
    12581258                foreach my $position (@$path_array) {                                   
    1259                     $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"});
     1259                    $self->processCoordinate($section, $position->{"lat"}, $position->{"lng"}, $unique_coordshort_map);
    12601260                }
    12611261            }
     
    12631263       
    12641264                my $bounds = $shape->{"bounds"};
    1265                 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"east"});
    1266                 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"east"});
    1267                 $self->processCoordinate($section, $bounds->{"south"}, $bounds->{"west"});
    1268                 $self->processCoordinate($section, $bounds->{"north"}, $bounds->{"west"});
     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);
    12691269            }   
    12701270       
     
    12721272       #}
    12731273      }
     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     
    12741283    } # end GPS.mapOverlay meta
    12751284
     
    13051314    }
    13061315   
    1307 }   
    1308 
     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.
    13091321sub processCoordinate {
    13101322    my $self = shift (@_);
    1311     my ($section, $latitude, $longitude) = @_;
     1323    my ($section, $latitude, $longitude, $unique_coordshort_map) = @_;
    13121324
    13131325    my $section_ptr = $self->_lookup_section($section);
     
    13381350    }   
    13391351   
    1340     #if(defined $beforeDec && defined $afterDec)
    1341     #{
    1342         my $name = "CoordShort";
    1343         push (@{$section_ptr->{'metadata'}}, [$name, "$latBeforeDec$lat_direction $lngBeforeDec$lng_direction"]);
     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
     1361    for(my $i = 2; $i <= 4; $i++)
     1362    {
     1363        my $latDecPlaces = (length($latAfterDec) >= $i) ? substr($latAfterDec, 0, $i) : "";         
     1364        my $lngDecPlaces = (length($lngAfterDec) >= $i) ? substr($lngAfterDec, 0, $i) : "";
     1365
     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]);
     1371       
     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
    13441379           
    1345         for(my $i = 2; $i <= 4; $i++)
    1346         {
    1347             my $latDecPlaces = (length($latAfterDec) >= $i) ? substr($latAfterDec, 0, $i) : "";         
    1348             my $lngDecPlaces = (length($lngAfterDec) >= $i) ? substr($lngAfterDec, 0, $i) : "";
    1349 
    1350             push (@{$section_ptr->{'metadata'}}, [$name,
    1351                     $latBeforeDec . $lat_direction. $latDecPlaces . " " . $lngBeforeDec . $lng_direction. $lngDecPlaces]);
     1380            #print STDERR "@@@@ pushed new value: " . $coordshort . " into map\n";
    13521381           
    13531382        }
    1354            
    1355         #Only add the metadata if it has not already been added
    1356         #my $metaMap = $self->get_metadata_hashmap($section); ### TODO: metaMap not used. Unnecesssary step? (Called function has no side-effects.)
    1357     #}
    1358 
    1359 
     1383    }
     1384   
     1385   
     1386       
     1387    #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.)
    13601389}
    13611390
  • main/trunk/greenstone3/web/interfaces/default/js/map-scripts.js

    r33184 r33185  
    150150    //Check which increment to use for longitude (i.e. 0.001, 0.01, 0.1 or 1 degree increments)
    151151    var lngDelta;
     152    var lngPrecision;
    152153    for(var i = 3; i >= 0; i--)
    153154    {
     
    205206    var query = "";
    206207    var iMax = Math.floor(latDistance / latDelta) + 1;
    207     var jMax = Math.floor(lngDistance / lngDelta) + 1;;
     208    var jMax = Math.floor(lngDistance / lngDelta) + 1;
    208209    for(var i = 0; i <= iMax; i++) //for(var i = 0; i <= Math.floor(latDistance / latDelta) + 1; i++)
    209210    {
     
    355356        {
    356357            if(doc.shapes) {
    357                 //console.log("@@@ making doc.shapes["+x+"] visible");
    358358                for(var x = 0; x < doc.shapes.length; x++) {                   
    359359                    doc.shapes[x].setVisible(true);
     
    369369        if(doc.shapes) {
    370370            console.log("@@@@ HERE IN doc.shapes");
    371             bounds = ShapesUtil.overlayBounds(doc.shapes);
     371            var docSection_overlay_bounds = ShapesUtil.overlayBounds(doc.shapes);
     372            // We now have the current document or document subsection's bounds.
     373            // Use this to extend the overall bounds (the cumulative bounds for all nearby documents,
     374            // or at least the cumulative bounds for this document with all its subsections).
     375            bounds.extend(docSection_overlay_bounds.getNorthEast());
     376            bounds.extend(docSection_overlay_bounds.getSouthWest());
    372377        }
    373378        else {
Note: See TracChangeset for help on using the changeset viewer.