Giter VIP home page Giter VIP logo

Comments (2)

ahocevar avatar ahocevar commented on June 26, 2024

What you're trying here is definitely possible. However, you might want to start small and then make bigger changes to make debugging easier. Questions that arise include:

  • are the layer minZoom and maxZoom valid?
  • is layer.layerInfo.opacity greater than 0?
  • is the default tilegrid of the VectorTile source correct? Maybe you wanted to apply minZoom and maxZoom there, and not on the layer?
  • Does the style make sense for the data, e.g. is there a source-layer: 'test_hidro', are there polygon geometries in the test_hidro layer?

from ol-mapbox-style.

lukastemberga avatar lukastemberga commented on June 26, 2024

Does the style make sense for the data, e.g. is there a source-layer: 'test_hidro', are there polygon geometries in the test_hidro layer?

This was the issue, I was trying to adjust source property to match name of layer from tegola, while all I had to do was adjust source-layer property to that of layer name coming from tegola. I don't know if there is a way to change source-layer name in mapbox since I made a naming mistake when uploading my data initially therefore .json response always contained wrong source-layer name. In the end I decided to download style and put it into my .../public/ folder and load style from there.

Your help is much appreciated!

I'am closing this issue but here is the way I did it if it helps someone in the future:

JS:

        const vectorTileSource = new VectorTileSource({
            format: new MVT({ featureClass: Feature }),
            url: `${import.meta.env.VITE_TEGOLA_URL}${layer.layerInfo.url}`,
        });
       const vectorTileLayer = new VectorTileLayer({
            source: vectorTileSource,
            //style: layerStyle,
            zIndex: 99999,
            maxZoom: 99,
            minZoom: 0,
            properties: {
                name: layer.label,
                slice: slice ?? "",
                hasZoomConstraint: !!minZoom || !!maxZoom,
                id: layer.id,
                layerType: layer.layerInfo.type,
            },
            declutter: true,
            opacity: 1,
        });

        applyStyle(vectorTileLayer, "/style.json", {
            accessToken: "pk.ey...", // Not sure if needed since I'm loading style locally (.../public/style.json)
            updateSource: false,
        });

        map.addLayer(vectorTileLayer);

style.json

{
    ...
    "layers": [
        {
            "id": "test",
            "type": "fill",
            "source": "composite",
            "source-layer": "test-hidro", // Layer name from tegola capabilities
            "layout": {},
            "paint": {
                "fill-color": [
                    "interpolate",
                    ["linear"],
                    ["zoom"],
                    0,
                    "hsl(308, 100%, 60%)",
                    22,
                    "hsl(308, 100%, 60%)"
                ],
                "fill-outline-color": "hsl(265, 100%, 22%)"
            }
        }
    ],
    ...
}

Tegola capabilities:

{
  "version": "v0.16.0",
  "maps": [
    {
      "name": "my_dataset",
      "attribution": "",
      "bounds": [
        -180,
        -85.0511,
        180,
        85.0511
      ],
      "center": [
        16.5166646,
        43.7333304,
        12
      ],
      "tiles": [
        ".../tegola/maps/my_dataset/{z}/{x}/{y}.pbf"
      ],
      "capabilities": ".../tegola/capabilities/my_dataset.json",
      "layers": [
        {
          "name": "test_hidro",
          "tiles": [
            ".../tegola/maps/data/my_dataset/{z}/{x}/{y}.pbf"
          ],
          "minzoom": 1,
          "maxzoom": 20
        }
      ]
    }
  ]
}

from ol-mapbox-style.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.