Giter Club home page Giter Club logo

Comments (14)

tmcw avatar tmcw commented on June 2, 2024 1

The solution is what I posted before: use

<script src='https://unpkg.com/@tmcw/[email protected]/dist/togeojson.umd.js'></script>

from togeojson.

tmcw avatar tmcw commented on June 2, 2024

It looks like, in this context, you're in a clone of this repository (togeojson/index.js), and trying to get browserify to create a standalone bundle of togeojson?

Assuming that's the case, first off: you can get a standalone bundle, if you're in a git checkout, by running:

$ npm install
$ npm run prepare

There are also prebuilt standalone bundles on unpkg: https://unpkg.com/browse/@tmcw/[email protected]/dist/ (you'd want the .umd ones, most likely).

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I have tried you suggestion, but still get error as:

    `Uncaught (in promise) ReferenceError: kml is not defined
at convert_kml_to_geojson (helper.js:313)`

html, script tag is:

<script src='https://unpkg.com/browse/@tmcw/[email protected]/dist/togeojson.umd.js'>

js call this function
`

          function convert_kml_to_geojson(kml_string){

            var kml_dom = new DOMParser().parseFromString(kml_string, "text/xml");
            console.log( 'kml_dom ', kml_dom );
        
        
        
           console.log( kml );
           console.log( kml(kml_dom) );
           
        
        
        
           }`

from togeojson.

tmcw avatar tmcw commented on June 2, 2024

You'll need to refer to the kml function of toGeoJSON as toGeoJSON.kml, instead of just kml.

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

This time I get
Uncaught (in promise) ReferenceError: toGeoJSON is not defined at convert_kml_to_geojson (helper.js:313)

          ` function convert_kml_to_geojson(kml_string){

            var kml_dom = new DOMParser().parseFromString(kml_string, "text/xml");
            console.log( 'kml_dom ', kml_dom );
        
        
        
           console.log( 'kml reference ->' ,toGeoJSON.kml );
           console.log( 'kml -> geojson -> ', toGeoJSON.kml(kml_dom) );
           
        
        
        
           }`

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I have tried, both script tag, with/without type='module'
same error
toGeoJSON is not defined

       `<script type='module' src='https://unpkg.com/browse/@tmcw/[email protected]/dist/togeojson.umd.js'> `

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I found the reason:
my browser console complain when load "togeojson.umd.js"

                 `Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.`

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I use opera, seem like failed to load module at the first place, because of strict......

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I tried with firefox, get more info
Loading module from “https://unpkg.com/browse/@tmcw/[email protected]/dist/togeojson.umd.js” was blocked because of a disallowed MIME type (“text/html”).

learn more at:

https://developer.mozilla.org/docs/Web/HTTP/Headers/X-Content-Type-Options?utm_source=mozilla&utm_medium=firefox-console-errors&utm_campaign=default

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

I tried with google chrome, get this, is ES6 module problem,many people get this.

  `Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.`

from togeojson.

tmcw avatar tmcw commented on June 2, 2024

The URL should be https://unpkg.com/@tmcw/[email protected]/dist/togeojson.umd.js

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

Ok, I found a fix !!!!!!!
Simply saying:

                  You need to save  togeojson.umd.js file on to your node http server! or Python http server!!!
                      if you use the online "unpkg.com" version, your browser will block load module due to unpkg.com server incorrectly respond MIME type!!!
                      if you put that file on apache2.4 server, likely failed for same reason(not test yet)

Why? because only node http server and python http server can correctly respond MIME type
see this top accepted answer:
https://stackoverflow.com/questions/46138375/trouble-with-es6-modules#

                           The problem is NOT caused by toGeoJSON module iteself, it caused by how you get this module from( unpkg.com, apache will failed, node and python http server will success) 

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

Now I save togeojson.umd.js to my node.js server, no more error.
works like a charming!!! after 4 hours painful countless try and failure.

I will continue to try save it on apache2.4 server, see what happen.

On other side, do you have any idea to work around it?

from togeojson.

hoogw avatar hoogw commented on June 2, 2024

yes, this one works:
https://unpkg.com/@tmcw/[email protected]/dist/togeojson.umd.js
but this one DO NOT work:
https://unpkg.com/browse/@tmcw/[email protected]/dist/togeojson.umd.js

I believe the local dist, by npm install is the same as first one (works) above.
So, for safe, just run a local npm install, get it from dist folder.

from togeojson.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.