mirror of
https://github.com/Viglino/ol-ext.git
synced 2025-12-08 19:26:29 +00:00
165 lines
4.6 KiB
HTML
165 lines
4.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!--
|
|
Copyright (c) 2015-2018 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
-->
|
|
<title>ol-ext: Flickr layer</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="DBPedia layer for OL3" />
|
|
<meta name="keywords" content="ol, opanlayers, layer, source, vector, flickr, photo" />
|
|
|
|
<!-- jQuery -->
|
|
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
|
|
<!-- Openlayers -->
|
|
<link rel="stylesheet" href="https://openlayers.org/en/v6.15.1/css/ol.css" />
|
|
<script type="text/javascript" src="https://openlayers.org/en/v6.15.1/build/ol.js"></script>
|
|
|
|
|
|
<!-- ol-ext -->
|
|
<link rel="stylesheet" href="../../dist/ol-ext.css" />
|
|
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
|
|
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
|
|
<script src="https://unpkg.com/elm-pep"></script>
|
|
|
|
<!-- ol-ext maki and fontawesome defintions used in fontsymbol -->
|
|
<script type="text/javascript" src="../../dist/extra/FontAwesomeDef.js"></script>
|
|
|
|
<!-- filesaver-js -->
|
|
<script type="text/javascript" src="https://cdn.rawgit.com/eligrey/FileSaver.js/aa9f4e0e/FileSaver.min.js"></script>
|
|
|
|
<link rel="stylesheet" href="../style.css" />
|
|
<style>
|
|
#select img {
|
|
max-height: 300px;
|
|
}
|
|
#map {
|
|
width: 600px;
|
|
height: 400px;
|
|
}
|
|
.fullscreen #map {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
z-index: 10;
|
|
}
|
|
.fullscreen .options.top {
|
|
position: fixed;
|
|
top: 0;
|
|
right: 0;
|
|
z-index:10000;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
|
|
|
|
<a href="../../index.html">
|
|
<h1>ol-ext: Flickr layer</h1>
|
|
</a>
|
|
<p class="info">
|
|
</p>
|
|
|
|
<!-- DIV pour la carte -->
|
|
<div id="map"></div>
|
|
<div class="options top">
|
|
<button onclick="$('body').toggleClass('fullscreen'); map.updateSize();">fullscreen</button>
|
|
</div>
|
|
<div id ="select" class="options" >Select an item.</div>
|
|
|
|
<script type="text/javascript">
|
|
// The map
|
|
var map = new ol.Map({
|
|
target: 'map',
|
|
view: new ol.View({
|
|
zoom: 5,
|
|
center: [159167, 5950510]
|
|
}),
|
|
interactions: ol.interaction.defaults(),
|
|
layers: [ new ol.layer.Tile({ name:"OSM", source: new ol.source.OSM() })]
|
|
});
|
|
|
|
|
|
var vector = new ol.layer.Vector({
|
|
name: 'DBPedia',
|
|
source: new ol.source.Vector(),
|
|
style: function(f) {
|
|
return new ol.style.Style({
|
|
image: new ol.style.Photo ({
|
|
src: f.get("img"),
|
|
radius: 20,
|
|
crop: true,
|
|
shadow: 5,
|
|
onload: function() { vector.changed(); },
|
|
stroke: new ol.style.Stroke({
|
|
width: 3,
|
|
color: '#fff'
|
|
})
|
|
})
|
|
})
|
|
}
|
|
});
|
|
|
|
map.addLayer(vector);
|
|
|
|
// Load feed
|
|
$.ajax({
|
|
url: 'https://api.flickr.com/services/feeds/geo/',
|
|
dataType: 'jsonp',
|
|
jsonpCallback: 'jsonFlickrFeed',
|
|
data: {
|
|
format: 'json',
|
|
// A comma delimited list of tags to filter the feed by.
|
|
tags: 'oiseau,france',
|
|
// Control whether items must have ALL the tags (tagmode=all), or ANY (tagmode=any) of the tags. Default is ALL.
|
|
tagmode: 'all',
|
|
// A comma delimited list of user IDs
|
|
ids: '',
|
|
// The display language for the feed
|
|
lang: 'fr-fr'
|
|
},
|
|
success: function (resp) {
|
|
console.log(resp.items.length+' items.')
|
|
var features = [];
|
|
resp.items.forEach(function(item) {
|
|
var feature = new ol.Feature(item);
|
|
feature.set('img', item.media.m);
|
|
feature.unset('media');
|
|
var geom = new ol.geom.Point([parseFloat(item.longitude), parseFloat(item.latitude)]);
|
|
feature.setGeometry(geom.transform('EPSG:4326', map.getView().getProjection()));
|
|
features.push(feature);
|
|
});
|
|
vector.getSource().addFeatures(features);
|
|
},
|
|
error: function() { console.log('oops'); }
|
|
})
|
|
|
|
// Control Select
|
|
var select = new ol.interaction.Select({
|
|
// select dbPedia style function
|
|
style: ol.style.dbPediaStyleFunction({ prefix:"sel", radius:12, fill: new ol.style.Fill({ color:"red"}) })
|
|
})
|
|
map.addInteraction(select);
|
|
// On selected
|
|
select.getFeatures().on(['add','remove'], function(e){
|
|
var info = $("#select").html("");
|
|
if (e.type=="add") {
|
|
var el = e.element;
|
|
$("<h2>").text(el.get("title")).appendTo(info);
|
|
// $("<img>").attr('src',el.get("img")).appendTo(info);
|
|
$("<div>").html(el.get("description")).appendTo(info);
|
|
}
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |