mirror of
https://github.com/netzmacht/contao-leaflet-libraries.git
synced 2025-11-29 03:24:34 +01:00
Add omnivore plugin.
This commit is contained in:
28
assets/leaflet-omnivore/CHANGELOG.md
Normal file
28
assets/leaflet-omnivore/CHANGELOG.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
## 0.3.2
|
||||||
|
|
||||||
|
* Move `brfs` and `hintify` to dependencies.
|
||||||
|
|
||||||
|
## 0.3.1
|
||||||
|
|
||||||
|
* Updates [wellknown](https://github.com/mapbox/wellknown) to 0.3.0 with exponent coordinate support
|
||||||
|
* Updates [togeojson](https://github.com/mapbox/togeojson) to 0.10.1 with timestamp, ie9 feature id, gx:Track, gx:MultiTrack support
|
||||||
|
|
||||||
|
## 0.3.0
|
||||||
|
|
||||||
|
* Includes [encoded polyline](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) support.
|
||||||
|
|
||||||
|
## 0.2.0
|
||||||
|
|
||||||
|
* Only includes the necessary parts of [TopoJSON](https://github.com/mbostock/topojson): less bytes,
|
||||||
|
and **IE9** and **IE10** are now supported.
|
||||||
|
* Tests now use Sauce Labs and run on real browsers for every commit.
|
||||||
|
* Builds now use an `npm` script rather than a Makefile.
|
||||||
|
|
||||||
|
## 0.1.0
|
||||||
|
|
||||||
|
* loader functions now support a `customLayer` option for providing options to
|
||||||
|
`L.geoJson` or using a different layer type.
|
||||||
|
|
||||||
|
## 0.0.1
|
||||||
|
|
||||||
|
* `gpx.parse` and `kml.parse` support parsing from either strings or DOM objects
|
||||||
58
assets/leaflet-omnivore/LICENSE
Normal file
58
assets/leaflet-omnivore/LICENSE
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
Copyright (c) 2014, Mapbox
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* Neither the name of the {organization} nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
TopoJSON
|
||||||
|
|
||||||
|
Copyright (c) 2012, Michael Bostock
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
* The name Michael Bostock may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
|
||||||
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||||
|
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||||
|
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
186
assets/leaflet-omnivore/README.md
Normal file
186
assets/leaflet-omnivore/README.md
Normal file
@@ -0,0 +1,186 @@
|
|||||||
|
[](https://travis-ci.org/mapbox/leaflet-omnivore)
|
||||||
|
|
||||||
|
# leaflet-omnivore
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[Leaflet](http://leafletjs.com/) supports the [GeoJSON](http://geojson.org/) format
|
||||||
|
by default. What if you have something else? That's where omnivore comes in.
|
||||||
|
|
||||||
|
It currently supports:
|
||||||
|
|
||||||
|
* [CSV](http://en.wikipedia.org/wiki/Comma-separated_values) (via [csv2geojson](https://github.com/mapbox/csv2geojson))
|
||||||
|
* GPX (via [toGeoJSON](https://github.com/mapbox/togeojson))
|
||||||
|
* [KML](http://developers.google.com/kml/documentation/) (via [toGeoJSON](https://github.com/mapbox/togeojson))
|
||||||
|
* [WKT](http://en.wikipedia.org/wiki/Well-known_text) (via [wellknown](https://github.com/mapbox/wellknown))
|
||||||
|
* [TopoJSON](https://github.com/mbostock/topojson)
|
||||||
|
* [Encoded Polylines](https://developers.google.com/maps/documentation/utilities/polylinealgorithm) via [polyline](https://github.com/mapbox/polyline)
|
||||||
|
|
||||||
|
Omnivore also includes an AJAX library, [corslite](https://github.com/mapbox/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](http://mapbox.com/mapbox.js/plugins/#leaflet-omnivore):
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src='//api.tiles.mapbox.com/mapbox.js/plugins/leaflet-omnivore/v0.2.0/leaflet-omnivore.min.js'></script>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
Or download `leaflet-omnivore.min.js` from this repository.
|
||||||
|
|
||||||
|
## example
|
||||||
|
|
||||||
|
Live examples:
|
||||||
|
|
||||||
|
* [WKT](https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-wkt/)
|
||||||
|
* [TopoJSON](https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-topojson/)
|
||||||
|
* [Tooltips](https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-kml-tooltip/)
|
||||||
|
* [KML](https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-kml/)
|
||||||
|
* [GPX](https://www.mapbox.com/mapbox.js/example/v1.0.0/omnivore-gpx/)
|
||||||
|
* [Icons](https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-from-csv-custom-style/)
|
||||||
|
* [CSV](https://www.mapbox.com/mapbox.js/example/v1.0.0/markers-from-csv/)
|
||||||
|
|
||||||
|
```js
|
||||||
|
var map = L.mapbox.map('map', 'examples.map-9ijuk24y')
|
||||||
|
.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](https://github.com/mapbox/csv2geojson#api): `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](https://developers.google.com/maps/documentation/utilities/polylinealgorithm),
|
||||||
|
by default 1e5, which is adjustable.
|
||||||
|
|
||||||
|
### Custom Layers
|
||||||
|
|
||||||
|
Passing custom options:
|
||||||
|
|
||||||
|
```js
|
||||||
|
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:
|
||||||
|
|
||||||
|
```js
|
||||||
|
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`:
|
||||||
|
|
||||||
|
```js
|
||||||
|
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
|
||||||
|
|
||||||
|
```js
|
||||||
|
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](http://browserify.org/) project:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
git clone git@github.com:mapbox/leaflet-omnivore.git
|
||||||
|
|
||||||
|
cd leaflet-omnivore
|
||||||
|
|
||||||
|
# to run tests
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# to build leaflet-omnivore.js
|
||||||
|
npm run build
|
||||||
|
```
|
||||||
|
|
||||||
|
`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](https://github.com/mbostock/topojson),
|
||||||
|
[csv2geojson](https://github.com/mapbox/csv2geojson), [wellknown](https://github.com/mapbox/wellknown), or
|
||||||
|
[toGeoJSON](https://github.com/mapbox/togeojson)
|
||||||
|
individually.
|
||||||
|
* **My AJAX request is failing for a cross-domain request**. Read up on the [Same Origin Restriction](http://en.wikipedia.org/wiki/Same-origin_policy).
|
||||||
|
By default, we use corslite, so cross-domain requests will try to use [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing)
|
||||||
|
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](https://gist.github.com/tmcw/6244497).
|
||||||
5
assets/leaflet-omnivore/bower.json
Normal file
5
assets/leaflet-omnivore/bower.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"name": "leaflet-omnivore",
|
||||||
|
"version": "0.3.0",
|
||||||
|
"description": "a geospatial format parser for Leaflet"
|
||||||
|
}
|
||||||
8
assets/leaflet-omnivore/component.json
Normal file
8
assets/leaflet-omnivore/component.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "leaflet-omnivore",
|
||||||
|
"version": "0.2.0",
|
||||||
|
"description": "a geospatial format parser for Leaflet",
|
||||||
|
"scripts": [
|
||||||
|
"leaflet-omnivore.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
255
assets/leaflet-omnivore/index.js
Normal file
255
assets/leaflet-omnivore/index.js
Normal file
@@ -0,0 +1,255 @@
|
|||||||
|
var xhr = require('corslite'),
|
||||||
|
csv2geojson = require('csv2geojson'),
|
||||||
|
wellknown = require('wellknown'),
|
||||||
|
polyline = require('polyline'),
|
||||||
|
topojson = require('topojson/topojson.js'),
|
||||||
|
toGeoJSON = require('togeojson');
|
||||||
|
|
||||||
|
module.exports.polyline = polylineLoad;
|
||||||
|
module.exports.polyline.parse = polylineParse;
|
||||||
|
|
||||||
|
module.exports.geojson = geojsonLoad;
|
||||||
|
|
||||||
|
module.exports.topojson = topojsonLoad;
|
||||||
|
module.exports.topojson.parse = topojsonParse;
|
||||||
|
|
||||||
|
module.exports.csv = csvLoad;
|
||||||
|
module.exports.csv.parse = csvParse;
|
||||||
|
|
||||||
|
module.exports.gpx = gpxLoad;
|
||||||
|
module.exports.gpx.parse = gpxParse;
|
||||||
|
|
||||||
|
module.exports.kml = kmlLoad;
|
||||||
|
module.exports.kml.parse = kmlParse;
|
||||||
|
|
||||||
|
module.exports.wkt = wktLoad;
|
||||||
|
module.exports.wkt.parse = wktParse;
|
||||||
|
|
||||||
|
function addData(l, d) {
|
||||||
|
if ('addData' in l) l.addData(d);
|
||||||
|
if ('setGeoJSON' in l) l.setGeoJSON(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a [GeoJSON](http://geojson.org/) document into a layer and return the layer.
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function geojsonLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, function(err, response) {
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
addData(layer, JSON.parse(response.responseText));
|
||||||
|
layer.fire('ready');
|
||||||
|
});
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a [TopoJSON](https://github.com/mbostock/topojson) document into a layer and return the layer.
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function topojsonLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
topojsonParse(response.responseText, options, layer);
|
||||||
|
layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a CSV document into a layer and return the layer.
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function csvLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
var error;
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
function avoidReady() {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
layer.on('error', avoidReady);
|
||||||
|
csvParse(response.responseText, options, layer);
|
||||||
|
layer.off('error', avoidReady);
|
||||||
|
if (!error) layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a GPX document into a layer and return the layer.
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function gpxLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
var error;
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
function avoidReady() {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
layer.on('error', avoidReady);
|
||||||
|
gpxParse(response.responseXML || response.responseText, options, layer);
|
||||||
|
layer.off('error', avoidReady);
|
||||||
|
if (!error) layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a [KML](https://developers.google.com/kml/documentation/) document into a layer and return the layer.
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function kmlLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
var error;
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
function avoidReady() {
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
layer.on('error', avoidReady);
|
||||||
|
kmlParse(response.responseXML || response.responseText, options, layer);
|
||||||
|
layer.off('error', avoidReady);
|
||||||
|
if (!error) layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a WKT (Well Known Text) string into a layer and return the layer
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function wktLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
wktParse(response.responseText, options, layer);
|
||||||
|
layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load a polyline string into a layer and return the layer
|
||||||
|
*
|
||||||
|
* @param {string} url
|
||||||
|
* @param {object} options
|
||||||
|
* @param {object} customLayer
|
||||||
|
* @returns {object}
|
||||||
|
*/
|
||||||
|
function polylineLoad(url, options, customLayer) {
|
||||||
|
var layer = customLayer || L.geoJson();
|
||||||
|
xhr(url, onload);
|
||||||
|
function onload(err, response) {
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
polylineParse(response.responseText, options, layer);
|
||||||
|
layer.fire('ready');
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function topojsonParse(data, options, layer) {
|
||||||
|
var o = typeof data === 'string' ?
|
||||||
|
JSON.parse(data) : data;
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
for (var i in o.objects) {
|
||||||
|
var ft = topojson.feature(o, o.objects[i]);
|
||||||
|
if (ft.features) addData(layer, ft.features);
|
||||||
|
else addData(layer, ft);
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function csvParse(csv, options, layer) {
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
options = options || {};
|
||||||
|
csv2geojson.csv2geojson(csv, options, onparse);
|
||||||
|
function onparse(err, geojson) {
|
||||||
|
if (err) return layer.fire('error', { error: err });
|
||||||
|
addData(layer, geojson);
|
||||||
|
}
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function gpxParse(gpx, options, layer) {
|
||||||
|
var xml = parseXML(gpx);
|
||||||
|
if (!xml) return layer.fire('error', {
|
||||||
|
error: 'Could not parse GPX'
|
||||||
|
});
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
var geojson = toGeoJSON.gpx(xml);
|
||||||
|
addData(layer, geojson);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function kmlParse(gpx, options, layer) {
|
||||||
|
var xml = parseXML(gpx);
|
||||||
|
if (!xml) return layer.fire('error', {
|
||||||
|
error: 'Could not parse KML'
|
||||||
|
});
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
var geojson = toGeoJSON.kml(xml);
|
||||||
|
addData(layer, geojson);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function polylineParse(txt, options, layer) {
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
options = options || {};
|
||||||
|
var coords = polyline.decode(txt, options.precision);
|
||||||
|
var geojson = { type: 'LineString', coordinates: [] };
|
||||||
|
for (var i = 0; i < coords.length; i++) {
|
||||||
|
// polyline returns coords in lat, lng order, so flip for geojson
|
||||||
|
geojson.coordinates[i] = [coords[i][1], coords[i][0]];
|
||||||
|
}
|
||||||
|
addData(layer, geojson);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function wktParse(wkt, options, layer) {
|
||||||
|
layer = layer || L.geoJson();
|
||||||
|
var geojson = wellknown(wkt);
|
||||||
|
addData(layer, geojson);
|
||||||
|
return layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseXML(str) {
|
||||||
|
if (typeof str === 'string') {
|
||||||
|
return (new DOMParser()).parseFromString(str, 'text/xml');
|
||||||
|
} else {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
}
|
||||||
1865
assets/leaflet-omnivore/leaflet-omnivore.js
Normal file
1865
assets/leaflet-omnivore/leaflet-omnivore.js
Normal file
File diff suppressed because it is too large
Load Diff
1
assets/leaflet-omnivore/leaflet-omnivore.min.js
vendored
Normal file
1
assets/leaflet-omnivore/leaflet-omnivore.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
67
assets/leaflet-omnivore/package.json
Normal file
67
assets/leaflet-omnivore/package.json
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
{
|
||||||
|
"name": "leaflet-omnivore",
|
||||||
|
"version": "0.3.2",
|
||||||
|
"description": "a geospatial format parser for Leaflet",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "zuul --local -- test/test.js",
|
||||||
|
"test-remote": "zuul -- test/test.js",
|
||||||
|
"test-headless": "zuul --phantom test/test.js",
|
||||||
|
"build": "browserify -s omnivore index.js > leaflet-omnivore.js && uglifyjs leaflet-omnivore.js -c -m > leaflet-omnivore.min.js"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:mapbox/leaflet-omnivore.git"
|
||||||
|
},
|
||||||
|
"browserify": {
|
||||||
|
"transform": [
|
||||||
|
"brfs",
|
||||||
|
"hintify"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"leaflet",
|
||||||
|
"formats",
|
||||||
|
"kml",
|
||||||
|
"csv",
|
||||||
|
"gpx",
|
||||||
|
"geojson",
|
||||||
|
"kml",
|
||||||
|
"leaflet",
|
||||||
|
"maps",
|
||||||
|
"gpx",
|
||||||
|
"wkt",
|
||||||
|
"osm",
|
||||||
|
"polyline",
|
||||||
|
"topojson",
|
||||||
|
"format",
|
||||||
|
"converter"
|
||||||
|
],
|
||||||
|
"author": "Tom MacWright",
|
||||||
|
"license": "BSD",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/mapbox/leaflet-omnivore/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/mapbox/leaflet-omnivore",
|
||||||
|
"dependencies": {
|
||||||
|
"csv2geojson": "~3.6.1",
|
||||||
|
"togeojson": "0.10.1",
|
||||||
|
"corslite": "0.0.6",
|
||||||
|
"wellknown": "0.3.0",
|
||||||
|
"hintify": "~0.1.0",
|
||||||
|
"brfs": "0.2.1",
|
||||||
|
"topojson": "1.6.8",
|
||||||
|
"polyline": "0.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"browserify": "7.0.2",
|
||||||
|
"tape": "2.4.2",
|
||||||
|
"uglify-js": "2.4.16",
|
||||||
|
"jshint": "2.5.0",
|
||||||
|
"mocha": "~1.20.1",
|
||||||
|
"zuul": "~1.7.0",
|
||||||
|
"st": "0.5.1",
|
||||||
|
"mapbox.js": "1.6.4",
|
||||||
|
"phantomjs": "~1.9.7-15"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -33,6 +33,15 @@ $GLOBALS['LEAFLET_LIBRARIES']['leaflet-providers'] = array
|
|||||||
'javascript' => 'assets/leaflet/libs/leaflet-providers/leaflet-providers.js'
|
'javascript' => 'assets/leaflet/libs/leaflet-providers/leaflet-providers.js'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$GLOBALS['LEAFLET_LIBRARIES']['leaflet-omnivore'] = array
|
||||||
|
(
|
||||||
|
'name' => 'Leaflet-omnivore',
|
||||||
|
'version' => '0.3.2',
|
||||||
|
'license' => '<a href="https://github.com/mapbox/leaflet-omnivore/blob/master/LICENSE" target="_blank">BSD</a>',
|
||||||
|
'homepage' => 'https://github.com/mapbox/leaflet-omnivore',
|
||||||
|
'javascript' => 'assets/leaflet/libs/leaflet-omnivore/leaflet-omnivore.min.js'
|
||||||
|
);
|
||||||
|
|
||||||
$GLOBALS['LEAFLET_LIBRARIES']['leaflet-ajax'] = array
|
$GLOBALS['LEAFLET_LIBRARIES']['leaflet-ajax'] = array
|
||||||
(
|
(
|
||||||
'name' => 'Leaflet-ajax',
|
'name' => 'Leaflet-ajax',
|
||||||
|
|||||||
Reference in New Issue
Block a user