Hi Gerd

Each 0x4a polygon generated by the OverviewBuilder corresponds to a
detail tile and I avoided changing anything relating to this except
stopping them getting chopped up into SubDivisions by the --order-by
logic (the initial reason for this thread) and outputting them before
the other polygons in the detail tile area.

If the detail tiles are transparent (implemented as none of the input
tiles having a 0x4b polygon), OverviewBuilder adds one. It is generated
as a rectangle covering all the detail tiles rather than the shape of
all the tiles. I've not changed this apart from outputting it first.

A shape that matches all the detail tiles is generated for use by the
DEM overview and could, maybe, be used for the 0x4b. I don't think this
is worth doing as part of this change. 

I haven't made any changes to existing polygons that are input into
OverviewBuilder (from whatever source); all, including 0x4a and 0x4b
are passed on. It is unlikely that a user defined 0x4a polygon would be
correctly set up, and, as seen by Carlos in his Australia map, getting
it wrong has very strange effects as you zoom in and out of the
overview.

I've attached a slightly updated patch - it looks like there was a for
loop that should have been deleted when replaced by a forEach in
OverviewBuilder::addMapCoverageArea

Ticker

On Thu, 2021-01-21 at 06:48 +0000, Gerd Petermann wrote:
> Hi Ticker,
> 
> sorry for the delay, I started a very time consuming mapping in my
> area to unglue landuse areas from highways....
> 
> I looked at overview-v3.patch in more detail. I don't understand the
> changes regarding 0x4a polygons. I am not sure but I think it is a
> step in the wrong direction. I think one goal is to allow arbitrary
> polygons with 0x4 with OSM input (similar to the --dem-polygon) as we
> already do with polish (*.mp) format. So, you should not assume that
> the 0x4a polygon is a rectangle. I might be confusing this with 0x4b
> though.
> Besides that I changed a few things to improve readability.
> 
> Gerd
> 
> ________________________________________
> Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im Auftrag
> von Ticker Berkin <rwb-mkg...@jagit.co.uk>
> Gesendet: Mittwoch, 13. Januar 2021 11:01
> An: Development list for mkgmap
> Betreff: Re: [mkgmap-dev] Tiles pruned in DEM map
> 
> Hi Gerd
> 
> My understanding of the overview map was that it was for BaseCamp and
> MapSource, and it is used instead of the detail tiles as you zoom
> out.
> I had also assumed that it shares the same TYP as the detail tiles.
> For
> --order-by, this TYP will have equal [_drawOrder]. So the overview
> map,
> to display correctly, must also output polygons in the display order.
> 
> Ticker
> 
> On Wed, 2021-01-13 at 09:46 +0000, Gerd Petermann wrote:
> > Hi Ticker,
> > 
> > I fear I don't get it. If --order-by option is only improving the
> > map
> > on the device I see no need to use it for a map that is not used on
> > the device, esp. not when it has negative effects.
> > 
> > Gerd
> > 
> > ________________________________________
> > Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im Auftrag
> > von Ticker Berkin <rwb-mkg...@jagit.co.uk>
> > Gesendet: Mittwoch, 13. Januar 2021 10:41
> > An: Development list for mkgmap
> > Betreff: Re: [mkgmap-dev] Tiles pruned in DEM map
> > 
> > Hi Gerd
> > 
> > I don't think this is the point of the patch.
> > 
> > --order-by is known to increase the size of the main map. This is
> > accepted by users who consider the benefit worthwhile. The overview
> > map, needing to operate in the same environment, has to keep to the
> > same principals and this can lead to a size increase and the effect
> > you
> > mention of a label being off-center, because the named area has
> > been
> > split and the display software labels one part and suppress the
> > label
> > on the other.
> > 
> > A good example depends on finding overlayed polygons that either:
> > 
> > a/ conflict with a given TYP [_drawOrder] - for example, using
> > mapnik.txt, you won't see any land features within Amenity/0x23,
> > Parking/0x05, Industrial/0x0c
> > 
> > b/ have equal [_drawOrder], ie most landuse areas etc, where what
> > will
> > be displayed depends mostly on the internal logic of mkgmap, and,
> > slightly by OSM extract ordering and the original object
> > complexity.
> > 
> > Finding these examples would be tedious. I originally noticed these
> > types of problems because the eTrex HCx starts displaying as soon
> > as
> > possible, and I'd see interesting features disappear from the
> > display
> > as it worked through everything that should be on the screen.
> > 
> > Ticker
> > 
> > 
> > On Wed, 2021-01-13 at 08:21 +0000, Gerd Petermann wrote:
> > > Hi Ticker,
> > > 
> > > I've hoped for a good example that shows how --order-by... really
> > > improves the overview map. I gave an example where the only
> > > visible
> > > difference is a label that is slightly off (so the patch worsens
> > > the
> > > map).
> > > 
> > > Gerd
> > > 
> > > ________________________________________
> > > Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im
> > > Auftrag
> > > von Ticker Berkin <rwb-mkg...@jagit.co.uk>
> > > Gesendet: Montag, 11. Januar 2021 12:39
> > > An: Development list for mkgmap
> > > Betreff: Re: [mkgmap-dev] Tiles pruned in DEM map
> > > 
> > > Hi Gerd
> > > 
> > > Here is an updated patch with the naming changes.
> > > 
> > > Ticker
> > > 
> > > On Wed, 2021-01-06 at 09:35 +0000, Gerd Petermann wrote:
> > > > Hi Ticker,
> > > > 
> > > > OK regarding the naming.
> > > > I think what I tried to point out is that the overview map
> > > > probably
> > > > never suffers the problem that should be solved with the order
> > > > -by
> > > > stuff, but on the other hand we really want to keep that map as
> > > > small
> > > > as possible to allow continent or maybe even planet wide
> > > > overview
> > > > maps.  So, I really prefer to enable the shape merging for the
> > > > overview map.
> > > > A possible work around might be to merge the shapes before
> > > > MapSplitter is executed. The number of points is rather small,
> > > > so
> > > > performance shouldn't be a problem as it is with real OSM data.
> > > > We
> > > > might even use java.awt.area for that.
> > > > Another question is if the --order-by could/should be disabled
> > > > for
> > > > the ovm_ maps.
> > > > 
> > > > Gerd
> > > > 
> > > > ________________________________________
> > > > Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im
> > > > Auftrag
> > > > von Ticker Berkin <rwb-mkg...@jagit.co.uk>
> > > > Gesendet: Mittwoch, 6. Januar 2021 10:19
> > > > An: Development list for mkgmap
> > > > Betreff: Re: [mkgmap-dev] Tiles pruned in DEM map
> > > > 
> > > > Hi Gerd
> > > > 
> > > > Sorry about overview-dem-dists.
> > > > 
> > > > I'd prefer the Map variable to be called IsOverviewComponent to
> > > > make
> > > > clear the distinction between the 2 types of overview and to be
> > > > consistent with the names used in MapBuilder. I can do a patch
> > > > to
> > > > this
> > > > effect.
> > > > 
> > > > --order-by is expected to increase the map size a bit; extra
> > > > polygon
> > > > splitting (in the ovm_ and carried into the composite) is
> > > > performed
> > > > so
> > > > that all polygons at any given point are in the same
> > > > subdivision
> > > > and
> > > > some merges (in both the ovm_ and the composite) are inhibited.
> > > > 
> > > > An overview map is unlikely to have multiple overlayed polygons
> > > > so
> > > > probably there won't be any cases where a fixed _drawOrder
> > > > couldn't
> > > > be
> > > > defined correctly, but it exists with the detail tiles that
> > > > need
> > > > a
> > > > TYP
> > > > where all _drawOrders are equal.
> > > > 
> > > > Ticker
> > > > 
> > > > On Tue, 2021-01-05 at 15:35 +0000, Gerd Petermann wrote:
> > > > > Hi Ticker,
> > > > > 
> > > > > there is a typo in the patch, overview-dem-dists instead of
> > > > > overview
> > > > > -dem-dist. My rather small overview map got 20MB instead of
> > > > > 181K
> > > > > ;)
> > > > > I also didn't like the idea that the overview map is
> > > > > recognized
> > > > > by
> > > > > the name. That can lead to strange effects with test maps, so
> > > > > I
> > > > > added
> > > > > a parameter.
> > > > > 
> > > > > With the corrections the size increases by only by 5K, but I
> > > > > have
> > > > > no
> > > > > idea how these 5K improve the map.
> > > > > I see one small difference where a label of a lake (1)  is
> > > > > placed
> > > > > a
> > > > > bit of the center. The "patched" map contains two polygons
> > > > > for
> > > > > this
> > > > > lake, I assume the Garmin software avoids to render its name
> > > > > twice
> > > > > but uses a different algo to calculate the position. These
> > > > > are
> > > > > the
> > > > > results for my own style, a variant of Minkos OpenFietsMap
> > > > > Light
> > > > > style.
> > > > > Will try again with default style and type file
> > > > > sameOrder.txt.
> > > > > 
> > > > > Gerd
> > > > > (1)
> > > > > https://www.openstreetmap.org/relation/3582977#map=14/53.5815
> > > > > /1
> > > > > 1.
> > > > > 19
> > > > > 91
> > > > > 
> > > > > ________________________________________
> > > > > Von: mkgmap-dev <mkgmap-dev-boun...@lists.mkgmap.org.uk> im
> > > > > Auftrag
> > > > > von Ticker Berkin <rwb-mkg...@jagit.co.uk>
> > > > > Gesendet: Dienstag, 5. Januar 2021 10:58
> > > > > An: Development list for mkgmap
> > > > > Betreff: Re: [mkgmap-dev] Tiles pruned in DEM map
> > > > > 
> > > > > Hi Gerd
> > > > > 
> > > > > shapeMergeFilter.merge() sorts the shapes according to typ,
> > > > > skipSize,
> > > > > fullArea and name. For --order-by to work for the overview,
> > > > > this
> > > > > must
> > > > > not happen; the order in the ovm_ files must be used. This is
> > > > > the
> > > > > same
> > > > > idea as when the more than 1 detail tiles are displayed on a
> > > > > device.
> > > > > 
> > > > > The size of osmmap.img for my test area, with the patch, is:
> > > > >  9216 --no-order-by-decreasing-area throughout
> > > > > 10752 --order-by-decreasing-area throughout
> > > > >  9219 --order-by-decreasing-area at start,
> > > > >       --no-order-by-decreasing-area for the combiners
> > > > > So, there is a slight increase, as expected, it really isn't
> > > > > of
> > > > > any
> > > > > significance.
> > > > > 
> > > > > --order-by-decreasing-area needs to be applied to both phases
> > > > > for
> > > > > it
> > > > > to
> > > > > work correctly.
> > > > > 
> > > > > If applied to the tile phase only, the overview map will
> > > > > render
> > > > > polygons in order of the results of the the shapeMergeFilter.
> > > > > 
> > > > > If applied to the overview phase only, probably similar; the
> > > > > order
> > > > > of
> > > > > the shapeMergeFilter governed ordering in the ovm_ .img
> > > > > 
> > > > > Ticker
> > > > > 
> > > > > On Mon, 2021-01-04 at 18:52 +0000, Gerd Petermann wrote:
> > > > > > Hi Ticker,
> > > > > > 
> > > > > > thanks for the patch. I'll have a closer look during the
> > > > > > next
> > > > > > days.
> > > > > > I
> > > > > > don't yet understand why shapes aren't always merged.
> > > > > > What is the impact on the size of the overview map? What
> > > > > > happens
> > > > > > for
> > > > > > those users who create the overview map in an extra step
> > > > > > that
> > > > > > doesn't
> > > > > > have the --order-by-decreasing-area option? What happens
> > > > > > when
> > > > > > it's
> > > > > > the other way around, no --order-by-decreasing-area option
> > > > > > for
> > > > > > the
> > > > > > tiles but --order-by-decreasing-area for the overview map?
> > > > > > 
> > > > > > Gerd
> > > > > 
> > > > > _______________________________________________
> > > > > mkgmap-dev mailing list
> > > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > > _______________________________________________
> > > > > mkgmap-dev mailing list
> > > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > _______________________________________________
> > > > mkgmap-dev mailing list
> > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > > _______________________________________________
> > > > mkgmap-dev mailing list
> > > > mkgmap-dev@lists.mkgmap.org.uk
> > > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > > _______________________________________________
> > > mkgmap-dev mailing list
> > > mkgmap-dev@lists.mkgmap.org.uk
> > > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > _______________________________________________
> > mkgmap-dev mailing list
> > mkgmap-dev@lists.mkgmap.org.uk
> > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> > _______________________________________________
> > mkgmap-dev mailing list
> > mkgmap-dev@lists.mkgmap.org.uk
> > http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> _______________________________________________
> mkgmap-dev mailing list
> mkgmap-dev@lists.mkgmap.org.uk
> http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
> _______________________________________________
> mkgmap-dev mailing list
> mkgmap-dev@lists.mkgmap.org.uk
> http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev
Index: src/uk/me/parabola/imgfmt/app/map/Map.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/map/Map.java	(revision 4596)
+++ src/uk/me/parabola/imgfmt/app/map/Map.java	(working copy)
@@ -70,6 +70,7 @@
 	private NETFile netFile;
 	private NODFile nodFile;
 	private DEMFile demFile;
+	private boolean isOverviewCombined;
 
 	// Use createMap() or loadMap() instead of creating a map directly.
 	private Map() {
@@ -89,7 +90,7 @@
 	 * @throws FileNotWritableException If the file cannot
 	 * be opened for write.
 	 */
-	public static Map createMap(String mapname, String outputdir, FileSystemParam params, String mapnumber, Sort sort)
+	public static Map createMap(String mapname, String outputdir, FileSystemParam params, String mapnumber, Sort sort, boolean overviewCombined)
 			throws FileExistsException, FileNotWritableException
 	{
 		Map m = new Map();
@@ -103,6 +104,7 @@
 		m.rgnFile = new RGNFile(m.fileSystem.create(mapnumber + ".RGN"));
 		m.treFile = new TREFile(m.fileSystem.create(mapnumber + ".TRE"));
 		m.lblFile = new LBLFile(m.fileSystem.create(mapnumber + ".LBL"), sort);
+		m.isOverviewCombined = overviewCombined;
 
 		int mapid;
 		try {
@@ -118,8 +120,9 @@
 	}
 
 	public void config(EnhancedProperties props) {
+		boolean isOverviewComponent = OverviewBuilder.isOverviewImg(mapName);
 		// we don't want routing info in the overview map (for now)
-		if (!OverviewBuilder.isOverviewImg(mapName)){
+		if (!isOverviewComponent && !isOverviewCombined) {
 			try {
 				if (props.containsKey("route") || props.containsKey("net") || props.containsKey("housenumbers")) {
 					addNet();
@@ -130,6 +133,11 @@
 			} catch (FileExistsException e) {
 				log.warn("Could not add NET and/or NOD sections");
 			}
+			// this sets things like draw-priority/transparent/custom
+			// and not relevant to overview maps
+			treFile.config(props);
+		}
+		if (!isOverviewComponent) { // allow dem on final overview but not in the ovm_
 			if (props.containsKey("dem")) {
 				try {
 					addDem();
@@ -138,7 +146,6 @@
 				}
 			}
 		}
-		treFile.config(props);
 	}
 
 	private void addNet() throws FileExistsException {
Index: src/uk/me/parabola/mkgmap/build/MapBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/build/MapBuilder.java	(revision 4596)
+++ src/uk/me/parabola/mkgmap/build/MapBuilder.java	(working copy)
@@ -74,7 +74,6 @@
 import uk.me.parabola.log.Logger;
 import uk.me.parabola.mkgmap.CommandArgs;
 import uk.me.parabola.mkgmap.Version;
-import uk.me.parabola.mkgmap.combiners.OverviewBuilder;
 import uk.me.parabola.mkgmap.filters.BaseFilter;
 import uk.me.parabola.mkgmap.filters.DouglasPeuckerFilter;
 import uk.me.parabola.mkgmap.filters.FilterConfig;
@@ -127,6 +126,9 @@
 	
 	private static final int MIN_SIZE_LINE = 1;
 
+	private final boolean isOverviewComponent;
+	private final boolean isOverviewCombined;
+
 	private final java.util.Map<MapPoint,POIRecord> poimap = new HashMap<>();
 	private final java.util.Map<MapPoint,City> cityMap = new HashMap<>();
 	private List<String> mapInfo = new ArrayList<>();
@@ -175,10 +177,20 @@
 	private HGTConverter.InterpolationMethod demInterpolationMethod;
 	
 
-	public MapBuilder() {
+	/**
+	 * Construct a new MapBuilder.
+	 * 
+	 * @param overviewComponent set to {@code true} if the map is a work file that
+	 *                          is later used as input for the OverviewBuilder
+	 * @param overviewCombined  set to {@code true} if the map is the combined
+	 *                          overview map
+	 */
+	public MapBuilder(boolean overviewComponent, boolean overviewCombined) {
 		regionName = null;
 		locationAutofill = Collections.emptySet();
 		locator = new Locator();
+		this.isOverviewComponent = overviewComponent;
+		this.isOverviewCombined = overviewCombined;
 	}
 
 	public void config(EnhancedProperties props) {
@@ -218,7 +230,7 @@
 			driveOnLeft = false;
 		orderByDecreasingArea = props.getProperty("order-by-decreasing-area", false);
 		pathsToHGT = props.getProperty("dem", null);
-		demDists = parseDemDists(props.getProperty("dem-dists", "-1"));
+		String demDistStr = props.getProperty("dem-dists", "-1");
 		demOutsidePolygonHeight = (short) props.getProperty("dem-outside-polygon", HGTReader.UNDEF);
 		String demPolygonFile = props.getProperty("dem-poly", null);
 		if (demPolygonFile != null) {
@@ -239,6 +251,18 @@
 			throw new IllegalArgumentException("invalid argument for option dem-interpolation: '" + ipm + 
 					"' supported are 'bilinear', 'bicubic', or 'auto'");
 		}
+
+		if (isOverviewCombined) { // some alternate options, some invalid etc
+			demDistStr = props.getProperty("overview-dem-dist", "-1");
+			mergeLines = true;
+			if (orderByDecreasingArea) {
+				orderByDecreasingArea = false;
+				mergeShapes = false;  // shape order in ovm_ imgs must be preserved to have the effect of above 
+			} else {
+				mergeShapes = true;
+			}
+		}
+		demDists = parseDemDists(demDistStr);
 	}
 
 	private static List<Integer> parseDemDists(String demDists) {
@@ -339,7 +363,7 @@
 					demArea = demPolygon;
 				}
 			} 
-			if (demArea == null && src instanceof OverviewMapDataSource) {
+			if (demArea == null && isOverviewCombined) {
 				Path2D demPoly = ((OverviewMapDataSource) src).getTileAreaPath();
 				if (demPoly != null) {
 					demArea = new java.awt.geom.Area(demPoly);
@@ -732,12 +756,11 @@
 		// The top level has to cover the whole map without subdividing, so
 		// do a special check to make sure.
 		LevelInfo[] levels = null;
-		if (src instanceof OverviewMapDataSource) {
-			mergeLines = true;
-			prepShapesForMerge(src.getShapes());
-			mergeShapes = true;
+		if (isOverviewCombined) {
+			if (mergeShapes)
+				prepShapesForMerge(src.getShapes());
 			levels = src.mapLevels();
-		} else if (OverviewBuilder.isOverviewImg(map.getFilename())) {
+		} else if (isOverviewComponent) {
 			levels = src.overviewMapLevels();
 		} else {
 			levels = src.mapLevels();
@@ -967,7 +990,7 @@
 	private void processInfo(Map map, LoadableMapDataSource src) {
 		// The bounds of the map.
 		map.setBounds(src.getBounds());
-		if (!(src instanceof OverviewMapDataSource))
+		if (!isOverviewCombined)
 			poiDisplayFlags |= TREHeader.POI_FLAG_DETAIL;
 			
 		poiDisplayFlags |= src.getPoiDispFlag();
Index: src/uk/me/parabola/mkgmap/combiners/OverviewBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/OverviewBuilder.java	(revision 4596)
+++ src/uk/me/parabola/mkgmap/combiners/OverviewBuilder.java	(working copy)
@@ -65,8 +65,9 @@
 	private LevelInfo[] wantedLevels;
 	private Area bounds;
 	private boolean hasBackground;
-	private EnhancedProperties demProps = new EnhancedProperties();
-	
+	private EnhancedProperties overviewProps = new EnhancedProperties();
+	private int maxRes = 16; // we can write a 0x4a polygon for planet in res 16.
+
 	public OverviewBuilder() {
 		this.overviewSource = new OverviewMapDataSource();
 	}
@@ -77,13 +78,7 @@
 		overviewMapnumber = args.get("overview-mapnumber", "63240000");
 		
 		outputDir = args.getOutputDir();
-		String demDist = args.getProperties().getProperty("overview-dem-dist");
-		String hgtPath = args.getProperties().getProperty("dem");
-		if (hgtPath != null && demDist != null && !"0".equals(demDist.trim())) {
-			demProps = new EnhancedProperties(args.getProperties());
-			demProps.setProperty("dem-dists", demDist);
-			demProps.setProperty("order-by-decreasing-area", "no");
-		}
+		overviewProps = new EnhancedProperties(args.getProperties());
 	}
 
 	public void onMapEnd(FileInfo finfo) {
@@ -99,7 +94,12 @@
 
 	public void onFinish() {
 		if (!hasBackground) {
+			List<MapShape> shapes = overviewSource.getShapes();
+			int inx = shapes.size();
 			overviewSource.addBackground();
+			// for --order-by-decreasing-area, need the background to be first:
+			if (shapes.size() > inx) // something was added
+				shapes.add(0, shapes.remove(inx));
 		}
 		calcLevels();
 		writeOverviewMap();
@@ -113,31 +113,6 @@
 	}
 
 	private void calcLevels() {
-		int maxRes = 16; // we can write a 0x4a polygon for planet in res 16
-		if (wantedLevels != null)
-			maxRes = wantedLevels[wantedLevels.length-1].getBits();
-		int maxSize = 0xffff << (24 - maxRes);
-		for (MapShape s : overviewSource.getShapes()){
-			if (s.getType() != 0x4a)
-				continue;
-			int maxDimPoly = s.getBounds().getMaxDimension();
-			if (maxDimPoly > maxSize){
-				int oldMaxRes = maxRes; 
-				while (maxDimPoly > maxSize){
-					maxRes--;
-					maxSize = 0xffff << (24 - maxRes);
-				}
-				final String[] name = s.getName().split("\u001d");
-				final String msg = "Tile selection (0x4a) polygon for";
-				final String msg2;
-				if (name.length == 2)
-					msg2 = "tile " + name[1].trim();
-				else 
-					msg2 = s.getBounds().toString(); 
-				log.error(msg, msg2, "cannot be written in level 0 resolution", oldMaxRes + ", using", maxRes, "instead");
-				
-			}
-		}
 		if (wantedLevels == null)
 			setRes(maxRes);
 		else {
@@ -160,6 +135,32 @@
 		}
 	}
 
+ 	/**
+	 * Adjust {@code maxRes} value.
+	 * @param detailTileBounds tile bounds (of ovm_ file)
+	 * @param tileName tile name
+	 */
+	private int checkFixRes(Area detailTileBounds, String tileName) {
+		int newMaxRes = maxRes;
+		int maxSize = 0xffff << (24 - newMaxRes);
+		int maxDimPoly = detailTileBounds.getMaxDimension();
+		if (maxDimPoly > maxSize) {
+			int oldMaxRes = newMaxRes;
+			while (maxDimPoly > maxSize) {
+				newMaxRes--;
+				maxSize = 0xffff << (24 - newMaxRes);
+			}
+			final String msg = "Tile selection (0x4a) polygon for";
+			final String msg2;
+			if (tileName != null)
+				msg2 = "tile " + tileName;
+			else
+				msg2 = detailTileBounds.toString();
+			log.error(msg, msg2, "cannot be written in level 0 resolution", oldMaxRes + ", using", newMaxRes, "instead");
+		}
+		return newMaxRes;
+	}
+
 	/**
 	 * Write out the overview map.
 	 */
@@ -167,7 +168,7 @@
 		if (overviewSource.mapLevels() == null)
 			return;
 		
-		MapBuilder mb = new MapBuilder();
+		MapBuilder mb = new MapBuilder(false, true);
 		mb.setEnableLineCleanFilters(false);
 
 		FileSystemParam params = new FileSystemParam();
@@ -181,12 +182,10 @@
 				codepage = 0; // should not happen
 			}
 			Sort sort = SrtTextReader.sortForCodepage(codepage);
-			Map map = Map.createMap(overviewMapname, outputDir, params, overviewMapnumber, sort);
-			if (!demProps.isEmpty()) {
-				map.config(demProps);
-				mb.config(demProps);
-			}
-			
+			Map map = Map.createMap(overviewMapname, outputDir, params, overviewMapnumber, sort, true);
+			map.config(overviewProps);
+			mb.config(overviewProps);
+
 			if (encodingType != null){
 				map.getLblFile().setEncoder(encodingType, codepage);
 			}
@@ -205,8 +204,6 @@
 	 * @param finfo Information about an individual map.
 	 */
 	private void readFileIntoOverview(FileInfo finfo) throws FileNotFoundException {
-		addMapCoverageArea(finfo);
-
 		MapReader mapReader = null;
 		String filename = finfo.getFilename();
 		if (codepage == null){
@@ -216,7 +213,7 @@
 			System.err.println("WARNING: input file " + filename + " has different code page " + finfo.getCodePage());
 		}
 
-		try{
+		try {
 			mapReader = new MapReader(filename);
 
 			if (encodingType == null){
@@ -262,7 +259,9 @@
 					mapLevels[0] = new LevelInfo(levels[1].getLevel(), levels[1].getResolution());
 				}
 				wantedLevels = mapLevels;
+				maxRes = wantedLevels[wantedLevels.length-1].getBits();
 			}
+			addMapCoverageArea(finfo);
 			if (isOverviewImg(filename)){
 				readPoints(mapReader);
 				readLines(mapReader);
@@ -277,12 +276,11 @@
 
 	/**
 	 * Read the points from the .img file and add them to the overview map.
-	 * We read from the least detailed level (apart from the empty one).
 	 *
 	 * @param mapReader Map reader on the detailed .img file.
 	 */
 	private void readPoints(MapReader mapReader) {
-		Area bounds = overviewSource.getBounds();
+		Area sourceBounds = overviewSource.getBounds();
 		Zoom[] levels = mapReader.getLevels();
 		for (int l = 1; l < levels.length; l++){
 			int min = levels[l].getLevel();
@@ -291,7 +289,7 @@
 			for (Point point: pointList) {
 				if (log.isDebugEnabled())
 					log.debug("got point", point);
-				if (!bounds.contains(point.getLocation())){
+				if (!sourceBounds.contains(point.getLocation())){
 					if (log.isDebugEnabled())
 						log.debug(point, "dropped, is outside of tile boundary");
 					continue;
@@ -312,7 +310,6 @@
 
 	/**
 	 * Read the lines from the .img file and add them to the overview map.
-	 * We read from the least detailed level (apart from the empty one).
 	 *
 	 * @param mapReader Map reader on the detailed .img file.
 	 */
@@ -348,7 +345,6 @@
 
 	/**
 	 * Read the polygons from the .img file and add them to the overview map.
-	 * We read from the least detailed level (apart from the empty one).
 	 *
 	 * @param mapReader Map reader on the detailed .img file.
 	 */
@@ -389,15 +385,16 @@
 	 * Add an area that shows the area covered by a detailed map.  This can
 	 * be an arbitary shape, although at the current time we only support
 	 * rectangles.
+	 * Also build up full overview path (not ness. rectangle) for DEM
+	 * and check/decrease resolution if necessary
 	 *
 	 * @param finfo Information about a detail map.
 	 */
 	private void addMapCoverageArea(FileInfo finfo) {
-		Area bounds = finfo.getBounds();
-		List<Coord> points = bounds.toCoords();
-		for (Coord co: points){
-			overviewSource.addToBounds(co);
-		}
+		List<Coord> points = finfo.getBounds().toCoords();
+		points.forEach(overviewSource::addToBounds);
+		overviewSource.addToTileAreaPath(points);
+		maxRes = checkFixRes(bounds, finfo.getMapname());
 		// Create the tile coverage rectangle
 		MapShape bg = new MapShape();
 		bg.setType(0x4a);
@@ -438,7 +435,7 @@
 		String fname = new File(name).getName();
 		if (fname.startsWith(OVERVIEW_PREFIX))
 			return fname.substring(OVERVIEW_PREFIX.length());
-		else return name;
+		return name;
 	}
 	
 	private static List<String> creMsgList(List<String[]> msgs){
Index: src/uk/me/parabola/mkgmap/main/AbstractTestMap.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/AbstractTestMap.java	(revision 4596)
+++ src/uk/me/parabola/mkgmap/main/AbstractTestMap.java	(working copy)
@@ -55,7 +55,7 @@
 
 		Map map;
 		try {
-			map = Map.createMap("32860003", ".", params, "32860003", SrtTextReader.sortForCodepage(1252));
+			map = Map.createMap("32860003", ".", params, "32860003", SrtTextReader.sortForCodepage(1252), false);
 		} catch (FileExistsException e) {
 			throw new ExitException("File exists already", e);
 		} catch (FileNotWritableException e) {
Index: src/uk/me/parabola/mkgmap/main/MapMaker.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/MapMaker.java	(revision 4596)
+++ src/uk/me/parabola/mkgmap/main/MapMaker.java	(working copy)
@@ -94,7 +94,7 @@
 	 *
 	 * @param args User supplied arguments.
 	 * @param src The data source to load.
-	 * @param mapNameExt 
+	 * @param mapNamePrefix prefix for output file (e.g. ovm_ for overview map component files)
 	 * @return The output filename for the map.
 	 */
 	private String makeMap(CommandArgs args, LoadableMapDataSource src, String mapNamePrefix) {
@@ -107,10 +107,10 @@
 		params.setMapDescription(args.getDescription());
 		log.info("Started making", args.getMapname(), "(" + args.getDescription() + ")");
 		try {
-			Map map = Map.createMap(mapNamePrefix + args.getMapname(), args.getOutputDir(), params, args.getMapname(), sort);
+			Map map = Map.createMap(mapNamePrefix + args.getMapname(), args.getOutputDir(), params, args.getMapname(), sort, false);
 			setOptions(map, args);
 
-			MapBuilder builder = new MapBuilder();
+			MapBuilder builder = new MapBuilder(OverviewBuilder.OVERVIEW_PREFIX.equals(mapNamePrefix), false);
 			builder.config(args.getProperties());
 			builder.makeMap(map, src);
 
Index: src/uk/me/parabola/mkgmap/reader/overview/OverviewMapDataSource.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/overview/OverviewMapDataSource.java	(revision 4596)
+++ src/uk/me/parabola/mkgmap/reader/overview/OverviewMapDataSource.java	(working copy)
@@ -55,6 +55,10 @@
 		return tileAreaPath;
 	}
 
+	public void addToTileAreaPath(List<Coord> points) {
+		tileAreaPath.append(Java2DConverter.createPath2D(points), false);
+	}
+
 	/**
 	 * This is a fake source of data and is not read from a file, so always
 	 * return false here.
@@ -158,10 +162,6 @@
 	 */
 	public void addShape(MapShape shape) {
 		mapper.addShape(shape);
-		if (shape.getType() == 0x4a) {
-			tileAreaPath.append(Java2DConverter.createPath2D(shape.getPoints()),false);
-			
-		}
 	}
 
 	public void addRoad(MapRoad road) {
_______________________________________________
mkgmap-dev mailing list
mkgmap-dev@lists.mkgmap.org.uk
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev

Reply via email to