I am working on a map mixing OpenLayers and leaflet libraries (it is possible, correct ?). I am such a beginner that, after lots of readings, I thought creating pop ups was less difficult for me with leaflet than OpenLayers.
After hours spent to display pop ups, I can't find the right manner. I get a
TypeError:a.div is undefined
HTML :
<html>
<head>
<title>OpenLayers Example</title>
<script src="http://openlayers.org/api/OpenLayers.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="./leaflet-0.7.3/leaflet.js"></script>
<script src="./highlight.pack.js"></script>
<link rel="stylesheet" href="./leaflet-0.7.3/leaflet.css" />
</head>
<body>
<center><div style="width:80%; height:98%" id="map"></div><center>
<script defer="defer" type="text/javascript">
var map = new OpenLayers.Map({
div: "map",
projection: "EPSG:3857",
});
var osm = new OpenLayers.Layer.OSM();
map.addLayer(osm);
map.setCenter(new OpenLayers.LonLat(131046.64, 5990608.29), 9);
<!--map.zoomTo(9)-->
//style pour les operations
var defaultStyle = new OpenLayers.Style({
'display': "none", //pas d'affichage de la couche
'pointRadius': 4,
'strokeColor': "red",
'strokeWidth': 0.5
});
var selectStyle = new OpenLayers.Style({
'pointRadius': 10
});
var operationStyle = new OpenLayers.StyleMap({'default': defaultStyle,
'select': selectStyle});
//layer communes d'apres geojson
var commune = new OpenLayers.Layer.Vector(
"commune", {
strategies: [new OpenLayers.Strategy.Fixed()],
protocol: new OpenLayers.Protocol.HTTP({
url: "communes.geojson",
format: new OpenLayers.Format.GeoJSON()
}),
//autre maniere de creer un style
styleMap: new OpenLayers.StyleMap({
'fillOpacity': 0,
'strokeColor': "red",
'strokeWidth': 0.8,
'label': "${nom_comm}",
'fontFamily': "Verdana",
'fontWeight': "bold",
'fontSize': "7px",
'labelOutlineColor': "white",
'labelOutlineWidth': 1
})
}
);
map.addLayer(commune);
$.getJSON("emprise.geojson", function(data) {
var geojsonLayer = L.geoJson(data, {
onEachFeature: function (feature, layer) {
layer.bindPopup(feature.properties.gid);
}
});
geojsonLayer.addTo(map);
});
</script>
</body>
</html>