encoding  utf-8
layout 100
code tex-map
  \framethickness=1mm  
endcode
doc-author "M.EGELS"

code metapost
########################################################################################
###########################*#############################################################
#############
#############
#############               Modification des tailles de texte
#############
#############
########################################################################################
########################################################################################

 def a_blocks (expr p) =
     T:=identity;
     pickup PenC;
     path q, qq; q = bbox p;
     picture tmp_pic; 
     uu := max(u, (xpart urcorner q - xpart llcorner q)/100, (ypart urcorner q - ypart llcorner q)/100);
     tmp_pic := image(
       for i = xpart llcorner q step 2uu until xpart urcorner q:
         for j = ypart llcorner q step 2uu until ypart urcorner q:
           qq := punked (((-.5uu,-.5uu)--(.5uu,-.5uu)--(.5uu,.5uu)--(-.5uu,.5uu)--cycle) 
          randomized (uu/2))
                rotated uniformdeviate(360) 
                shifted ((i,j) randomized 1.6uu);
           if xpart (p intersectiontimes qq) < 0:
                thdraw qq;
           fi;
         endfor;  
       endfor;
     );
     clip tmp_pic to p;
     draw tmp_pic;
   enddef;
 def l_u_doline (expr P) =
    T:=identity;
    laenge:= arclength P;
    symsize:=adjust_step(laenge,2u);
    triangle_width:=symsize/10;
    cur:=(symsize-triangle_width)/2;
    pickup PenC;
    forever:
      t1 := arctime (cur) of P;
      t  := arctime (cur + triangle_width/2) of P;
      t2 := arctime (cur + triangle_width) of P;
        thfill (subpath (t1,t2) of P) -- 
          ((point t of P) + symsize/2 * unitvector(thdir(P,t) rotated 90)) -- 
          cycle;
        thdraw (point t2 of P) --((point t of P) + symsize/2 * unitvector(thdir(P,t) rotated 90)) -- 
          (point t1 of P) withcolor (0.5, 0, 0);
      cur := cur + symsize;
      exitif cur > laenge - (1*symsize/3); % for rounding errors
      t1:=arctime (cur) of P;
    endfor;
  enddef;
#fonts_setup(<xs>,<s>,<m>,<l>,<xl>);
fonts_setup(8,14,18,20,25); 
% default values depend on scale; for 1:200 they are 7,8,10,20,30 

  
########################################################################################
########################################################################################
#############
#############
#############               Modification de la fléche du Nord
#############
#############
########################################################################################
########################################################################################
   def s_northarrow (expr rot) =
    begingroup
      interim defaultscale:=0.5; % scale your north arrow here
      T:=identity scaled defaultscale rotated -rot;
      pickup pencircle scaled (0.08cm * defaultscale);
      thdraw (-.4cm,-1.4cm)--(0,2.8cm)--(.4cm,-1.4cm)--cycle;
      p:=fullcircle scaled 1.6cm;
      thclean p; thdraw p;
      p:=(0.95cm,0)--(0.65cm,0);
      thdraw p; thdraw p xscaled -1;
      pickup pencircle scaled (0.12cm * defaultscale);
      p:=(0.28cm,0.42cm);
      thdraw p--(p yscaled -1)--(p xscaled -1)--(p scaled -1);
    endgroup;
  enddef;

    
########################################################################################
########################################################################################
#############
#############
#############               Modification de l'echelle
#############
#############
########################################################################################
########################################################################################


# Echelle
 def s_scalebar (expr l, units, txt) =
     begingroup
       interim warningcheck:=0;
       tmpl:=l / Scale * cm * units / 2;
       tmpx:=l / Scale * cm * units / 5;
       tmph:=5bp; % bar height
     endgroup;
     pickup PenC;
     draw (-tmpl,0)--(tmpl,0)--(tmpl,-tmph)--(-tmpl,-tmph)--cycle;
     p:=(0,0)--(tmpx,0)--(tmpx,-tmph)--(0,-tmph)--cycle;
     for i:=-2.5 step 2 until 2:
       fill p shifted (i * tmpx,0);
     endfor;
     begingroup
       interim labeloffset:=3.5bp;
       for i:=0 step (l/5) until (l-1):
         tmpx:=tmpl * (i * 2 / l - 1);
         label.bot(thTEX(decimal (i)),(tmpx,-tmph));
       endfor;
       label.bot(thTEX(decimal (l) & "\thinspace" & txt) ,(tmpl,-tmph));
       label.top(thTEX("Echelle 1 : " & decimal (Scale*100)),(0,0));
     endgroup;
   enddef;    
def p_altitude(expr pos)=
    T:=identity shifted pos;
    pickup PenD;
    p:=(-.3u,0)--(.3u,0);
    thdraw p; thdraw p rotated 90;
    p:=fullcircle scaled .2u;
    thclean p; thdraw p;
enddef;
   vardef p_label@#(expr txt,pos,rot,mode) =
    if mode=1:
      thdrawoptions(withcolor .8red + .4blue);
      p_altitude(pos);
      % append "m" to label
      picture txtm;
      txtm:=image(
        draw txt;
        interim labeloffset:=0;
        label.urt(btex \thaltitude m etex, lrcorner txt);
      );
      % give extra offset in case of l/r/t/b alignment
      pair ctmp;
      ctmp:=center thelabel@#("x", (0,0));
      if (xpart ctmp * ypart ctmp)=0:
        interim labeloffset:=(.4u);
      else: % diagonal alignment
        interim labeloffset:=(.2u);
      fi;
      % draw label
      lab:=thelabel@#(txtm, pos);
      draw lab _thop_; % use color
      thdrawoptions();
      bboxmargin:=0.8bp;
      write_circ_bbox((bbox lab) smoothed 2);
    else:
      if mode=7: interim labeloffset:=(u/8) fi;
      lab:=thelabel@#(txt, pos);
      if mode>1: pickup PenD fi;
      if mode=2: process_uplabel;
      elseif mode=3: process_downlabel;
      elseif mode=4: process_updownlabel;
      elseif mode=5: process_circledlabel;
      elseif mode=6: process_boxedlabel;
      elseif mode=7: process_label(pos,rot);  % station name
      elseif mode=8: process_filledlabel(pos, rot);
      else: process_label(pos,rot); fi;
    fi;
  enddef;
  
  
  
  
  #################################################
  #################################################
  ####                      ###
  ####    Blocs                ###
  #################################################
  #################################################
 
  code metapost
    def a_blocks (expr p) =
      distance:=1;
      T:=identity;
      pickup PenC;
      path q, qq; q = bbox p;
      picture tmp_pic; 
      uu := max(u, (xpart urcorner q - xpart llcorner q)/100, (ypart urcorner q - ypart     llcorner q)/100);
      tmp_pic := image(
        for i = xpart llcorner q step distance*uu until xpart urcorner q:
          for j = ypart llcorner q step distance*uu until ypart urcorner q:
            qq := punked (((-.5uu,-.5uu)--(.5uu,-.5uu)--(.5uu,.5uu)--(-.5uu,.5uu)--cycle) 
          randomized (uu/10))
                 rotated uniformdeviate(360) 
                 shifted ((i,j) randomized 1.0uu);
      if xpart (p intersectiontimes qq) < 0:
        thclean qq;
        thdraw qq;
      fi;
          endfor;  
        endfor;
      );
      clip tmp_pic to p;
      draw tmp_pic;
    enddef;
    def a_u_eau (expr p) =
      T:=identity;
      thfill p withcolor (0.1, 0.2, 0.8);
    enddef;  
  endcode
  
##################################################################################
##################################################################################
####
####        Modification des couleurs
####
####
##################################################################################
##################################################################################

  
#colour map-fg [98 87 38] #couleur carte jaune pale
#colour map-fg [100 100 79] #couleur carte jaune pale
colour map-bg [100 100 100] #couleur fond de carte blanc
#colour map-fg altitude #couleur carte jaune pale
color map-fg topo-date
  
  

    
  transparency on
  opacity 70
  language fr
 # grid-size 10 10 10 m
 # grid bottom
 # surface bottom
  surface-opacity 70
  legend off
 # map-header  75 50 sw
 # statistics topo-length on 
 # statistics explo-length on
  symbol-set UIS
 #symbol-hide point label
 # symbol-hide line label
  symbol-hide group cave-centerline
# symbol-color group water-flow [10  20  80]
  symbol-colour point water-flow  [10  20  80]
  symbol-colour line water-flow  [10  20  80]  
    
  symbol-hide point cave-station
 cs UTM30  
 grid-origin 0 0 1520 m
 scale 1 100
base-scale 1 50

endlayout
#lookup topo-altitude -title "Profondeur"
#[2018] [98 87 38] "Exploré en 2018"
#[2019] [94 77 42] "Exploré en 2019" 
#endlookup
lookup topo-date -title "Date d'exploration"
[2018] [98 87 38] "Exploré en 2018"
[2019] [94 77 42] "Exploré en 2019" 
endlookup

