mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-25 17:36:21 +00:00
154 lines
5.3 KiB
HTML
154 lines
5.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!----------------------------------------------------------
|
|
|
|
Copyright (c) 2017-2018 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
|
|
------------------------------------------------------------>
|
|
<title>ol-ext: WikiCommons layer</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="WikiCommons layer for OL3" />
|
|
<meta name="keywords" content="ol3, layer, source, vector, wikipedia, wikimedia, commons" />
|
|
|
|
<!-- 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/master/css/ol.css" />
|
|
<script type="text/javascript" src="https://openlayers.org/en/master/build/ol.js"></script>
|
|
|
|
<!-- ol-ext -->
|
|
<link rel="stylesheet" href="../../dist/ol-ext.css" />
|
|
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
|
|
|
|
<!-- ol-ext maki and fontawesome defintions used in fontsymbol -->
|
|
<script type="text/javascript" src="../../dist/extra/fontawesomedef.js"></script>
|
|
|
|
<link rel="stylesheet" href="../style.css" />
|
|
<style>
|
|
#select img
|
|
{ max-height: 300px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol3-ext"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
|
|
|
|
<a href="../../index.html">
|
|
<h1>ol-ext: WikiCommons layer</h1>
|
|
</a>
|
|
<p class="info">
|
|
<i>ol.layer.WikiCommons</i> is a tile vector layer that use <a href="https://commons.wikimedia.org/">Wikimedia Commons</a>.
|
|
</p>
|
|
|
|
<!-- DIV pour la carte -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
<div class="options"></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: 15,
|
|
center: [261204.43490751847, 6250258.191535994]
|
|
}),
|
|
interactions: ol.interaction.defaults(),
|
|
layers: [ new ol.layer.Tile({ name:"OSM", source: new ol.source.OSM() })]
|
|
});
|
|
|
|
// WikiCommons layer source
|
|
var vectorSource = new ol.source.WikiCommons(
|
|
{ // Tile strategy load at zoom 14
|
|
strategy: ol.loadingstrategy.tile(ol.tilegrid.createXYZ({ minZoom: 14, maxZoom: 14, tileSize:512 })),
|
|
// Bbox strategy : reload at each move
|
|
//strategy: ol.loadingstrategy.bbox,
|
|
// Language
|
|
lang:"fr"
|
|
});
|
|
|
|
// Force layer reload on resolution change
|
|
map.getView().on('change:resolution', function(evt)
|
|
{ //vectorSource.clear();
|
|
if (map.getView().getZoom() < 14) $(".options").first().text("Zoom to load data...");
|
|
else $(".options").first().text("");
|
|
});
|
|
|
|
var iconStyle = [ new ol.style.Style() ];
|
|
var selectStyle = [ new ol.style.Style() ];
|
|
var vector = new ol.layer.Vector(
|
|
{ name: 'WikiCommons',
|
|
source: vectorSource,
|
|
// Limit resolution to avoid large area request
|
|
maxResolution: 10, // > zoom 14
|
|
// y ordering
|
|
renderOrder: ol.ordering.yOrdering(),
|
|
style: function() { return iconStyle }
|
|
});
|
|
|
|
map.addLayer(vector);
|
|
|
|
// Control Select
|
|
var select = new ol.interaction.Select(
|
|
{ style: function(){ return selectStyle; }
|
|
})
|
|
map.addInteraction(select);
|
|
// On select > show information
|
|
select.getFeatures().on(['add','remove'], function(e)
|
|
{ var info = $("#select").html("");
|
|
if (e.type=="add")
|
|
{ var el = e.element;
|
|
console.log(el.getProperties())
|
|
$("<h2>").text(el.get("title")).appendTo(info);
|
|
if (el.get("thumbnail"))
|
|
{ $("<img>").attr('src',el.get("thumbnail")).appendTo(info)
|
|
.wrap($("<a>").attr({href: el.get('descriptionurl'), target:"new" }));
|
|
}
|
|
$("<p>").html("© WikiCommons - "+el.get('user')+" - "+el.get('copy')).appendTo(info);
|
|
}
|
|
});
|
|
|
|
</script>
|
|
|
|
<!-- Script to test webfont loading -->
|
|
<!-- @see https://github.com/zachleat/fontfaceonload -->
|
|
<!-- @use https://github.com/typekit/webfontloader -->
|
|
<script src="https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
|
|
<script type="text/javascript">
|
|
WebFont.load(
|
|
{ custom: {
|
|
families: ['FontAwesome'],
|
|
urls: ['https://rawgit.com/FortAwesome/Font-Awesome/master/css/font-awesome.min.css'],
|
|
testStrings: { 'FontAwesome': '\uf240' }
|
|
},
|
|
classes: false,
|
|
// Clear the cache and force redraw when fonts are loaded
|
|
active: function()
|
|
{ iconStyle = [ new ol.style.Style(
|
|
{ image: new ol.style.FontSymbol (
|
|
{ fill: new ol.style.Fill({ color: "#369" }),
|
|
stroke: new ol.style.Stroke({ color: "#fff", width: 2 }),
|
|
radius: 10,
|
|
glyph: "fa-camera"
|
|
})
|
|
})];
|
|
selectStyle = [ new ol.style.Style(
|
|
{ image: new ol.style.FontSymbol (
|
|
{ fill: new ol.style.Fill({ color:"red" }),
|
|
stroke: new ol.style.Stroke({ color: "#fff", width: 2 }),
|
|
radius: 12,
|
|
glyph: "fa-camera"
|
|
})
|
|
})];
|
|
vector.changed();
|
|
console.log("FontAwesome is loaded!");
|
|
}
|
|
});
|
|
</script>
|
|
<!-- -->
|
|
</body>
|
|
</html> |