-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from OpenDRR/leaflet-manual-integration
Leaflet manual integration
- Loading branch information
Showing
8 changed files
with
15,367 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -284,4 +284,5 @@ stylesheets: | |
crossorigin: "anonymous" | ||
theme-name: GCWeb | ||
title: "gcweb-jekyll" # Site name or title | ||
wetSiteRoot: "https://wet-boew.github.io/wet-boew" | ||
wetSiteRoot: "https://wet-boew.github.io/wet-boew" | ||
leaflet: "[email protected]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
|
||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> | ||
<script src="{{ site.assets }}/{{ site.theme-name }}/wet-boew/js/wet-boew.min.js"></script> | ||
<!-- {% if page.leaflet == true %} | ||
<script src="https://unpkg.com/{{ site.leaflet }}/dist/leaflet.js"></script> | ||
{% endif %} --> | ||
{% if site.themeJS == true %}<script src="{{ site.assets }}/{{ site.theme-name }}/js/theme.min.js"></script>{% endif %} | ||
{% if section == "mobile-centre" %}<script src="{{ site.assets }}/js/whole-record-link.min.js"></script>{% endif %} | ||
{% if page.javascripts %}{% for script in page.javascripts %}<script {% for attr in script %}{% if attr[0] == 'src' or attr[0] == 'data-main' %}{{ attr[0] }}="{{ attr[1] | relative_url }}" {% else %}{{ attr[0] }}="{{ attr[1] }}" {% endif %}{% endfor %}></script>{% endfor %}{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
<div id="map" class="leafmap" style="width: 100%;height:300px;"></div> | ||
<script src="https://unpkg.com/{{ site.leaflet }}/dist/leaflet.js"></script> | ||
<script> | ||
{% if page.leaflet %} | ||
// L.Icon.Default.imagePath = '{{ "images/carto/" | prepend: site.baseurl }}'; | ||
|
||
var viirs = 'VIIRS_SNPP_CorrectedReflectance_TrueColor'; | ||
// var modis = 'MODIS_Terra_CorrectedReflectance_TrueColor'; | ||
|
||
var basemap = { | ||
'OpenStreetMap': L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
'attribution': '© <a href="https://osmlab.github.io/attribution-mark/copyright/?name={{ site.title }}">OpenStreetMap</a> contributors', | ||
'minZoom': 2, | ||
'maxZoom': 19 | ||
}), | ||
'Thunderforest': L.tileLayer('https://{s}.tile.thunderforest.com/' + '{% if include.tf_layer %}{{ include.tf_layer }}{% else %}outdoors{% endif %}' + '/{z}/{x}/{y}.png', { | ||
'attribution': 'Maps © <a href="http://www.thunderforest.com/">Thunderforest</a>, © <a href="https://osmlab.github.io/attribution-mark/copyright/?name={{ site.title }}">OpenStreetMap</a> contributors', | ||
'minZoom': 2, | ||
'maxZoom': 19 | ||
}), | ||
'Carto': L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/' + '{% if include.c_layer %}{{ include.c_layer }}{% else %}dark_all{% endif %}' + '/{z}/{x}/{y}.png', { | ||
'attribution': '© <a href="http://cartodb.com/attributions">CartoDB</a>, © <a href="https://osmlab.github.io/attribution-mark/copyright/?name={{ site.title }}">OpenStreetMap</a> contributors', | ||
'minZoom': 2, | ||
'maxZoom': 19 | ||
}), | ||
'Esri': L.tileLayer('https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', { | ||
'attribution': 'Tiles © Esri, © <a href="https://osmlab.github.io/attribution-mark/copyright/?name={{ site.title }}">OpenStreetMap</a> contributors', | ||
'minZoom': 3, | ||
'maxZoom': 18 | ||
}), | ||
'Gibs': L.tileLayer('https://map1.vis.earthdata.nasa.gov/wmts-webmerc/' + viirs + '/default/' + '{{ page.date| date: "%Y-%m-%d" }}' + '/GoogleMapsCompatible_Level9/{z}/{y}/{x}.jpg', { | ||
'attribution': 'Maps © <a href="http://earthdata.nasa.gov">Gibs</a>, © <a href="https://osmlab.github.io/attribution-mark/copyright/?name={{ site.title }}">OpenStreetMap</a> contributors', | ||
'minZoom': 3, | ||
'maxZoom': 9 | ||
}) | ||
}; | ||
|
||
var map = L.map('map', { | ||
{% if page.latlng %} | ||
'center': [{{ page.latlng[0] }}, {{ page.latlng[1] }}], | ||
'zoom': {{ page.zoom }}, | ||
{% if include.leaflet_tile %} | ||
'layers': [basemap.{{ include.leaflet_tile }}] | ||
{% else %} | ||
'layers': [basemap.OpenStreetMap] | ||
{% endif %} | ||
{% endif %} | ||
}); | ||
map.scrollWheelZoom.disable(); | ||
{% endif %} | ||
|
||
{% if page.mlatlng %} | ||
var marker = L.marker( | ||
[{{ page.mlatlng[0] }}, {{ page.mlatlng[1] }}] | ||
).addTo(map); | ||
{% endif %} | ||
|
||
{% if page.icon %} | ||
var xmarker = L.icon({ | ||
iconUrl: '{{ page.icon | prepend: site.baseurl }}', | ||
iconRetinaUrl: '{{ page.icon | prepend: site.baseurl }}', | ||
iconSize: [37, 50], | ||
iconAnchor: [18.5, 50], | ||
popupAnchor: [0, -51] | ||
}); | ||
|
||
var marker = L.marker([{{ page.mlatlng[0] }}, {{ page.mlatlng[1] }}], { | ||
icon: {{ page.icon }} | ||
}).addTo(map); | ||
{% endif %} | ||
|
||
{% if page.mpop or page.icon %} | ||
marker.bindPopup("{{ page.mpop }}").openPopup(); | ||
{% endif %} | ||
|
||
{% if page.layer %} | ||
var layer_obj; | ||
fetch( "{{page.layer}}" ).then(( resp ) => { | ||
return resp.json(); | ||
}).then(( data ) => { | ||
layer_obj = data; | ||
_addGeoJSONObjToMap( layer_obj, map ); | ||
}).catch(( err ) => { | ||
console.log( err ); | ||
_addGeoJSONObjToMap( layer_obj, map ); | ||
}); | ||
{% endif %} | ||
|
||
function _onEachFeature( feature, layer ) { | ||
var potentialPopup = "" | ||
if ( feature.properties && feature.properties.popupContent ) { | ||
potentialPopup += feature.properties.popupContent; | ||
} | ||
if ( feature.properties && feature.properties.href ) { | ||
potentialPopup += | ||
'<a href="' + feature.properties.href + '">' + | ||
'<img src="' + newWindowImgSrcBase64 + '"></img></a>';} | ||
if( potentialPopup ){ | ||
layer.bindPopup(potentialPopup ); | ||
} | ||
} | ||
|
||
function _addGeoJSONObjToMap( leafletItem, map ){ | ||
var geojson = L.geoJSON( leafletItem, { | ||
onEachFeature: _onEachFeature, | ||
style: featureStyle | ||
} ); | ||
layers = geojson.getLayers(); | ||
for ( var i=0; i<layers.length; i++ ){ | ||
try { | ||
var geom = layers[i].feature.geometry; | ||
if (!( 'center' in tagInputArg )){ | ||
// If the user didn't specify a center, infer from geojson | ||
map.panTo( new L.LatLng( geom.coordinates[1], | ||
geom.coordinates[0] ) ); | ||
} | ||
} catch( e ){ } | ||
} | ||
geojson.addTo( map ); | ||
} | ||
|
||
function getColor(d) { | ||
return d > 1000 ? '#800026' : | ||
d > 500 ? '#BD0026' : | ||
d > 200 ? '#E31A1C' : | ||
d > 100 ? '#FC4E2A' : | ||
d > 50 ? '#FD8D3C' : | ||
d > 20 ? '#FEB24C' : | ||
d > 10 ? '#FED976' : | ||
'#FFEDA0'; | ||
} | ||
|
||
function featureStyle(feature) { | ||
return { | ||
fillColor: getColor(feature.properties.CensusPop), | ||
weight: 1, | ||
opacity: 1, | ||
color: 'white', | ||
dashArray: '0', | ||
fillOpacity: 0.7 | ||
}; | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.