首页 > 解决方案 > 使用 Spring Boot 显示带有 openlayers 地图的图层

问题描述

我想在openlayers地图上显示一个图层(MultiPolygons),但我不知道如何使用spring boot来做到这一点,如果有人可以帮助我,我将非常感激。

PS:我正在使用 postrges

我读了一点关于休眠空间的信息,但我仍然不知道我该怎么做。

这就是我声明我的层的方式:

package com.example.demo;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;


@Entity
@Table(name="polygon")
public class Couche {
    // pour indiquer la clé primaire 
    @Id
    @Column(name = "gid" )
    //L' @GeneratedValueannotation consiste à configurer le mode d'incrémentation de la colonne
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long  gid  ; 

    @Column(columnDefinition = "geometry(MultiPolygon,4326)")
    private String geom ;


    //geters seters pour gid 
    public Long getGid() {
        return  gid;
    }
    public void setGid(Long  gid) {
        this. gid =  gid;
    }

    //geters seters pour Geom
    public String getGeom() {
        return geom;
    }
    public void setGeom(String geom) {
        this.geom = geom;
    }

} 

这是我的包含地图的 HTML 页面:

<!doctype html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/css/ol.css" type="text/css">
    <style>
      .map {
        height: 400px;
        width: 100%;
      }
    </style>
    <script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.5.0/build/ol.js"></script>
    <title>OpenLayers example</title>
  </head>
  <body>
    <h2>My Map</h2>

    <div id="map" class="map"></div>
    <script type="text/javascript">

    //////////////////////////////////////////// zoomslider
    var zoomslider = new ol.control.ZoomSlider();
    
    // la carte 
      var map = new ol.Map({
        target: 'map',
        layers: [
          new ol.layer.Tile({
            source: new ol.source.OSM()
          })
        ],
        view: new ol.View({
          center: ol.proj.fromLonLat([37.41, 8.82]),
          zoom: 4
        }),
        controls: ol.control.defaults().extend
      ([new ol.control.FullScreen(),

          zoomslider
         
      ]),

      });


    </script>

  </body>
</html>

标签: javahtmlspring-bootopenlayers

解决方案


推荐阅读