Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught TypeError: Cannot read properties of undefined (reading 'lat') #267

Open
iamtekson opened this issue Sep 21, 2021 · 4 comments
Open

Comments

@iamtekson
Copy link

I have tried to implement the onClick event using this plugin as below,

const vectorGrid = L.vectorGrid
  .slicer(street, {
    rendererFactory: L.svg.tile,
    maxNativeZoom: 19,
    maxZoom: 20,
    interactive: true,
    getFeatureId: function (f) {
      return f.properties.name;
    },
  })
  .on("click", function (e) {
    console.log(e);
  })
  .addTo(map);

When I clicked the layer, it shows the following error,

Uncaught TypeError: Cannot read properties of undefined (reading 'lat')
    at Object.project (Projection.SphericalMercator.js:24)
    at Object.latLngToPoint (CRS.js:28)
    at i.project (Map.js:993)
    at i.latLngToLayerPoint (Map.js:1015)
    at i.latLngToContainerPoint (Map.js:1072)
    at i._fireDOMEvent (Map.js:1434)
    at i._handleDOMEvent (Map.js:1397)
    at HTMLDivElement.c (DomEvent.js:92)

In this error log, I didn't find the error linked to my vector grid file. Please help me how can I solve this issue?

@iamtekson
Copy link
Author

Note: I have tried this plugin on leaflet versions 1.0.0 and 1.2.0 which are working fine. But with the latest leaflet version, the plugin is out of date.

@b108
Copy link

b108 commented Feb 15, 2022

Add layer style (via option "vectorTileLayerStyles") with

{radius: 15}

.
Radius must be > 10.

This should help.

alexandru-m-g added a commit to OCHA-DAP/hdx-ckan that referenced this issue May 13, 2022
- workaround for problem with point features and radiuses smaller than 11
Leaflet/Leaflet.VectorGrid#267
Leaflet/Leaflet.VectorGrid#148
@dpakprajul
Copy link

Mine is working.
I have used:

  1. <script src="https://unpkg.com/leaflet@1.9.2/dist/leaflet.js" integrity="sha256-o9N1jGDZrf5tS+Ft4gbIK7mYMipq9lqpVJ91xHSyKhg=" crossorigin=""></script>
  2. <script type="text/javascript" src="https://unpkg.com/leaflet.vectorgrid@1.2.0"></script>

2022-11-11

@geekypradip
Copy link

I have tried to implement the onClick event using this plugin as below,

const vectorGrid = L.vectorGrid
  .slicer(street, {
    rendererFactory: L.svg.tile,
    maxNativeZoom: 19,
    maxZoom: 20,
    interactive: true,
    getFeatureId: function (f) {
      return f.properties.name;
    },
  })
  .on("click", function (e) {
    console.log(e);
  })
  .addTo(map);

When I clicked the layer, it shows the following error,

Uncaught TypeError: Cannot read properties of undefined (reading 'lat')
    at Object.project (Projection.SphericalMercator.js:24)
    at Object.latLngToPoint (CRS.js:28)
    at i.project (Map.js:993)
    at i.latLngToLayerPoint (Map.js:1015)
    at i.latLngToContainerPoint (Map.js:1072)
    at i._fireDOMEvent (Map.js:1434)
    at i._handleDOMEvent (Map.js:1397)
    at HTMLDivElement.c (DomEvent.js:92)

In this error log, I didn't find the error linked to my vector grid file. Please help me how can I solve this issue?

function patchVectorGridLayer(obj) {
 // Fix error for point data.
// eg. mouseover does not work without this.
 obj._createLayer_orig = obj._createLayer;
 obj._createLayer = function (feat, pxPerExtent, layerStyle) {
  let layer = this._createLayer_orig(feat, pxPerExtent, layerStyle);
  if (feat.type === 1) {
    layer.getLatLng = null;
  }
  return layer;
};
// do this for chaining
 return obj;
}

just wrap the vectorgrid with patchVectorGridLayer function like :
example :

const vectorGrid =patchVectorGridLayer( L.vectorGrid
  .slicer(street, {
    rendererFactory: L.svg.tile,
    maxNativeZoom: 19,
    maxZoom: 20,
    interactive: true,
    getFeatureId: function (f) {
      return f.properties.name;
    },
  }))
  .on("click", function (e) {
    console.log(e);
  })
  .addTo(map);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants