PluginProbe
Leaflet Map / 2.17.2
Leaflet Map v2.17.2
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / scripts / leaflet-ajax-geojson.js

leaflet-ajax-geojson.js in Leaflet Map 2.17.2, at scripts/leaflet-ajax-geojson.js

76 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ;(function () {
2 window.WPLeafletMapPlugin = window.WPLeafletMapPlugin || []
3 window.WPLeafletMapPlugin.unshift(initAjaxGeoJSON)
4
5 function initAjaxGeoJSON() {
6 L.AjaxGeoJSON = L.GeoJSON.extend({
7 options: {
8 type: 'json', // 'json|kml|gpx'
9 },
10
11 initialize: function (url, options) {
12 L.setOptions(this, options)
13 this._url = url
14 this.layer = L.geoJson(null, this.options)
15 },
16
17 onAdd: function (map) {
18 var _this = this
19 var type = this.options.type
20 var xhr
21
22 this.map = map
23
24 map.addLayer(this.layer)
25
26 if (!this.request) {
27 this.request = xhr = new XMLHttpRequest()
28
29 xhr.onreadystatechange = function () {
30 var data
31 if (xhr.readyState === xhr.DONE && xhr.status === 200) {
32 if (type === 'json') {
33 data = JSON.parse(xhr.responseText)
34 } else if (['kml', 'gpx'].indexOf(type) !== -1) {
35 data = window.toGeoJSON[type](xhr.responseXML)
36 }
37 _this.json = data
38 _this.layer.addData(data)
39 _this.fire('ready')
40 }
41 }
42
43 xhr.open('get', this._url, true)
44
45 xhr.send()
46 }
47 this.fire('add')
48 },
49
50 eachLayer: function (fnc) {
51 this.layer.eachLayer(fnc)
52 },
53
54 setStyle: function (style) {
55 this.layer.setStyle(style)
56 },
57
58 resetStyle: function (layer) {
59 this.layer.resetStyle(layer)
60 },
61
62 onRemove: function (map) {
63 this.map.removeLayer(this.layer)
64 },
65
66 getBounds: function () {
67 return this.layer.getBounds()
68 },
69 })
70
71 L.ajaxGeoJson = function (url, options) {
72 return new L.AjaxGeoJSON(url, options)
73 }
74 }
75 })()
76