Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting _minzoom in attribute_function() doesn't work per feature #774

Open
pdrhlik opened this issue Oct 28, 2024 · 0 comments · May be fixed by #778
Open

Setting _minzoom in attribute_function() doesn't work per feature #774

pdrhlik opened this issue Oct 28, 2024 · 0 comments · May be fixed by #778

Comments

@pdrhlik
Copy link

pdrhlik commented Oct 28, 2024

Hi,

I am using tilemaker to create contour tiles. I process some DEM data and use gdal to create shp contours. Each contour line has an elevation attribute. I want to show different contour lines on different zoom levels to reduce the tile size, eg.:

zoom 11: 50 m intervals
zoom 12: 20 m intervals
zoom 13: 10 m intervals
zoom 14: 5 m intervals

Based on the documentation in the Shapefiles and GeoJSON section, this should be possible with a following attribute_function():

function attribute_function(attr, layer)
  if attr["elevation"] then
    local table = {}
    local elevation = math.floor(attr["elevation"])
    local minzoom = 14

    if elevation % 50 == 0 then
      minzoom = 11
    elseif elevation % 20 == 0 then
      minzoom = 12
    elseif elevation % 10 == 0 then
      minzoom = 13
    end

    table["elevation"] = elevation
    table["_minzoom"] = minzoom

    return table
  end

  return attr
end

This is my config.json file for reference.

{
  "layers": {
    "contour": { "minzoom": 11, "maxzoom": 14, "source": "contours/part1.shp", "source_columns": ["elevation"] },
    "contour_2": { "minzoom": 11, "maxzoom": 14, "source": "contours/part2.shp", "source_columns": ["elevation"], "write_to": "contour" },
    "contour_3": { "minzoom": 11, "maxzoom": 14, "source": "contours/part3.shp", "source_columns": ["elevation"], "write_to": "contour" }
  },
  "settings": {
    "minzoom": 11,
    "maxzoom": 14,
    "basezoom": 14,
    "include_ids": false,
    "bounding_box": [-180, -85, 180, 85]
  }
}

Unfortunately, this doesn't work. It seems that the _minzoom isn't applied per feature. Instead, the last _minzoom that is set is applied for the whole layer.

The code handling _minzoom is here (for shapefiles):

if (key=="_minzoom") { minzoom=val; continue; }
attributeStore.addAttribute(attributes, key, (float)val, 0);
layer.attributeMap[key] = 1;

Am I missing something here or is it not working as expected?

Thanks for any input,
Patrik

@pdrhlik pdrhlik linked a pull request Nov 7, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant