Skip to content

FenceLayer


ts
/*
 * @Author: jiegiser changjie@jouav.com
 * @Date: 2023-11-28 11:44:34
 * @LastEditors: jiegiser changjie@jouav.com
 * @LastEditTime: 2023-11-28 11:45:05
 * @Description: 请填写简介
 */
import { Map } from "maplibre-gl";
import { ThreeGISMap } from "@jodvf/three-gis-map";
import * as maplibregl from "maplibre-gl";

const container = document.createElement("div");
container.style.width = "100%";
container.style.height = "100%";
document.body.appendChild(container);

const map = new Map({
  container: container,
  style:
    "https://api.maptiler.com/maps/b01b290f-bdf7-452e-9a34-f6e300dacc4f/style.json?key=MNqni2pVxL0GkkL0hgYb", // stylesheet location
  maxPitch: 85,
  center: [104.07410531052449, 30.656418650992663],
  pitch: 50,
  zoom: 2.5
});

window.maplibregl = maplibregl;
const joGISThree = new ThreeGISMap(map, maplibregl, {
  projection: "EPSG:3857"
});

joGISThree.on("jogisthree.load", () => {
  createFenceLayer();
});

function createFenceLayer() {
  const fencelLayer = joGISThree.addLayer({
    type: "fence",
    id: "fence-layer",
    minzoom: 1,
    // gradients: [
    //   [1, "rgba(0,150,255,0)"],
    //   [0.8, "rgba(0,150,255,0.4)"],
    //   [0.5, "rgba(0,255,255,0.7)"],
    //   [0.2, "rgba(0,150,255,0.4)"],
    //   [0, "rgba(0,150,255,0)"],
    // ],
    duration: 10,
    // blending: "add",
    height: 200000,
    lineCount: 5,
    lineWidth: 2,
    lineColor: "yellow"
  });
  fetch("./assets/json/china.json")
    .then((res) => res.json())
    .then((data) => {
      fencelLayer.setData(data, "EPSG:4326");
    });
}