Maps display

A provider neutral maps component.

Weblog Licensed under LGPL */

    9:- module(map,
   10	  [
   11	    geo_map//1,
   12	    average_geopoints/2
   13	  ]).   14
   15:- use_module(library(http/html_write)).   16:- use_module(library(settings)).   17
   18:- use_module(weblog(info/maps/google/gmap)).   19:- use_module(weblog(info/maps/leaflet/leafletmap)).   20
   21
   22:- meta_predicate geo_map(1, ?, ?).
 geo_map(+Generator:closure)// is det
Geomap (map of Earth) component.

Generator is an arity n term that corresponds to an arity n+1 predicate.

geo_map//1 will repeatedly query Generator for information and build up the map. The final argument may be

Defining icon types means binding an icon/3 for each type, then binding all the properties

Defining an icon requires that the following be defined for each icon type name:

*/

   90geo_map(Generator) -->
   91	{
   92	     (	 call(Generator, provider(P))
   93	     ;
   94		 P = google
   95	     )
   96	},
   97	make_geo_map(P, Generator).
   98
   99geo_map(_Generator) -->
  100	{
  101		throw(error(domain_error(list, 'provider'), context(geo_map//2,
  102				   'invalid provider')))
  103	},
  104	html([p('error - cannot make map')]).
  105
  106
  107make_geo_map(leaflet, Generator) -->
  108	lmap(Generator).
  109make_geo_map(google, Generator) -->
  110	gmap(Generator).
 average_geopoints(+Points:list, -MeanPoint:point) is det
returns 0,0 for empty list */
  116average_geopoints([] , point(0.0, 0.0)) :- !.
  117average_geopoints(Coordinates, point(ALat, ALong)) :-
  118	sum_geopoints(Coordinates, 0, SumLat, 0, SumLong),
  119	length(Coordinates, Count),
  120	ALat is SumLat/Count,
  121	ALong is SumLong/Count.
  122
  123sum_geopoints([], Lat, Lat, Long, Long).
  124sum_geopoints([point(Lat, Long)|T], Lat0, LatS, Long0, LongS) :-
  125	Lat1 is Lat0+Lat,
  126	Long1 is Long0+Long,
  127	sum_geopoints(T, Lat1, LatS, Long1, LongS)