🚀 تخفیف ۳۵٪ + ۳.۵ میلیون هدیه! برنامه‌نویسی رو الان شروع کن - فقط امروز!
۰ ثانیه
۰ دقیقه
۰ ساعت
۲ مهران
مشکل با marker دوم
جامعه پی اچ پی ایجاد شده در ۱۹ مرداد ۱۴۰۲

سلام من بعد از اینکه marker دوم را اضافه میکنم popup مارکر دوم کار نمیکنه همچنین مارکر دوم با map حرکت میکنه که یعنی مختصات درستی را نشون نمیده این error ‌ها را هم گرفتم توی browser

Uncaught TypeError: Cannot read properties of null (reading 'lat')
    at Object.project (Projection.SphericalMercator.js:24:43)
    at Object.latLngToPoint (CRS.js:28:40)
    at e.project (Map.js:982:27)
    at e.latLngToLayerPoint (Map.js:1004:29)
    at e.update (Marker.js:204:24)
    at e.onAdd (Marker.js:123:8)
    at e._layerAdd (Layer.js:114:8)
    at e.whenReady (Map.js:1477:13)
    at e.addLayer (Layer.js:172:8)
    at e.addTo (Layer.js:52:7)
/memap/assets/images/favicon.png:1       
Failed to load resource: the server responded with a status of 404 (Not Found)
4Projection.SphericalMercator.js:24  Uncaught TypeError: Cannot read properties of null (reading 'lat')
    at Object.project (Projection.SphericalMercator.js:24:43)
    at Object.latLngToPoint (CRS.js:28:40)
    at e.project (Map.js:982:27)
    at e.panInside (Map.js:527:25)
    at e._panOnFocus (Marker.js:397:7)
    at HTMLImageElement.o (DomEvent.js:108:13)
8Projection.SphericalMercator.js:24  Uncaught TypeError: Cannot read properties of null (reading 'lat')
    at Object.project (Projection.SphericalMercator.js:24:43)
    at Object.latLngToPoint (CRS.js:28:40)
    at e.project (Map.js:982:27)
    at e._latLngToNewLayerPoint (Map.js:1510:15)
    at e._animateZoom (Marker.js:330:23)
    at e.fire (Events.js:195:9)
    at e._animateZoom (Map.js:1701:8)
    at e. (Map.js:1679:9)

وقتی مارکر دوم را حذف میکنم همه چی درست میشه

const defaultLocation = [32.558664, 51.575801];
const defaultZoom = 14;
var map = L.map("map").setView(defaultLocation, defaultZoom);
var tiles = L.tileLayer("https://tile.openstreetmap.org/{z}/{x}/{y}.png", {
  maxZoom: 19,
  attribution:
    'Memap Project Mehran Saedi',
  id: "mapbox/streets-v11",
}).addTo(map);
// Set the height of map dynamically
document
  .getElementById("map")
  .style.setProperty("height", window.innerHeight + "px");
// move to places in map  ...
// setTimeout(function () {
//   map.setView([32.6419508, 51.6657103], defaultZoom);
// }, 5000);
// show and pin markers
var marker1 = L.marker(defaultLocation)
  .addTo(map)
  .bindPopup("Mehran Saedi")
  .openPopup();
var marker2 = L.marker(32.55, 51.5758)
  .addTo(map)
  .bindPopup("Mehran")
  .openPopup();
  var northLine = map.getBounds().getNorth();
  var southLine = map.getBounds().getSouth();
  var eastLine = map.getBounds().getEast();
  var westLine = map.getBounds().getWest();
  map.setView([northLine, eastLine], defaultZoom);

مشکل حل شد.

مهران ۱۹ مرداد ۱۴۰۲، ۱۶:۲۵

موفق باشید.

محسن موحد ۱۹ مرداد ۱۴۰۲، ۲۲:۰۴