Skip to content

Instantly share code, notes, and snippets.

@gledsoncruz
Created April 3, 2014 19:51
Show Gist options
  • Save gledsoncruz/9961615 to your computer and use it in GitHub Desktop.
Save gledsoncruz/9961615 to your computer and use it in GitHub Desktop.
Leaflet - Configurando o Mapa
L.Icon.Default.imagePath = "/assets"
var cloudmadeUrl = 'http://{s}.tile.cloudmade.com/BC9A493B41014CAABB98F0471D759707/{styleId}/256/{z}/{x}/{y}.png',
cloudmadeAttribution = 'Map data © 2011 OpenStreetMap contributors, Imagery © 2011 CloudMade';
var nightTime = L.tileLayer(cloudmadeUrl, {
styleId:999
});
var googleRoadMap = new L.Google('ROADMAP');
var googleSatellite = new L.Google('SATELLITE');
function onEducacaoFeature(feature, layer) {
if (feature.properties && feature.properties.nome) {
layer.bindPopup("<p><b>Nome:</b> "+feature.properties.nome+"</p>"+
"<p><b>Email:</b> "+feature.properties.email+"</p>");
}
}
var educacao = new L.GeoJSON(null, {onEachFeature: onEducacaoFeature});
function educacaoJson(data) {
educacao.addData(data);
}
$.ajax({
url : "http://localhost:3000/educacional.json",
success: educacaoJson
});
// create a map in the "map" div, set the view to a given place and zoom
var map = L.map('map', {drawControl: false, maxZoom: 25, minZoom: 13, layers: [googleSatellite ]}).setView([-22.511447, -44.108906], 13);
//**************** INICIANDO OS CONTROLES *********************
var editarEdu = educacao; //new L.FeatureGroup();
map.addLayer(editarEdu);
var options = {
position: 'topleft',
draw: {
polyline: false,
polygon: false,
circle: false, // Turns off this drawing tool
rectangle: false,
},
edit: {
featureGroup: editarEdu, //REQUIRED!!
remove: true
}
};
var drawControl = new L.Control.Draw(options);
map.addControl(drawControl);
map.on('draw:created', function (e) {
var type = e.layerType,
layer = e.layer;
var wkt = "POINT(" + layer.getLatLng().lng + " " + layer.getLatLng().lat + ")";
$('#myModal').css({"z-index":"9999"});
$('#map').css({"z-index":"0"});
$('#myModal').modal('show');
$('#educacao_the_geom').val('');
$('#educacao_the_geom').val(wkt);
editarEdu.addLayer(layer);
$('#myModal').on('hide.bs.modal', function (e) {
$(this).clearErrors();
$('.controls input').each(function(){
$(this).val('');
editarEdu.removeLayer(layer);
})
$('#educacao_tipo option')[0].selected = true;
});
});
map.on('draw:deleted', function (e) {
var type = e.layerType,
layer = e.layer;
if (type === 'marker') {
alert('Deletado!!');
}
editarEdu.addLayer(layer);
});
var baseMaps = {
//"Minimal": minimal,
"Google": googleRoadMap,
"Google Satélite": googleSatellite,
"Noturno": nightTime
};
var overlayMaps = {
"Educação Municipal": educacao
};
L.control.layers(baseMaps, overlayMaps).addTo(map);
L.control.scale().addTo(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment