if (!window.my_labels) {
window.my_labels = new Cesium.CustomDataSource('my_labels');
viewer.dataSources.add(window.my_labels);
}
let props = {
wfs_url: "http://IP:PORT/geoserver/sanwei/wfs",//geoserver wfs服务地址
wfs_layer: "sanwei:layerName"//图层
}
let cameraExtent = viewer.camera.computeViewRectangle();//视窗范围
let picks = [];
if (cameraExtent) {
let west = parseFloat(Cesium.Math.toDegrees(cameraExtent.west).toFixed(8));
let south = parseFloat(Cesium.Math.toDegrees(cameraExtent.south).toFixed(8));
let east = parseFloat(Cesium.Math.toDegrees(cameraExtent.east).toFixed(8));
let north = parseFloat(Cesium.Math.toDegrees(cameraExtent.north).toFixed(8));
picks = [
[west, south],
[east, north]
];
}
let wfsurl = props.wfs_url + "?service=WFS&version=1.1.0&request=GetFeature&typename=" +
props.wfs_layer + "&maxFeatures=200&outputFormat=application/json&srsname=EPSG:4326";
if (picks.length > 0) {
wfsurl += `&BBOX=${picks[0][0]},${picks[0][1]},${picks[1][0]},${picks[1][1]},EPSG:4326`
} else {
//如果没有获取到视窗范围就不继续执行
return
}
fetch(wfsurl).then(result => {
if (!result.ok) {
throw new Error(
`couldn't load "${result.url}". Request failed with status ${result.status} : ${result.statusText}`
);
}
result.json().then((json) => {
let { features } = json;
if (window.my_labels && features && features.length > 0) {
window.my_labels.entities.removeAll()
for (let i = 0; i < features.length; i++) {
let { geometry, properties } = features[i];
let { coordinates } = geometry;
window.my_labels.entities.add({
position: Cesium.Cartesian3.fromDegrees(coordinates[0], coordinates[1]),
label: {
text: properties.areaname || "未知地名",
showBackground: true,
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
}
});
}
}
});
}).catch(error => {
return Promise.reject(error);
}).finally(() => {
});
Cesium 加载geoserver发布的WFS点要素服务
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 首先在geoserver上发布影像图的切片,并在tile layer上选择对应的坐标系及图片格式查看图层效果(多级...
- Geoserver发布地图服务比较简单,这里不做赘述。 1、Cesium加载Geoserver发布的WMS服务 (...
- Geoserver发布的shp数据,发布后利用openlayers查看,显示数据,url如下:http://loc...
- Geoserver发布的tiff数据,发布后利用openlayers查看,显示数据,url如下:http://lo...