我有一个geoshape查询,它运行在本地ES实例上,如下所示:
带有地理位置查询的httprequest.js
spatialsearch() {
var _url = 'http://127.0.0.1:9201/_search?';
var b = {
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"metadata.o2r.spatial.geometry": {
"shape": {
"type": "polygon",
"coordinates": [
[
[-22.0, 76.0],
[-27.0, 65.0],
[-57.0, 65.0],
[-59.0, 76.0],
[-22.0, 76.0]
]
]
},
"relation": "contains"
}
}
}
}
}
};
return $http.post(_url, b);
console.log("hello");
}
目前我已将坐标硬编码到查询中,但我希望能够从用户在传单地图上绘制的geojson对象中获取坐标,并将它们插入上述函数中的坐标数组中。我能够在开发控制台中以字符串形式显示geojson对象的坐标,但我无法弄清楚如何保存它们并在上面的函数中检索它们。 这是我如何制作geojson并在控制台中显示它们的坐标。
search.controller.js
leafletData.getMap().then(function(map) {
leafletData.getLayers().then(function(baselayers) {
var drawnItems = baselayers.overlays.draw;
map.on('draw:created', function (e) {
var layer = e.layer;
drawnItems.addLayer(layer);
console.log(JSON.stringify(layer.toGeoJSON()));
});
});
});
答案 0 :(得分:0)
我将坐标存储在变量中,然后在http请求函数coordinates_selected = layer.toGeoJSON();
更新功能
function spatialsearch(coordinates_selected) {
var coords = coordinates_selected.geometry.coordinates;
console.log('c', JSON.stringify(coordinates_selected.geometry.coordinates));
var _url = 'http://localhost:9201/_search?';
var b = {
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_shape": {
"metadata.o2r.spatial.geometry": {
"shape": {
"type": "polygon",
"coordinates": coords
/* [
[-22.0, 76.0],
[-27.0, 65.0],
[-57.0, 65.0],
[-59.0, 76.0],
[-22.0, 76.0]
]*/
},
"relation": "within"
}
}
}
}
}
};