7 changed files with 69 additions and 12 deletions
@ -0,0 +1,46 @@ |
|||||||
|
package com.biutag.supervision.controller.datav; |
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject; |
||||||
|
import com.biutag.supervision.pojo.entity.CountyStreetDept; |
||||||
|
import com.biutag.supervision.service.CountyStreetDeptService; |
||||||
|
import com.google.gson.Gson; |
||||||
|
import jakarta.annotation.Resource; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.springframework.boot.test.context.SpringBootTest; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.List; |
||||||
|
import java.util.Map; |
||||||
|
|
||||||
|
@SpringBootTest |
||||||
|
public class SubOneControllerTest { |
||||||
|
|
||||||
|
@Resource |
||||||
|
private CountyStreetDeptService countyStreetDeptService; |
||||||
|
@Test |
||||||
|
public void testSubstr() { |
||||||
|
List<CountyStreetDept> depts = countyStreetDeptService.getTest(4062); |
||||||
|
Map<String, Object> geoJson = new HashMap<>(); |
||||||
|
geoJson.put("type", "FeatureCollection"); |
||||||
|
geoJson.put("name", "4062"); |
||||||
|
|
||||||
|
List<Map<String, Object>> features = new ArrayList<>(); |
||||||
|
for (CountyStreetDept dept : depts) { |
||||||
|
Map<String, Object> feature = new HashMap<>(); |
||||||
|
feature.put("type", "Feature"); // 第一个键值
|
||||||
|
|
||||||
|
Map<String, Object> properties = new HashMap<>(); |
||||||
|
properties.put("name", dept.getName()); |
||||||
|
properties.put("id", dept.getId()); |
||||||
|
feature.put("properties", properties); // 第二个键值
|
||||||
|
|
||||||
|
feature.put("geometry", new Gson().fromJson(dept.getGeometry(), Object.class)); // 第三个键值
|
||||||
|
features.add(feature); |
||||||
|
} |
||||||
|
geoJson.put("features", features); |
||||||
|
JSONObject jsonObject = new JSONObject(); |
||||||
|
jsonObject.put("geoJson", geoJson); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue