calvinmetcalf / leaflet.shapefile

Shapefile in Leaflet
http://calvinmetcalf.github.io/leaflet.shapefile/
MIT License
256 stars 119 forks source link

Problem in integrating this plugin with shpjs #69

Closed GaganGowda89 closed 2 years ago

GaganGowda89 commented 2 years ago

I have installed the shpjs package using npm, npm -i shpjs --save

I copied lealfet.shapefile.js and made some changes as follows:

import * as shp from 'shpjs'

/* global cw, shp */
L.Shapefile = L.GeoJSON.extend({
  options: {
    importUrl: shp
  },

....
 var shapefile = function(a, b, c) {
  return new L.Shapefile(a, b, c);
 };

 module.export = shapefile;

Later I tried importing the leaflet.shapefile as shown in my page1.ts file,

const l1 = require('../../assets/leaflet.shpfile.js'); ...

 shp(reader.result).then(function (geojson) {   //More info: https://github.com/calvinmetcalf/shapefile-js
   l1.shapefile(geojson).addTo(this.map);//More info: https://github.com/calvinmetcalf/leaflet.shapefile
  });

I am not sure if I am doing it right. Can you suggest how do I insert ArrayBuffer in either shp(reader) or in L.shapefile.

calvinmetcalf commented 2 years ago

ok why did you you need to change it, what was broken?

GaganGowda89 commented 2 years ago

I am not sure how to use leaflet.shapefile in my project. I tried exporting it but was not able to find the right way. I have an ArrayBuffer which is converted from Base64 as you see in the link below

https://gis.stackexchange.com/questions/431503/loading-shapefile-data-into-l-shapefile-says-nodebuffer-is-not-supported-by-this?noredirect=1#comment704143_431503

All I need is to fit the ArrayBuffer into shp(buffer) or leaflet.shapefile(ArrayBuffer). I am not sure which to use and not sure whether i am using the right package for my problem. Hope you can suggest. Thanks :)

calvinmetcalf commented 2 years ago

https://stackoverflow.com/questions/41997027/uncaught-error-nodebuffer-is-not-supported-by-this-browser i think this might help

GaganGowda89 commented 2 years ago

Hi Calvin, that did not solve my problem. Anyway, i was just curious to ask you, how do i callL.shapefile using leaflet.shapefile.js. Am i using this right shp(buffer) or L.shapefile(buffer) doing the same? I meant

     shp(file).then(function (geojson) {    //More info: https://github.com/calvinmetcalf/shapefile-js
      L.geoJSON(geojson).addTo(this.map);//More info: https://github.com/calvinmetcalf/leaflet.shapefile

    });

or


const l1 = require('../../assets/leaflet.shpfile.js');

     shp(file).then(function (geojson) {    //More info: https://github.com/calvinmetcalf/shapefile-js
      l1.shapefile(geojson).addTo(this.map);// The call I am making here is wrong.
      //or L.shapefile(geojson)<--- How do i call this from the import that i made?
    });
calvinmetcalf commented 2 years ago

probably the first way is better in your case

GaganGowda89 commented 2 years ago

Closing the issue, as it is not related to this. :) Thanks again