1

我正在尝试在 GeoJson 对象的点的左/右添加一个标记。我正在尝试获取我的坐标并从中减去 0.00001,但是当我尝试运行它时它会出错。我想如果它本质上是一个 JSON obj,我将能够将它拉出来并对其进行数学运算并将其保存为另一个变量。有任何想法吗?

代码:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css" />
    <script src="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.js"></script>
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>

    <style>
      #my-map {
        width: 1700px;
        height: 900px;
      }
    </style>
  </head>

  <body>
    <div id="my-map"></div>
    <script>
      window.onload = function () {
        var basemap = L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
          maxZoom: 19,
          minZoom: 5,
        });

        $.getJSON("geocode-output.geojson", function (data) {
          var geojson = L.geoJson(data, {
            onEachFeature: function (feature, layer) {
              layer.bindPopup(
                feature.properties.address +
                  "<p><b> Location Address: " +
                  feature.properties.address +
                  "</b></p>" +
                  "<p><b> Crit Flow: " +
                  feature.properties.crit_flow +
                  "</b></p>" +
                  "<p><b> Peak Hr: " +
                  feature.properties.peak_hr +
                  "</b></p>" +
                  "<p><b> Lat_test: " +
                  feature.geometry.coordinates[0] +
                  "</b></p>"
              );
            },
          });

          var googleSat = L.tileLayer("http://{s}.google.com/vt/lyrs=s&x={x}&y={y}&z={z}", {
            maxZoom: 20,
            subdomains: ["mt0", "mt1", "mt2", "mt3"],
          });

          var map = L.map("my-map").fitBounds(geojson.getBounds());
          //    .setView([0.0,-10.0], 2);

          let lat_test = feature.geometry.coordinates[0] - 0.00001;
          let lng_test = feature.geometry.coordinates[1];
          var marker = L.marker([37.7858, -122.401], { title: "My marker" }).addTo(map);

          basemap.addTo(map);
          googleSat.addTo(map);

          geojson.addTo(map);
        });
      };
    </script>
  </body>
</html>

没有算术的代码输出: 不带算术的代码输出

4

0 回答 0