Skip to content

Commit

Permalink
fix 修改ugc例子 review by qiw
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxianhuii committed Apr 29, 2024
1 parent 5c47f58 commit 9b6e47e
Show file tree
Hide file tree
Showing 29 changed files with 212 additions and 220 deletions.
5 changes: 0 additions & 5 deletions examples/leaflet/ugc_computeGeodesicArea.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
<h5 class="panel-title text-center">计算经纬度面积</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算点到线段的距离</span>
</div>
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />
</div>
</div>
Expand Down
15 changes: 6 additions & 9 deletions examples/leaflet/ugc_computeGeodesicDistance.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@
<body>
<div id="toolbar" class="panel panel-primary">
<div class="panel-heading">
<h5 class="panel-title text-center">距离计算</h5>
<h5 class="panel-title text-center">计算测地线的长度</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算点到线段的距离</span>
</div>
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
</div>
</div>
Expand All @@ -47,6 +42,7 @@ <h5 class="panel-title text-center">距离计算</h5>
<script type="text/javascript" include="ugcwasm" src="../../dist/leaflet/include-leaflet.js"></script>
<script>
var map, popup, marker, line;
popup = L.popup();
var map, bufferLayer;
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
var url = host + '/iserver/services/map-world/rest/maps/World';
Expand All @@ -63,7 +59,6 @@ <h5 class="panel-title text-center">距离计算</h5>
});

function addFeatures() {
marker = L.marker([30, 123]).addTo(map);
line = {
type: 'Feature',
geometry: {
Expand All @@ -89,11 +84,13 @@ <h5 class="panel-title text-center">距离计算</h5>
var geometryAnalysis = new L.supermap.GeometryAnalysis();
var distance;
distance = geometryAnalysis.computeGeodesicDistance([120, 125], [30, 30], 6378137, 0.0033528106647475);
marker.bindPopup('距离为: ' + distance).openPopup();
popup.setLatLng([30, 123])
.setContent('距离为: ' + distance)
.openOn(map);
}

function clearPopup() {
marker && marker.closePopup();
map.closePopup();
}
</script>
</body>
Expand Down
11 changes: 1 addition & 10 deletions examples/leaflet/ugc_distanceToLineSegment.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,9 @@
<body>
<div id="toolbar" class="panel panel-primary">
<div class="panel-heading">
<h5 class="panel-title text-center">距离计算</h5>
<h5 class="panel-title text-center">计算点到线段的距离</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算点到线段的距离</span>
</div>
</div>
<div class="panel distanceTip">(两个几何对象边线间最短距离)</div>
<div class="panel distanceToLineSegmentTip" style="display: none">
(如果点到线段的垂足不在线段上,则返回点到线段较近的端点的距离)
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
<input type="button" class="btn btn-default" value="移除" onclick="clearPopup()" />
</div>
Expand Down
2 changes: 1 addition & 1 deletion examples/leaflet/ugc_isIntersectRegionWithRect.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<body>
<div id="toolbar" class="panel panel-primary">
<div class="panel-heading">
<h5 class="panel-title text-center">线光滑</h5>
<h5 class="panel-title text-center">面与矩形相交检测</h5>
</div>
<div class="panel-body content">
<input type="button" class="btn btn-default" value="执行" onclick="search()" />
Expand Down
3 changes: 3 additions & 0 deletions examples/leaflet/ugc_pointPositon.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ <h5 class="panel-title text-center">点线关系</h5>
if (pointResult) {
pointResult.removeFrom(map);
}
if (lineResult) {
lineResult.removeFrom(map);
}
// if (!map) {
// return;
// }
Expand Down
14 changes: 10 additions & 4 deletions examples/leaflet/ugc_resample.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,21 @@ <h5 class="panel-title text-center">重采样</h5>
</div>
<div class="panel-body content">
<input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
<input type="button" class="btn btn-default" value="移除" onclick="clearLayer()" />
</div>
</div>
<div id="map" style="width: 100%; height: 100%"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" include="ugcwasm" src="../../dist/leaflet/include-leaflet.js"></script>
<script>
var map, polygon;
var map, polygon, resLayer;
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
var url = host + '/iserver/services/map-world/rest/maps/World';
L.supermap
.initMap(url, {
mapOptions: {
center: [30, 120],
zoom: 6
center: [60, 40],
zoom: 4
}
})
.then((res) => {
Expand Down Expand Up @@ -105,16 +106,21 @@ <h5 class="panel-title text-center">重采样</h5>
}

function search() {
clearLayer();
var geometryAnalysis = new L.supermap.GeometryAnalysis();
var result = geometryAnalysis.resample(polygon, 0.5);
L.geoJSON(result, {
resLayer = L.geoJSON(result, {
style: function(params) {
return {
color: 'green'
}
}
}).addTo(map);
}

function clearLayer() {
resLayer && resLayer.removeFrom(map);
}
</script>
</body>
</html>
10 changes: 8 additions & 2 deletions examples/leaflet/ugc_smooth.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ <h5 class="panel-title text-center">线光滑</h5>
</div>
<div class="panel-body content">
<input type="button" class="btn btn-default" value="执行" onclick="search()" />
<input type="button" class="btn btn-default" value="移除" onclick="clearLayer()" />
</div>
</div>
<div id="map" style="width: 100%; height: 100%"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" include="ugcwasm" src="../../dist/leaflet/include-leaflet.js"></script>
<script>
var map, popup, point, line;
var map, resLayer, point, line;
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
var url = host + '/iserver/services/map-world/rest/maps/World';
L.supermap
Expand Down Expand Up @@ -95,10 +96,11 @@ <h5 class="panel-title text-center">线光滑</h5>
}

function search() {
clearLayer();
var geometryAnalysis = new L.supermap.GeometryAnalysis();
let smoothLine;
smoothLine = geometryAnalysis.smooth(line, point);
L.geoJSON(smoothLine, {
resLayer = L.geoJSON(smoothLine, {
style: function() {
return {
weight: 5,
Expand All @@ -107,6 +109,10 @@ <h5 class="panel-title text-center">线光滑</h5>
}
}).addTo(map);
}

function clearLayer() {
resLayer && resLayer.removeFrom(map);
}
</script>
</body>
</html>
10 changes: 9 additions & 1 deletion examples/leaflet/ugc_spatialRelationship.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ <h5 class="panel-title text-center">空间关系</h5>
<script type="text/javascript" include="ugcwasm" src="../../dist/leaflet/include-leaflet.js"></script>
<script>
var map, targetPolygon, searchPolygons, searchLines, searchPoints;
var resArr = [];
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
var url = host + '/iserver/services/map-world/rest/maps/World';
L.supermap
Expand Down Expand Up @@ -163,7 +164,7 @@ <h5 class="panel-title text-center">空间关系</h5>
type: 'Polygon'
}
};
searchPolygons = [targetPolygon, polygon1];
searchPolygons = [targetPolygon, polygon1, polygon2];
L.geoJSON(searchPolygons).addTo(map);
}

Expand All @@ -178,12 +179,19 @@ <h5 class="panel-title text-center">空间关系</h5>
searchResults.push(polygon);
}
});
searchResults.forEach((item) => {
res = L.geoJSON(item).addTo(map);
resArr.push(res);
});
}

function clearLayer() {
if (!map) {
return;
}
resArr.forEach(res => {
res.removeFrom(map);
})
}
</script>
</body>
Expand Down
5 changes: 0 additions & 5 deletions examples/mapboxgl/ugc_computeGeodesicArea.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
<h5 class="panel-title text-center">计算经纬度面积</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算点到线段的距离</span>
</div>
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />
</div>
</div>
Expand Down
7 changes: 1 addition & 6 deletions examples/mapboxgl/ugc_computeGeodesicDistance.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,9 @@
<body>
<div id="toolbar" class="panel panel-primary">
<div class="panel-heading">
<h5 class="panel-title text-center">距离计算</h5>
<h5 class="panel-title text-center">计算测地线的长度</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算点到线段的距离</span>
</div>
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,24 @@
<body>
<div id="toolbar" class="panel panel-primary">
<div class="panel-heading">
<h5 class="panel-title text-center">距离计算</h5>
<h5 class="panel-title text-center">根据设置距离获取直线平行线</h5>
</div>
<div class="panel-body content">
<div class="panel">
<div class="input-group">
<span class="input-group-addon">计算</span>
<select id="operation" class="form-control">
<option value="distanceToLineSegment">点到线段的距离</option>
</select>
<span class="input-group-addon">线距(米)</span>
<input class="form-control" id="distance" type="number" value="5" />
</div>
</div>
<div class="panel distanceTip">(两个几何对象边线间最短距离)</div>
<div class="panel distanceToLineSegmentTip" style="display: none">
(如果点到线段的垂足不在线段上,则返回点到线段较近的端点的距离)
</div>
<input type="button" class="btn btn-default" value="计算" onclick="search()" />&nbsp;
<input type="button" class="btn btn-default" value="移除" onclick="clearPopup()" />
<input type="button" class="btn btn-default" value="分析" onclick="search()" />&nbsp;
<input type="button" class="btn btn-default" value="移除" onclick="clearLayer()" />
</div>
</div>
<div id="map" style="width: 100%; height: 100%"></div>
<script type="text/javascript" include="bootstrap-css" src="../js/include-web.js"></script>
<script type="text/javascript" include="ugcwasm" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
<script>
var map, popup, point, line;
var map, popup, point, line, res;
var host = window.isLocal ? window.server : 'https://iserver.supermap.io';
var url = host + '/iserver/services/map-world/rest/maps/World/zxyTileImage.png?z={z}&x={x}&y={y}';
function initMap(url) {
Expand All @@ -79,7 +73,7 @@ <h5 class="panel-title text-center">距离计算</h5>
]
},
center: [120, 30],
zoom: 6
zoom: 5
});
map.on('load', function () {
resolve(map);
Expand All @@ -104,33 +98,15 @@ <h5 class="panel-title text-center">距离计算</h5>
}

function search() {
clearPopup();
const operationFun = document.getElementById('operation').value;
clearLayer();
const distance = parseFloat(document.getElementById('distance').value);
var geometryAnalysis = new mapboxgl.supermap.GeometryAnalysis();
let distance;
distance = geometryAnalysis.computeParallel(
{
type: 'Feature',
properties: {},
geometry: {
coordinates: [
[120, 30],
[125, 30]
],
type: 'LineString'
}
},
5
);
addLayer('line1', 'line', [distance], {
const res = geometryAnalysis.computeParallel(line, distance);
console.log(res)
addLayer('line1', 'line', [res], {
'line-color': 'green',
'line-width': 5
});

// popup = new mapboxgl.Popup()
// .setLngLat(point.geometry.coordinates)
// .setHTML('距离为: ' + distance)
// .addTo(map);
}

function addLayer(id, type, sourceData, paint) {
Expand All @@ -148,8 +124,11 @@ <h5 class="panel-title text-center">距离计算</h5>
});
}

function clearPopup() {
popup && popup.remove();
function clearLayer() {
if (map.getLayer("line1")) {
map.removeLayer("line1")
map.removeSource("line1")
}
}

initMap(url).then((map) => {
Expand Down
Loading

0 comments on commit 9b6e47e

Please sign in to comment.