简体   繁体   English

Leaflet 不显示 EPSG:3857 坐标

[英]Leaflet not show EPSG:3857 coordinates

I am totally stuck with my WGS 84 / EPSG:3857 coordinates and display them on Leaflet.我完全坚持我的 WGS 84 / EPSG:3857 坐标并将它们显示在 Leaflet 上。

I have Geojson with coordinates.我有带坐标的 Geojson。

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      "6690861",
      "682187"
    ]
  },
  "properties": {
    "id": "908",
    "message": "105",
    "date": "",
    "place": "",
    "shape": ""
  }
}

Now i want it display on Leaflet.现在我希望它显示在 Leaflet 上。 But nothing show up.但什么也没有出现。 I search already 5 hours and find something about Proj4.我已经搜索了 5 个小时并找到了有关 Proj4 的信息。 Also no errors showing up.也没有出现错误。

My script code:我的脚本代码:

 var map = L.map('map').setView([52.2129919, 5.2793703], 8); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data &copy; <a href="https://openstreetmap.org">OpenStreetMap</a>'}).addTo(map); // GeoJSON layer (UTM15) proj4.defs('EPSG:3857'); async function addGeoJson() { const response = await fetch("geojs.php"); const data = await response.json(); L.geoJson(data).addTo(map); var layerGroup = L.geoJSON(data, { onEachFeature: function (feature, layer) { layer.bindPopup('<h1>'+feature.properties.message+'</h1><p>Datum: '+feature.properties.date+'</p>'); } }).addTo(map); } addGeoJson();

It's for my the first time i work with this coordinates.这是我第一次使用这个坐标。 With lat/long coordinates was don't have problems.经纬度坐标没有问题。 And just started with javascript.刚刚开始使用 javascript。

Kind regards,亲切的问候,

I might be a bit late, but following the documentation of Proj4 , I would say that you need to add the crs to your geojson, like so:我可能有点晚了,但是按照 Proj4 的文档,我会说您需要将 crs 添加到您的 geojson 中,如下所示:

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [
      "6690861",
      "682187"
    ]
  },
  "properties": {
    "id": "908",
    "message": "105",
    "date": "",
    "place": "",
    "shape": ""
  },
  "crs": {
    "type": "name",
    "properties": {
      "name": "urn:ogc:def:crs:EPSG::3857"
    }
  }
}

Also, I think it's L.Proj.geoJson(data).addTo(map);另外,我认为它是L.Proj.geoJson(data).addTo(map); instead of L.geoJson(data).addTo(map);而不是L.geoJson(data).addTo(map);

I tried L.geoJson on my code and it didn't show anything contrary to L.Proj.geoJson so it might be your problem here.我在我的代码上尝试了 L.geoJson 并没有显示任何与 L.Proj.geoJson 相反的内容,所以这可能是你的问题。

Bro, You have stored the coordinates as a string, you have to store it as an integer.兄弟,您已将坐标存储为字符串,您必须将其存储为整数。 Put the plus(+) symbol their so it will automatically convert to the integer.把加号(+)符号放在它们上面,这样它就会自动转换为整数。 I have faced this type of problem once while showing data with the open layers.在显示具有开放层的数据时,我曾经遇到过此类问题。 Let's try!我们试试看!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM