Soy muy nuevo en esto de los SIG.
Tengo que integrar la opción de exportación a KML en uno de mis proyectos.
No pude ver esta opción al buscar en Google.
¿Existe la opción de hacer esto?
<!DOCTYPE html>
<html>
<head>
<title>Leaflet.draw vector editing handlers</title>
<script src="libs/leaflet-src.js"></script>
<link rel="stylesheet" href="libs/leaflet.css" />
<script src="../src/Leaflet.draw.js"></script>
<link rel="stylesheet" href="../dist/leaflet.draw.css" />
<link rel="stylesheet" href="../src/NavBar/Leaflet.NavBar.css" />
<script src="../src/Toolbar.js"></script>
<script src="../src/Tooltip.js"></script>
<script src="../src/ext/GeometryUtil.js"></script>
<script src="../src/ext/LatLngUtil.js"></script>
<script src="../src/ext/LineUtil.Intersect.js"></script>
<script src="../src/ext/Polygon.Intersect.js"></script>
<script src="../src/ext/Polyline.Intersect.js"></script>
<script src="../src/draw/DrawToolbar.js"></script>
<script src="../src/draw/handler/Draw.Feature.js"></script>
<script src="../src/draw/handler/Draw.SimpleShape.js"></script>
<script src="../src/draw/handler/Draw.Polyline.js"></script>
<script src="../src/draw/handler/Draw.Circle.js"></script>
<script src="../src/draw/handler/Draw.Marker.js"></script>
<script src="../src/draw/handler/Draw.Polygon.js"></script>
<script src="../src/draw/handler/Draw.Rectangle.js"></script>
<script src="../src/edit/EditToolbar.js"></script>
<script src="../src/edit/handler/EditToolbar.Edit.js"></script>
<script src="../src/edit/handler/EditToolbar.Delete.js"></script>
<script src="../src/Control.Draw.js"></script>
<script src="../src/NavBar/Leaflet.NavBar.js"></script>
<script src="../src/edit/handler/Edit.Poly.js"></script>
<script src="../src/edit/handler/Edit.SimpleShape.js"></script>
<script src="../src/edit/handler/Edit.Circle.js"></script>
<script src="../src/edit/handler/Edit.Rectangle.js"></script>
<script src="../src/edit/handler/Edit.Marker.js"></script>
</head>
<body>
<div id="map" style="width: 900px; height: 500px; border: 1px solid #ccc"></div>
<button type="button" onclick="plotAccidents();">plot accidents</button><br/>
<button type="button" onclick="clearAccidents();">clear accidents</button><br/>
<button type="button" onclick="addWMS();">Add WMS</button><br/>
<button type="button" onclick="panTo();">Pan To Address</button><br/>
WKT String : <span id="wktstring"></span>
<script>
var bounds;
var plotbounds;
var count=0;
var checked =1;
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '© <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib});
map = new L.Map('map', {layers: [osm], center: new L.LatLng(47.58, 29.22), zoom: 13}),
drawnItems = L.featureGroup().addTo(map);
var markers = new L.FeatureGroup();
map.addControl(new L.Control.Draw({
edit: { featureGroup: drawnItems }
}));
map.on('draw:created', function(event) {
var layer = event.layer;
drawnItems.addLayer(layer);
});
L.control.navbar().addTo(map);
function plotAccidents()
{
populate();
map.addLayer(markers);
}
function clearAccidents()
{
map.removeLayer(markers);
}
function getRandomLatLng(map) {
//if(bounds==null)
bounds = map.getBounds();
if(count==0)
{
console.log(bounds);
}
//if(count==0)
//{
//console.log("southWest");
//console.log(bounds.getSouthWest());
//}
southWest = bounds.getSouthWest();
northEast = bounds.getNorthEast();
lngSpan = northEast.lng - southWest.lng;
latSpan = northEast.lat - southWest.lat;
count++;
return new L.LatLng(
southWest.lat + latSpan * Math.random(),
southWest.lng + lngSpan * Math.random());
}
function populate() {
for (var i = 0; i < 10; i++) {
var point = getRandomLatLng(map);
if(plotbounds!=null && !plotbounds.contains(point))
continue;
var marker = L.marker(point);
marker.bindPopup("<p>Accident details goes here</p>", {
showOnMouseOver: true
});
markers.addLayer(marker);
}
return false;
}
function toWKT(layer) {
var lng, lat, coords = [];
if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
var latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++) {
latlngs[i]
coords.push(latlngs[i].lng + " " + latlngs[i].lat);
if (i === 0) {
lng = latlngs[i].lng;
lat = latlngs[i].lat;
}
};
if (layer instanceof L.Polygon) {
return "POLYGON((" + coords.join(",") + "," + lng + " " + lat + "))";
} else if (layer instanceof L.Polyline) {
return "LINESTRING(" + coords.join(",") + ")";
}
} else if (layer instanceof L.Marker) {
return "POINT(" + layer.getLatLng().lng + " " + layer.getLatLng().lat + ")";
}
}
var drawnItems = new L.LayerGroup();
map.on('draw:created', function (e) {
var type = e.layerType;
plotbounds = e.layer.getBounds();
console.log(plotbounds);
var layer = e.layer;
drawnItems.addLayer(layer);
document.getElementById('wktstring').innerHTML=(toWKT(layer));
});
map.addLayer(drawnItems);
function addWMS()
{
L.tileLayer.wms("http://sedac.ciesin.columbia.edu/geoserver/wms", {
layers: 'gpw-v3:gpw-v3-population-density_2000',
format: 'image/png',
version: '1.1.0',
transparent: true,
attribution: "",
tiled:true
}).addTo(map);
}
function panTo()
{
map.panTo(new L.LatLng(40.737, -73.923));
}
</script>
</body>
</html>
0 votos
He actualizado la respuesta