Fist of all, I am fairly new to javascript so I am still trying to learn, please bear with me. I am trying to create a map using leaflet that brings in a JSONP layer using WFS from geoserver on my localhost. I have successfully added the layer to the map and can use oneachfeature function to get feature properties upon clicking.
Now I what to create a highchart basic area graph that opens inside a popup, or a new window, that uses several feature properties from the geoJSON where clicked. I am struggling to understand the popup div and when the highchart actually gets created. Right now as I have it the popup opens a highchart graph in the popup window, but it is also behind the base map tile as I can see it if I pan across my map, before the base tiles finish loading. I also notice that the highchart graph does not appear to use the tooltip options such as hover. I suspect that I am not setting up or calling on my div correctly. Here is the relevant part of my code.
<body>
<div id="map">
<div id="chartcontainer" class="highchart">
</div>
<script>
//URL for the WFS JSONP output from geoserver
var URL = "http://localhost:8080/geoserver/Capstone/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=Capstone:TrinityJSON&outputFormat=text/javascript&format_options=callback:getJson";
//ajax to call the WFS from geoserver and add JSON to map
var WFSLayer = null;
var ajax = $.ajax({
url : URL,
dataType : 'jsonp',
jsonpCallback : 'getJson',
success : function (response) {
WFSLayer = L.geoJson(response, {
style: function (feature) {
return {
stroke: false,
fillColor: 'FFFFFF',
fillOpacity: 0.1
};
},
//onEachFeature used to create popup using the JSON data.
onEachFeature: function (feature, layer) {
layer.on('click', function(e){
var chartplotoptions ={
chart: {
type: 'area'
},
title: {
text: 'Aquifer Units'
},
xAxis: {
allowDecimals: false,
labels: {
formatter: function () {
return this.value;
}
}
},
yAxis: {
startOnTick: false,
minPadding: 0.05,
title: {
text: 'Elevation from Sea Level (ft)',
},
labels: {
formatter: function () {
return this.value ;
}
}
},
tooltip: {
pointFormat: '{series.name}{point.y}'
},
plotOptions: {
area: {
pointStart: 0,
threshold: 657,
marker: {
enabled: false,
symbol: 'circle',
radius: 2,
states: {
hover: {
enabled: true
}
}
}
}
},
series: [{
name: 'Surface',
data: [parseFloat(feature.properties.Top1),parseFloat(feature.properties.Top1)]
},
]
};
$('#chartcontainer').highcharts(chartplotoptions);
layer.bindPopup($('#chartcontainer').html());
layer.openPopup();
});
}
}).addTo(map);
}
});
</script>
</body>