ngageoint / geopackage-js

GeoPackage JavaScript Library
http://ngageoint.github.io/geopackage-js/
MIT License
304 stars 78 forks source link

geoPackageFeatureLayer is not a function #166

Closed robbiegleeson closed 3 years ago

robbiegleeson commented 3 years ago

Package Version

"@ngageoint/leaflet-geopackage": "^3.0.3"

React Version

"react": "^16.13.1",

Error Details

TypeError: leaflet__WEBPACK_IMPORTED_MODULE_1___default.a.geoPackageFeatureLayer is not a function

Details

I am looking to use leaflet-geopackage within my React.js project. When trying to load a .gpkg file once the titleLayer is loaded I get the above error.

Code

import L from 'leaflet';

useEffect(() => {
    var map = L.map('map').setView([lat, lng], 6);
    setMap(map)

    const titleLayer = L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpejY4NXVycTA2emYycXBndHRqcmZ3N3gifQ.rJcFIG214AriISLbB6B5aw', {
      maxZoom: 18,
      attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, ' +
        '<a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, ' +
        'Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
      id: 'mapbox/light-v9',
      tileSize: 512,
      zoomOffset: -1,
    }).addTo(map);

      titleLayer.on('load', () => {
        L.geoPackageFeatureLayer([], {
        geoPackageUrl: 'path-to-my-local-file/data.gpkg',
        layerName: 'rivers'
      }).addTo(map);
    })
  ....
})

I've installed the package but I can't seem to figure out why it's throwing this error

BLECUONA commented 3 years ago

I am facing the same issue. Have you found a solution @robbiegleeson ?

Thank you.

danielbarela commented 3 years ago

How did you import the leaflet-geopackage library? Do you have a complete example I can look at?

BLECUONA commented 3 years ago

Thanks for your reply.

I am trying to use it in a react js project. After npm install @ngageoint/leaflet-geopackage I tried many ways to import leaflet-geopackage library without success :

Am I doing something wrong?

NB : I use Node 12 to avoid #172

danielbarela commented 3 years ago

If you can provide an example project, I can take a look and determine what is wrong.

BLECUONA commented 3 years ago

Here is an example project with my issue.

Thank you for your help.

danielbarela commented 3 years ago

It appears you need to allocate more space to your build so I modified your package.json scripts to this

...
  "scripts": {
    "start": "react-scripts --max_old_space_size=4096 start",
    "build": "react-scripts --max_old_space_size=4096 build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
...

I updated your Geopackage.js file to this

import React, { useEffect } from 'react';
import { useMap } from 'react-leaflet';

/* Both of these import throw "FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory" */
require('@ngageoint/leaflet-geopackage/dist/leaflet-geopackage.min.js');
// require('@ngageoint/leaflet-geopackage');

export function Geopackage() {
    const map = useMap();

    useEffect(() => {
        const geopackageTileLayer = window.L.geoPackageTileLayer({
            geoPackageUrl: 'http://ngageoint.github.io/GeoPackage/examples/rivers.gpkg',
            layerName: 'rivers_tiles',
        });
        geopackageTileLayer.addTo(map);

        geopackageTileLayer.on('load', () => {
            window.L.geoPackageFeatureLayer([], {
            geoPackageUrl: 'http://ngageoint.github.io/GeoPackage/examples/rivers.gpkg',
            layerName: 'rivers'
        }).addTo(map);
    });
    }, []);

    return null;
};

Once that was done, it all loaded just fine for me.

BLECUONA commented 3 years ago

--max_old_space_size=4096 is insufficient for me. I needed to increase it to 8192 and that perfectly loaded, thanks!