Giter Club home page Giter Club logo

leaflet-omnivore's Introduction

leaflet-omnivore

Leaflet supports the GeoJSON format by default. What if you have something else? That's where omnivore comes in.

It currently supports:

Omnivore also includes an AJAX library, corslite, so you can specify what you want to add to the map with just a URL.

Installation

use it easily with the Mapbox Plugins CDN:

<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.3.1/leaflet-omnivore.min.js'></script>

Or download leaflet-omnivore.min.js from this repository.

example

Live examples:

var map = L.mapbox.map('map', 'mapbox.streets')
    .setView([38, -102.0], 5);

omnivore.csv('a.csv').addTo(map);
omnivore.gpx('a.gpx').addTo(map);
omnivore.kml('a.kml').addTo(map);
omnivore.wkt('a.wkt').addTo(map);
omnivore.topojson('a.topojson').addTo(map);
omnivore.geojson('a.geojson').addTo(map);
omnivore.polyline('a.txt').addTo(map);

API

Arguments with ? are optional. parser_options consists of options sent to the parser library, not to the layer: if you want to provide options to the layer, see the example in the Custom Layers section.

By default, the library will construct a L.geoJson() layer internally and call .addData(geojson) on it in order to load it full of GeoJSON. If you want to use a different kind of layer, like a L.mapbox.featureLayer(), you can, by passing it as customLayer, as long as it supports events and addData(). You can also use this API to pass custom options to a L.geoJson() instance.:

  • .csv(url, parser_options?, customLayer?): Load & parse CSV, and return layer. Options are the same as csv2geojson: latfield, lonfield, delimiter
  • .csv.parse(csvString, parser_options?): Parse CSV, and return layer.
  • .kml(url): Load & parse KML, and return layer.
  • .kml.parse(kmlString | gpxDom): Parse KML from a string of XML or XML DOM, and return layer.
  • .gpx(url, parser_options?, customLayer?): Load & parse GPX, and return layer.
  • .gpx.parse(gpxString | gpxDom): Parse GPX from a string of XML or XML DOM, and return layer.
  • .geojson(url, parser_options?, customLayer?): Load GeoJSON file at URL, parse GeoJSON, and return layer.
  • .wkt(url, parser_options?, customLayer?): Load & parse WKT, and return layer.
  • .wkt.parse(wktString): Parse WKT, and return layer.
  • .topojson(url, parser_options?, customLayer?): Load & parse TopoJSON, and return layer.
  • .topojson.parse(topojson): Parse TopoJSON (given as a string or object), and return layer.
  • .polyline(url, parser_options?, customLayer?): Load & parse polyline, and return layer.
  • .polyline.parse(txt, options, layer): Parse polyline (given as a string or object), and return layer.

Valid options:

polyline

  • precision will change how the polyline is interpreted. By default, the value is 5. This is the factor in the algorithm, by default 1e5, which is adjustable.

Custom Layers

Passing custom options:

var customLayer = L.geoJson(null, {
    filter: function() {
        // my custom filter function
        return true;
    }
});

var myLayer = omnivore.csv('foo', null, customLayer);

Adding custom styles to a GeoJSON layer:

var customLayer = L.geoJson(null, {
    // http://leafletjs.com/reference.html#geojson-style
    style: function(feature) {
        return { color: '#f00' };
    }
});
// this can be any kind of omnivore layer
var runLayer = omnivore.kml('line.kml', null, customLayer)

Using a L.mapbox.featureLayer:

var layer = omnivore.gpx('a.gpx', null, L.mapbox.featureLayer());

Async & Events

Each function returns an L.geoJson object. Functions that load from URLs are asynchronous, so they will not immediately expose accurate .setGeoJSON() functions.

For this reason, we fire events:

  • ready: fired when all data is loaded into the layer
  • error: fired if data can't be loaded or parsed
var layer = omnivore.gpx('a.gpx')
    .on('ready', function() {
        // when this is fired, the layer
        // is done being initialized
    })
    .on('error', function() {
        // fired if the layer can't be loaded over AJAX
        // or can't be parsed
    })
    .addTo(map);

ready does not fire if you don't use an asynchronous form of the function like .topojson.parse(): because you don't need an event. Just run your code after the call.

Development

This is a browserify project:

git clone [email protected]:mapbox/leaflet-omnivore.git

cd leaflet-omnivore

# to run tests
npm install

# to build leaflet-omnivore.js
npm run prepublish

leaflet-omnivore.js and leaflet-omnivore.min.js are built files generated from index.js by browserify. If you find an issue, it either needs to be fixed in index.js, or in one of the libraries leaflet-omnivore uses to parse formats.

FAQ

  • What if I just want one format? Lucky for you, each format is specified in a different module, so you can just use TopoJSON, csv2geojson, wellknown, or toGeoJSON individually.
  • My AJAX request is failing for a cross-domain request. Read up on the Same Origin Restriction. By default, we use corslite, so cross-domain requests will try to use CORS if your server and browser supports it, but if one of them doesn't, there's no way on the internet to support your request.
  • Why isn't JSONP supported? Here's why.

leaflet-omnivore's People

Contributors

baconsoap avatar cappelaere avatar chipkoziara avatar fuzhenn avatar jerrygallagher avatar jseppi avatar kennynaoh avatar lyzidiamond avatar mick avatar nostalgiaz avatar rhewitt22 avatar sabas avatar snkashis avatar stephanebachelier avatar tmcw avatar tomneyland avatar tristen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leaflet-omnivore's Issues

Leaflet or Mapbox

Is this designed for leaflet.js or for mapbox.js? The latter is a plugin for the former, and currently the examples and tests refer to it.

If this script can be used with leaflet.js alone, it would be nice to have some tests or examples showing how. If not, that's worth noting explicitly.

LOL #mathproblemz, Unexpected Token Illegal

Chrome keeps throwing an "Unexpected token Illegal" error onload. It's apparently due to this bit:

function (_dereq_, module, exports) {
                varπ = Math.PI,
                    π_4 = π/4,radians=π/180;

Any way around this?

mapbox + ionic issue

my controller code here
var add_omnivore = omnivore.csv('/lib/airports3.csv').addTo(map);
It works fine in my web browser ( ionic serve)
but It is not working on my IOS simulator

Error Message here
publicFacility_prj[21547:1281476] error JSON.stringify()ing argument: TypeError: JSON.stringify cannot serialize cyclic structures.

Parse a.gpx as string

If I try to read a.gpx as a string I get the following error:

TypeError: x.getElementsByTagName is not a function Line 542

Reading it as a file however, works just fine.

Bad characters in javascript

I'm not sure why this isn't already reported, but when I try to use omnivore, Javascript complains that illegal characters are being used.

When I open the source code, I also see the illegal characters. The one it is complaining about is:
var Ï~@ = Math.PI, (on line 1542 of non-minimized version)

I'm guessing that maybe a non-ascii character was used. But it doesn't seem to be the green symbol pi (π), which is odd, but is legal. I've downloaded it several times, and run it without even opening it, so I don't think any conversion is the problem.

Any idea what is happening?

Pass options to generated GeoJson

Thanks for sharing the great omnivore plugin. One thing i really miss is that you do not provide a way to pass options to the generated geojson object.

I know you provide the ready event but for some cases it does not work. For instance I want to generate a CircleMarker for a given point. Usually the GeoJSON layer turns the point into a marker, with the pointToLayer callback I can change this.

So it would be really helpful if you allow to pass the pointToLayer, style, onEachFeature, filter and coordsToLatLng to the geojson layer.

I know by creating a custom layer before and pass it, also works...

Any reasons not to add this feature?

topojson styling reopen

Tom,
I would like to reopen the issue as it could be fixed in the existing code base by passing the options to the L.geoJson constructor.

Thanks,
Pat.

style geojson layer(polygon)

This isn't really an issue but could you supply an example of styling a geojson layer(polygon) before or after converting from topojson. topojson and leaflet-omnivore make it possible to render a large layer but I can't figure out where to put the {style: style} function. I 'm not using the mapbox api, just leaflet. Also how would one implement the leafet onEachFeature. Any help would be greatly appreciated.

thanks in advance,

Mike S.

TopoJSON LICENSE?

Hey, it looks like you’re embedding my TopoJSON implementation in your library.

Which is great (yay!), except you haven’t followed the terms of the TopoJSON LICENSE. Specifically, you need to include the TopoJSON LICENSE file somewhere in your source distribution, such as lib/topojson/LICENSE.

Thanks!

Lag on csv load from http?

Does anyone else experience lag while loading a csv from a link? The file seems to download fine(~4MB), no disruption to app function while dl'ing, but once the markers are being processed the app freezes up until loaded or ready state. Is there an event I can use to run the Jquery progress bar widget?

convert to gpx?

this beautiful lib! Can convert geojson/json to gpx format?

do you know another lib for this one?

Impossible to use omnivore

Hi have,
I have cloned your officiale test, but it's impossible to run it and I have two errors:

  • Uncaught SyntaxError: Unexpected token ILLEGAL
  • Uncaught ReferenceError: omnivore is not defined

This is my test page: http://goo.gl/G1D2Ho

Is it my fault?

Thank you,

Andrea

MultiPolygon not being added to map

I am not 100% sure if this is omnivore not being able to add the polygon, or if this is mapbox getBounds() that is failing to execute on the multipolygon object.

Basically, I create a layer then feed MULTIPOLYGON WKT to omnivore through omnivore.wkt.parse, I then pass that layer to "map.fitBounds(runLayer.getBounds());

At which point I get:
Error: Invalid LatLng object: (NaN, NaN)
https://api.tiles.mapbox.com/mapbox.js/v1.6.3/mapbox.js
Line 1

The MultiPolygon object I am passing is:
"MULTIPOLYGON (((-117.189582 32.725158, -117.189545 32.725187, -117.190133 32.725274, -117.189582 32.725158)), ((-117.190375 32.724537999999995, -117.190272 32.724779999999996, -117.190652 32.724907, -117.192605 32.724801, -117.190446 32.724548, -117.190375 32.724537999999995)), ((-117.182688 32.726089, -117.182454 32.7261, -117.180834 32.725528, -117.180219 32.725446, -117.179951 32.726959, -117.182389 32.72753, -117.184926 32.728311, -117.184477 32.728047, -117.184503 32.727964, -117.184991 32.727007, -117.184894 32.726886, -117.182688 32.726089)), ((-117.16132999999999 32.703193999999996, -117.160751 32.703821, -117.16032200000001 32.70354, -117.161226 32.702622, -117.161148 32.702567, -117.16107 32.702622, -117.160354 32.703364, -117.159834 32.703023, -117.15974299999999 32.703116, -117.159554 32.7031, -117.159385 32.702643, -117.160335 32.702363, -117.160303 32.702281, -117.159255 32.702583, -117.158878 32.702346, -117.158885 32.702290999999995, -117.160426 32.701841, -117.160374 32.701736, -117.158644 32.702258, -117.159041 32.702583, -117.15893 32.702681999999996, -117.158384 32.702352, -117.158312 32.702225, -117.157857 32.701912, -117.15787 32.701813, -117.158052 32.701741, -117.161096 32.700862, -117.161214 32.700784999999996, -117.161149 32.700686, -117.154893 32.696351, -117.154633 32.696296, -117.15194 32.697092999999995, -117.151765 32.696686, -117.15129 32.696349999999995, -117.151167 32.696141, -117.15064 32.695861, -117.152104 32.694431, -117.151955 32.694342999999996, -117.150549 32.695811, -117.150228 32.695595, -117.14981900000001 32.696025, -117.14926 32.696598, -117.149188 32.696912, -117.148863 32.696959, -117.148501 32.697139, -117.147395 32.698282, -117.149058 32.699436, -117.150769 32.700536, -117.149177 32.702161, -117.152729 32.704654999999995, -117.152838 32.70494, -117.15279100000001 32.705225, -117.151501 32.705227, -117.150342 32.705223, -117.14757 32.705235, -117.14773 32.706272999999996, -117.147733 32.709424999999996, -117.147763 32.710456, -117.147735 32.71166, -117.148026 32.713682999999996, -117.14819 32.714452, -117.148042 32.714557, -117.1479 32.715767, -117.148085 32.716043, -117.148076 32.716172, -117.14787799999999 32.716809999999995, -117.148082 32.717863, -117.14756 32.717864999999996, -117.147606 32.718378, -117.147776 32.719398999999996, -117.148336 32.721102, -117.148978 32.722215, -117.14944299999999 32.722828, -117.15010000000001 32.723478, -117.150669 32.723855, -117.151251 32.724104, -117.150528 32.725572, -117.149565 32.725076, -117.149067 32.723852, -117.14865 32.723456, -117.148239 32.723386999999995, -117.14838499999999 32.723017999999996, -117.148282 32.722805, -117.148086 32.72265, -117.147688 32.722558, -117.147287 32.722667, -117.146965 32.723008, -117.146748 32.723518, -117.14672999999999 32.722978, -117.146993 32.722468, -117.147075 32.722069, -117.146588 32.722452, -117.14648700000001 32.722767999999995, -117.14649 32.723213, -117.146196 32.723165, -117.146389 32.722358, -117.145506 32.722336999999996, -117.14479 32.722628, -117.144722 32.722894, -117.14487199999999 32.723532999999996, -117.14474200000001 32.723841, -117.144945 32.723667999999996, -117.14548500000001 32.724258999999996, -117.14556 32.72465, -117.14495099999999 32.724694, -117.144483 32.724948, -117.144223 32.725221, -117.143791 32.726326, -117.143584 32.726552999999996, -117.143177 32.726714, -117.142667 32.726709, -117.142067 32.726849, -117.14302599999999 32.730345, -117.143661 32.730547, -117.144012 32.730865, -117.14534 32.733354, -117.145419 32.733661999999995, -117.14540000000001 32.735077, -117.145475 32.735177, -117.145771 32.735212, -117.14572 32.736289, -117.14592 32.737499, -117.146355 32.738519, -117.147396 32.7402, -117.147499 32.740573999999995, -117.14752899999999 32.741169, -117.151181 32.741129, -117.1513 32.740507, -117.151546 32.740072999999995, -117.153902 32.738217999999996, -117.15478999999999 32.737296, -117.155784 32.736788, -117.155958 32.736706999999996, -117.155959 32.734852, -117.155852 32.734234, -117.15564 32.733596, -117.154921 32.732301, -117.154652 32.731418, -117.158027 32.731401, -117.158079 32.730559, -117.158253 32.729684, -117.15824 32.729296999999995, -117.15939399999999 32.729302, -117.159398 32.730354999999996, -117.15939900000001 32.731394, -117.163028 32.731373, -117.164849 32.731365, -117.16486 32.732423, -117.16575399999999 32.732394, -117.166687 32.732386999999996, -117.167516 32.732378, -117.167516 32.732315, -117.168173 32.732316, -117.169871 32.731808, -117.169468 32.73083, -117.17044 32.730526, -117.171365 32.731584999999995, -117.178548 32.73964, -117.179976 32.741143, -117.181014 32.741842, -117.182322 32.742536, -117.18323 32.741974, -117.183504 32.741687999999996, -117.18423899999999 32.740536, -117.184275 32.740480999999996, -117.185058 32.739543999999995, -117.185795 32.739115, -117.186657 32.73897, -117.187513 32.739205999999996, -117.188244 32.738963999999996, -117.188761 32.738758, -117.190761 32.738309, -117.191665 32.734950999999995, -117.196293 32.736069, -117.196992 32.736533, -117.201536 32.737637, -117.201993 32.73761, -117.202435 32.737840999999996, -117.202223 32.739286, -117.205482 32.739613, -117.206273 32.739321, -117.20698 32.740401, -117.20730499999999 32.740702999999996, -117.207918 32.741062, -117.208218 32.741431999999996, -117.20815999999999 32.741665, -117.207792 32.741813, -117.207649 32.742048, -117.207846 32.742821, -117.208963 32.742537, -117.209555 32.742539, -117.208891 32.740978, -117.208539 32.740935, -117.207843 32.740423, -117.207524 32.740319, -117.207537 32.740148, -117.207296 32.739972, -117.206639 32.738625, -117.20682099999999 32.738580999999996, -117.206814 32.738312, -117.206704 32.73829, -117.206769 32.737685, -117.206983 32.737173, -117.207437 32.736668, -117.208843 32.735765, -117.209129 32.734899, -117.20870099999999 32.734341, -117.209025 32.734367999999996, -117.209358 32.732034999999996, -117.208999 32.732, -117.208583 32.731958999999996, -117.208876 32.72983, -117.20894200000001 32.729461, -117.209362 32.729376, -117.20918 32.728982, -117.20528 32.729346, -117.205214 32.728637, -117.204613 32.729229, -117.202092 32.728626, -117.1996 32.72905, -117.199507 32.728502, -117.199083 32.728277, -117.198751 32.727975, -117.198549 32.727568, -117.198536 32.727095, -117.198647 32.726605, -117.198881 32.726186999999996, -117.19910899999999 32.725989999999996, -117.199577 32.725933999999995, -117.201542 32.726028, -117.205588 32.725901, -117.210831 32.725314, -117.213364 32.724905, -117.211845 32.724361, -117.20880199999999 32.724771, -117.207939 32.725155, -117.205801 32.725356, -117.20493 32.72512, -117.197937 32.725218, -117.197663 32.724999, -117.195945 32.724865, -117.195724 32.725093, -117.19630599999999 32.725252, -117.196511 32.725486, -117.196597 32.726611999999996, -117.196522 32.727133, -117.196313 32.728439, -117.19610399999999 32.728617, -117.195584 32.72869, -117.195307 32.728816, -117.195166 32.729006999999996, -117.195141 32.729383, -117.192991 32.729272, -117.18551 32.728849, -117.184271 32.728575, -117.181621 32.727700999999996, -117.180183 32.727515, -117.178597 32.727655999999996, -117.177395 32.727669999999996, -117.178366 32.727363, -117.177575 32.727365, -117.176722 32.727243, -117.175714 32.72688, -117.174563 32.72605, -117.17388 32.725207999999995, -117.173639 32.724641999999996, -117.173457 32.723735, -117.173475 32.719912, -117.17347699999999 32.719704, -117.17376999999999 32.719704, -117.173835 32.719605, -117.17381499999999 32.719159999999995, -117.173464 32.719132, -117.173458 32.717988, -117.176665 32.717945, -117.176659 32.716789999999996, -117.173452 32.716761999999996, -117.173452 32.716393, -117.173608 32.716394, -117.173608 32.716245, -117.173907 32.716234, -117.173907 32.716152, -117.173452 32.716135, -117.173445 32.715899, -117.176665 32.715921, -117.176665 32.715453, -117.173445 32.715453, -117.173445 32.715154999999996, -117.173445 32.714815, -117.176646 32.714838, -117.176639 32.714024, -117.173823 32.713989999999995, -117.173836 32.71393, -117.173608 32.713924, -117.173445 32.713847, -117.173446 32.713721, -117.173608 32.713721, -117.173576 32.712648, -117.174259 32.71283, -117.174577 32.713198999999996, -117.17554 32.712907, -117.175618 32.713100000000004, -117.175696 32.713100000000004, -117.17563799999999 32.71288, -117.17585199999999 32.712803, -117.175566 32.711686, -117.17585199999999 32.711538, -117.17572200000001 32.711192, -117.175644 32.711224, -117.17446100000001 32.709883, -117.174363 32.709993, -117.175527 32.711273999999996, -117.175105 32.711461, -117.175118 32.711554, -117.174948 32.711653, -117.173738 32.712253, -117.17351099999999 32.712225, -117.173361 32.712374, -117.173192 32.711978, -117.174077 32.711703, -117.174018 32.711571, -117.173127 32.711818, -117.172932 32.711362, -117.173329 32.711219, -117.173251 32.711020999999995, -117.172769 32.711003999999996, -117.172067 32.709452999999996, -117.172067 32.709184, -117.171319 32.708469, -117.17063 32.708463, -117.170609 32.708027, -117.169179 32.708441, -117.167293 32.708408, -117.163677 32.705943999999995, -117.165154 32.704498, -117.166168 32.705174, -117.166546 32.704965, -117.166728 32.704586, -117.166741 32.704344, -117.163782 32.702463, -117.162468 32.703876, -117.16322199999999 32.704364999999996, -117.162904 32.704646, -117.16319 32.70486, -117.163326 32.704738999999996, -117.163404 32.704794, -117.16278 32.705338999999995, -117.162403 32.705069, -117.162494 32.704997999999996, -117.160881 32.703908, -117.16146 32.703271, -117.16132999999999 32.703193999999996), (-117.172803 32.711469, -117.173129 32.712233999999995, -117.173104 32.715708, -117.171098 32.715711999999996, -117.171082 32.713587, -117.17105699999999 32.711482, -117.172803 32.711469)))"

IE9 Support

Hi,
On CHANGELOG omnivore seems to support IE9. But if you try to open any of the Mapbox Omnivore samples (like https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-kml/) on IE9, page will hang an browser will say that "mapbox.com is not responding".

Trying on home, i got the message "No such interface supported" on JS console. Char 29 on this line:
https://github.com/mapbox/leaflet-omnivore/blob/v0.3.0/leaflet-omnivore.js#L786

I'm testing on the IE 9/Win 7 virtualbox image from modern.IE
Hope that you can fix it, there is a lot of people still using IE9...

Thanks.

An hello word to use bind bindPopup

Hi,
each function returns an L.geoJson object, but I'm not able to use onEachFeature to have a popup for each marker of my maps.

I have tested the below code, but it does not work.

How to have a popup for an omnivore marker?

Thank you

function onEachFeature(feature, layer) {
        if (feature.properties && feature.properties.mypop) {
            layer.bindPopup(feature.properties.mypop);
        }
    }
    var points = omnivore.geojson('poi.geojson')
    .on('ready', function() {
        map.fitBounds(points.getBounds());
        map.addLayer(points );
        onEachFeature: onEachFeature
    });

It doesn't display the markers

Hi, my problem is awkard, since it's a copy&paste from one of the examples.

I downloaded the library, I have it in the main level: the same one where the leaflet.js and index.html is.
The curious thing is that worked at the begining and I didn't change anything in the code.
After it started to fail I changed the .kml file from one folder to another without any luck. The same with the leafletomnivare.js

Here is the code.

// in a loadX.js
function loadGasStations()
{
var runLayer = omnivore.kml('Mapas/infladores.kml').on('ready', function() {
        mapa.fitBounds(runLayer.getBounds());
    })
.addTo(mapa);
}
index.html

<script>leaflet, jquery etc </script>
<script>js/loadX.js</script>

---call loadGasStation

Thanks in advance.

Dependencies broken

Omnivore cannot be used with npm + browserify.

After installing with npm install --save leaflet-omnivore and including with var omnivore = require("leaflet-omnivore"); I get the following error while compiling with browerify

cannot find module 'brfs' from '/path/to/my/project/node_modules/leaflet-omnivore'
cannot find module 'hintify' from '/path/to/my/project/node_modules/leaflet-omnivore'

I suspect it might be because of a mixup of dependencies and dev-dependencies in your package.json

bower.js

Can you add leaflet-omnivore to the bower repo?
Thank you!

Google-served CSV loading but not rendering

Not sure what the deuce here. I've got a valid csv being fed from a published google spreadsheet to omnivore in mapbox.js - ajax loads it just fine, on inspection all the data is there. However none of the points load into the map as geojson, and I can't figure out where in the process the pipe is breaking.

Possible to use omnivore to populate popup info?

Is it possible to use omnivore to parse other data in a CSV file other than just lat and long? For instance, if I want to populate popups with info from the csv or even customize the marker based on csv data, is this possible with omnivore? If so, is there any documentation or code samples on how that can be accomplished?

topojson styling?

topojsonload does not seem to read styling options that could be passed for each feature.
How could this be achieved?
Thanks.
Pat.

Possible to use setFilter on polyline draw/animation?

Hey everyone, wondering if I can follow the mapbox radius search filter example here:
https://www.mapbox.com/mapbox.js/example/v1.0.0/marker-radius-search/

And use setFilter on a polyline animation, so as the add(); function goes it reveals markers on the map from the csv layer. I am trying this right now but get a distanceTo undefined error in this configuration and then adding the setFilter after add(); results in no change... apologies if this is wrong place for setFilter question, I assume it is common/part of Omnivore.

Many thanks,
mapbox/JS newb

var RADIUS = 3218;
var firstPath = L.polyline([], line_options).on('add', function(e) {
    csvLayer.setFilter(function showStations(feature) {
        return e.target._latlngs.distanceTo(L.latLng(
        feature.geometry.coordinates[1],
        feature.geometry.coordinates[0])) < RADIUS;
        });
}).addTo(map);
var p = 0;
add();
function add() {
firstPath.addLatLng(
    L.latLng(startString[p][0],startString[p][1]));
    if (++p < startString.length) window.setTimeout(add, 100);
}    

parsed comparison logic issue

Lines 477 and 478 of leaflet-omnivore.js are currently:
if (parsed[i][lonfield] !== undefined &&
parsed[i][lonfield] !== undefined)

it looks like one of them should probably be a latfield

Multipolygons from topojson don't have feature object

I'm using a topojson derived from a geojson (and properties preserved with -p flag), and it behaves correctly with polygons .
I'm attaching events with this chain

.on('mouseover',mouseover_prov).on('mouseout',mouseout_prov).on('click',onMapClick_prov)

and each function has an e argument, but console.log shows e.layer.feature.properties only on Polygon type geometries.
This gives an error when trying to populate a popup with properties.something..

The console.log trace is

s.Mixin.Events.fireEvent mapbox.js:1
s.FeatureGroup.s.LayerGroup.extend._propagateEvent mapbox.js:3
s.Mixin.Events.fireEvent mapbox.js:1
s.FeatureGroup.s.LayerGroup.extend._propagateEvent mapbox.js:3
s.Mixin.Events.fireEvent mapbox.js:1
s.Path.s.Path.extend._fireMouseEvent mapbox.js:3
t.(anonymous function).o

Different behaviour in minified code

When I parse a KML file, there appears to be different behaviour with the minified version of leaflet omnivore. The minified code doesn't attach the Placemark ID to the resulting geoJSON layer, but it works correctly in the non-minified code.

Given a variable kml containing a kml file string, the following code demonstrates the different behaviour. It returns undefined with minified code, but correctly returns the ID otherwise.

var kmlLayer = omnivore.kml.parse(kml);
var firstLayer = kmlLayer.getLayers()[0];
console.log(firstLayer.feature.id);

Global .jshintrc was causing project not to build

When trying to run npm run build, I was receiving a long list of errors like below and the build would fail. Turns out it was due to a global .jshintrc I had floating around which I guess was getting picked up by hintify? I removed the global file and build worked as expected.

[1] Brizo: ~/workspace/leaflet-omnivore
$ npm run build                                                                           [±:master:∂]

> [email protected] build /Users/flasher/workspace/leaflet-omnivore
> browserify -s omnivore index.js > leaflet-omnivore.js && uglifyjs leaflet-omnivore.js -c -m > leaflet-omnivore.min.js

/Users/flasher/workspace/leaflet-omnivore/index.js: line 29, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 34, col 84, Line is too long.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 41, col 21, 'geojsonLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 42, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 52, col 102, Line is too long.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 59, col 22, 'topojsonLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 60, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 62, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 78, col 17, 'csvLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 79, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 81, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 103, col 17, 'gpxLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 104, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 106, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 121, col 109, Line is too long.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 128, col 17, 'kmlLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 129, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 131, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 153, col 17, 'wktLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 154, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 156, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 172, col 22, 'polylineLoad' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 173, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 175, col 20, 'onload' is already defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 183, col 23, 'topojsonParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 184, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 195, col 18, 'csvParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 196, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 199, col 21, 'onparse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 206, col 18, 'gpxParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 207, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 218, col 18, 'kmlParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 219, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 229, col 23, 'polylineParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 230, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 242, col 18, 'wktParse' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 243, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 249, col 18, 'parseXML' was used before it was defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 250, col 5, Missing "use strict" statement.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 42, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 60, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 79, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 104, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 129, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 154, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 173, col 32, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 186, col 22, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 196, col 22, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 211, col 22, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 223, col 22, 'L' is not defined.
/Users/flasher/workspace/leaflet-omnivore/index.js: line 223, col 22, Too many errors. (87% scanned).

Style imported paths.

I'm trying to import multiple kml files and style them. That is my code as now:

  var comuni = new Array();
  for (var i = nearby.comuni.length - 1; i >= 0; i--) {
    var c = nearby.comuni[i].colore;
    comune = omnivore.kml(nearby.comuni[i].kml);
    comune.setStyle({color: c});
    comuni.push(comune);
  };
  var comuniLayer = L.layerGroup(comuni);

All variables are instanced correctly, the kmls are converted and successfully added to the map, but the fill and stroke colors are always the default blue. The "c" var contains an hex color code. What am I missing?

Other formats?

There must be other formats but can't really think of them right now. Avoiding shp as usual, and any esri bs.

incomplete function

second parameter (options) in the following function is not being used. I wonder why?
Line number is 242 in file leaflet-omnivore.js

function wktParse(wkt, options, layer) {
    layer = layer || L.geoJson();
    var geojson = wellknown(wkt);
    addData(layer, geojson);
    return layer;
}

How to grab KML styles defined in Style node

Hi and thanks for the great library!

I am trying to use it to display KML but it seems to ignore the styles defined in the KML, if they are part of a separated KML Style definition. All I get from the feature.properties obejct is a styleHash and a styleUrl, which value is something like "-606ed2a7" and "#downArrowIcon" respectively. I believe the styleHash value is no use for me as it is only a hash value used when parsing.

But once I have the "styleUrl" value, is there a way to grab the Style node or even better the different styles (inner and outer colors, icon urls, ...)?

Should that be done in the parser or should that be done in my own code?

A sample KML with different styles can be found here:
https://developers.google.com/kml/documentation/KML_Samples.kml‎

Thanks for your help!

Timestamps not supported?

I use leaflet and leaflet-omnivore to present a GPX track on a map along with photos taken along the track. Now I'm working on an animation along the track in-between the photos. To decide where along the track a photo is taken I planned to use the timestamps both in the photos and the track but I realised when importing the GPX the resulting GeoJSON does not include all the timestamps, just the first timestamp of the whole track.

My GPX file results in a LineString and when looking into the code(here) it only reads the first timestamp. Though there are other Leaflet plugins like Leaflet-Playback which instead uses an array of timestamps(see here).

When reading up on GeoJSON it seems not to define how timestamps are expected to be treated. Is there any reason why leaflet-omnivore does not create an array of timestamps but rather just take the first?

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.