AngularJs 将 Leaflet Geojson 对象集成到 Elasticsearch Geoshape 查询中

Integrating Leaflet Geojson Objects into Elasticsearch Geoshape Query in AngularJs

我在本地 ES 实例上有一个 运行 geoshape 查询,如下所示:

httprequest.js 使用 geoshape 查询

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()));
                  });
               });

           });

我将坐标存储在一个变量中,然后在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"
            }
          }
        }
      }
    }
  };