请问点击查询面怎么做?需要点击地图查询出地块高亮并显示气泡信息。
写的几何查询做点击查询面代码如下(可粘贴到官网沙箱运行),bug点击太快的时候前面查询出来的地块不会清除,请问正确的代码该怎么写?
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title data-i18n="resources.title_getFeatureByGeometry"></title>
<script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
var map, resultLayer = L.geoJSON(),
baseUrl = host + "/iserver/services/map-world/rest/maps/World",
url = host + "/iserver/services/data-world/rest/data";
map = L.map('map', {
preferCanvas: true,
crs: L.CRS.EPSG4326,
center: {lon: 0, lat: 0},
maxZoom: 18,
zoom: 2
});
L.supermap.tiledMapLayer(baseUrl).addTo(map);
map.on('click', function (e) {
var lat = e.latlng.lat;
var lng = e.latlng.lng;
query(lat, lng);
});
function query(lat, lng) {
map.removeLayer(resultLayer);//清空之前的图层
var marker1 = L.marker([lat, lng]);
var geometryParam = new SuperMap.GetFeaturesByGeometryParameters({
datasetNames: ["World:Countries"],
geometry: marker1,
spatialQueryMode: "INTERSECT"
});
L.supermap
.featureService(url)
.getFeaturesByGeometry(geometryParam, function (serviceResult) {
resultLayer = L.geoJSON(serviceResult.result.features, {
onEachFeature: function (feature, layer) {
layer.bindPopup(resources.text_country + ":" + feature.properties.COUNTRY);//可避免二次点击该点时闪烁
L.popup()
.setLatLng([lat, lng])
.setContent(resources.text_country + ":" + feature.properties.COUNTRY)
.openOn(map);
console.log(feature);
}
}).addTo(map);
});
}
</script>
</body>
</html>