maplibre / martin

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.
https://martin.maplibre.org
Apache License 2.0
2.33k stars 215 forks source link

How to call the table in the database in the front-end code after using and connecting to postgresql #1438

Closed thunder-gzy closed 4 months ago

thunder-gzy commented 4 months ago

By accessing http://127.0.0.1:8243/catalog, you can get the table information in the postgresql database, but how to call these vector data in the front end? Is there a demo?

sharkAndshark commented 4 months ago

I just wrote a post about working with Martin and Openlayers and MBTiles. And a demo Openlayers code is here:

import "./style.css";
import { Map, View } from "ol";
import MVT from "ol/format/MVT.js";
import TileLayer from "ol/layer/Tile";
import OSM from "ol/source/OSM";
import VectorTileLayer from "ol/layer/VectorTile.js";
import VectorTileSource from "ol/source/VectorTile.js";

let my_layer = new VectorTileLayer({
  source: new VectorTileSource({
    format: new MVT(),
    url: "http://localhost:3000/world_cities/{z}/{x}/{y}",
  }),
});

const map = new Map({
  target: "map",
  layers: [
    new TileLayer({
      source: new OSM(),
    }),
    my_layer,
  ],
  view: new View({
    center: [0, 0],
    zoom: 2,
  }),
});