Commits

stefano cudini committed 07aef5a Draft

load popup in geojson example

Comments (0)

Files changed (2)

examples/geojson-layer.html

 	map.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));	//base layer
 
 	var featuresLayer = new L.GeoJSON(data, {
-			style: function(f) {
-				return {color: f.properties.color };
+			style: function(feature) {
+				return {color: feature.properties.color };
+			},
+			onEachFeature: function(feature, marker) {
+				marker.bindPopup('<h4 style="color:'+feature.properties.color+'">'+ feature.properties.name +'</h4>');
 			}
 		});
 
 	searchControl.on('search_locationfound', function(e) {
 		
 		e.layer.setStyle({fillColor: '#3f0', color: '#0f0'});
+		if(e.layer._popup)
+			e.layer.openPopup();
 
 	}).on('search_collapsed', function(e) {
 

examples/simple.html

 
 	var controlSearch = new L.Control.Search({layer: markersLayer, initial: false});
 
-	controlSearch.on('search_locationfound', function(e) {
-		e.layer.openPopup();
-	});
-
 	map.addControl( controlSearch );
 
 	////////////populate map with markers from sample data