Leaflet GeoJson¶
Table of Contents
Access¶
A web application employing LeafletJS and GeoJson is enabled upon installation.
It can be access via the Leaflet tab on the home page:

It can also be access directly via url at:
http://domain.com/LeafletJSDemo.html
Usage¶
Once accessed using above, the app will appear as shown below:

Click on the US layer to view the getFeature info for the State.
The data will be displayed as below:

Structure¶
The app is located at:
/vaw/www/html/LeafletJSDemo.html
On installation, data from PostgreSQL is exported to GeoJson format and saved to:
/var/www/html/states.json
Content¶
The content of the html page is displayed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | <!doctype html>
<html>
<head>
<style type="text/css">
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
</style>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.1.0/dist/leaflet.css"
integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.1.0/dist/leaflet.js"
integrity="sha512-mNqn2Wg7tSToJhvHcqfzLMU6J4mkOImSPTxVZAdo+lcPlk+GhZmYgACEe0x35K7YzW1zJ7XyJV/TT1MrdXvMcA=="
crossorigin=""></script>
</head>
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
</head>
<body>
<div id="map"></div>
<script>
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 2, maxZoom: 8, attribution: osmAttrib});
$.getJSON("states.geojson", function(data) {
function onEachFeature(feature, layer) {
layer.bindPopup("Name: " + feature.properties.STATE_NAME + "<br>" + "Abbreviation: " + feature.properties.STATE_ABBR);
}
var geojson = L.geoJson(data, {
onEachFeature: onEachFeature
});
var map = L.map('map').fitBounds(geojson.getBounds());
osm.addTo(map);
geojson.addTo(map);
});
</script>
</body>
</html>
|