-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating Leaflet layers.
- Loading branch information
Tom Nightingale
committed
Oct 10, 2012
1 parent
4b93029
commit b351b58
Showing
1 changed file
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
Wkt.Wkt.prototype.isRectangle = false; | ||
|
||
Wkt.Wkt.prototype.construct = { | ||
point: function (config, component) { | ||
var coord = component || this.components; | ||
if (coord instanceof Array) { | ||
coord = coord[0]; | ||
} | ||
|
||
return L.marker(this.coordsToLatLng(coord), config); | ||
}, | ||
|
||
multipoint: function (config) { | ||
var layers = [], | ||
coords = this.components, | ||
latlng; | ||
|
||
for (var i = 0, len = coords.length; i < len; i++) { | ||
layers.push(this.construct.point.call(this, config, coords[i])); | ||
} | ||
|
||
return L.featureGroup(layers, config); | ||
}, | ||
|
||
linestring: function (config, component) { | ||
var coords = component || this.components, | ||
latlngs = this.coordsToLatLngs(coords); | ||
|
||
return L.polyLine(latlngs); | ||
}, | ||
|
||
multilinestring: function (config) { | ||
var coords = this.components, | ||
latlngs = this.coordsToLatLngs(coords, 1); | ||
|
||
return L.multiPolyline(latlngs); | ||
}, | ||
|
||
polygon: function (config) { | ||
var coords = this.components, | ||
latlngs = this.coordsToLatLngs(coords, 1); | ||
return L.polygon(latlngs); | ||
}, | ||
|
||
multipolygon: function (config) { | ||
var coords = this.components, | ||
latlngs = this.coordsToLatLngs(coords, 2); | ||
|
||
return L.multiPolygon(latlngs); | ||
} | ||
}; | ||
|
||
L.Util.extend(Wkt.Wkt.prototype, { | ||
coordsToLatLngs: L.GeoJSON.coordsToLatLngs, | ||
coordsToLatLng: function (coords, reverse) { | ||
var lat = reverse ? coords.x : coords.y, | ||
lng = reverse ? coords.y : coords.x; | ||
|
||
return L.latLng(lat, lng, true); | ||
} | ||
}); |