0

我有一个在本地 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 对象中获取坐标,并将它们插入到上述函数的坐标数组中。我可以在 dev-console 中以字符串形式显示 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()));
                  });
               });

           });
4

1 回答 1

1

我将坐标存储在一个变量中,然后在 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"
            }
          }
        }
      }
    }
  };
于 2017-05-23T08:18:49.747 回答