How to load GeoJSON data
This article mainly explains "how to load GeoJSON data". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to load GeoJSON data".
Leaflet is an open source JavaScript class library for interactive maps on the desktop and mobile. The size of the JS library is about 38k after compression, and it has all the map functions that developers need.
Leaflet maintains the design idea of simplicity, performance and practicality. It works efficiently on all major desktop and mobile platforms, and can extend plug-ins. It has a beautiful, easy-to-use and well-documented API, and a simple, easy-to-read source code.
Leaflet can realize data display and pop-up data information management by loading GeoJSON data, loading point, line and surface data in batches, and transforming them into corresponding feature objects.
The following is illustrated by an GeoJSON load point data that is displayed as an icon:
/ / iterate through each feature, bind pop-up bubbles and prompt messages
Function onEachFeature (feature, layer) {
If (feature.properties & & feature.properties.name) {
Layer.bindTooltip (feature.properties.name)
Layer.bindPopup (feature.properties.address)
}
}
/ / set icon style
Var baseballIcon = L.icon ({
IconUrl: 'img/leaflet/school_icon.png'
IconSize: [24, 27]
IconAnchor: [12, 27]
PopupAnchor: [0,-28]
TooltipAnchor: [0,-20]
});
/ / load json data
$.getJSON ('sampledata/ta_school_point.json', function (data) {
/ / create a layer through geojson
Schoollayer =
L.geoJSON (data, {
OnEachFeature: onEachFeature
/ / cycle to set icon style
PointToLayer: function (feature, latlng) {
Return L.marker (latlng, {
Icon: baseballIcon
});
}
});
/ / add to the map and locate
Schoollayer.addTo (map)
Map.fitBounds (schoollayer.getBounds ())
});
Thank you for your reading, the above is the content of "how to load GeoJSON data", after the study of this article, I believe you have a deeper understanding of how to load GeoJSON data, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!