Skip to content

Commit

Permalink
Fix sur les exemples Leaflet avec un appel de Gp.Services.getConfig()
Browse files Browse the repository at this point in the history
  • Loading branch information
lowzonenose committed Jun 12, 2023
1 parent 6b8634e commit 59efde6
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 16 deletions.
13 changes: 6 additions & 7 deletions DRAFT_CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@







# Extension Geoportail OpenLayers, version __VERSION__

**__DATE__**
> Release Extension Geoportail openlayers
## Summary

- Ajout d'exemples avec l'appel de *Gp.Services.getConfig()*

## Changelog

* [Added]
Expand All @@ -30,14 +27,15 @@




# Extension Geoportail Leaflet, version __VERSION__

**__DATE__**
> Release Extension Geoportail leaflet
## Summary

- Ajout d'exemples avec l'appel de *Gp.Services.getConfig()*

## Changelog

* [Added]
Expand All @@ -50,13 +48,14 @@

* [Fixed]

- Fix sur les exemples avec un appel de *Gp.Services.getConfig()*

* [Security]

---




# Extension Geoportail Itowns, version __VERSION__

**__DATE__**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{{#extend "layout-leaflet-sample-bundle-getconfig"}}

{{#content "head"}}
<title>Sample Leaflet</title>
{{/content}}

{{#content "style"}}
<style>
div#map {
width: 100%;
height: 500px;
}
</style>
{{/content}}

{{#content "body"}}
<h2>Ajout de tous les widgets</h2>
<!-- map -->
<div id="map"></div>
{{/content}}

{{#content "js"}}
// on cache l'image de chargement du Géoportail.
document.getElementById("map").style.backgroundImage = "none";

// Création de la map
var layer = L.geoportalLayer.WMTS({
layer : "ORTHOIMAGERY.ORTHOPHOTOS"
});

var map = L.map('map', {
zoom : 2,
center : L.latLng(48, 2)
});

layer.addTo(map);

var iso = L.geoportalControl.Isocurve();
map.addControl(iso);
var layerSwitcher = L.geoportalControl.LayerSwitcher();
map.addControl(layerSwitcher);
var mp = L.geoportalControl.MousePosition();
map.addControl(mp);
var route = L.geoportalControl.Route();
map.addControl(route);
var reverse = L.geoportalControl.ReverseGeocode();
map.addControl(reverse);
var search = L.geoportalControl.SearchEngine();
map.addControl(search);
var measureProfil = L.geoportalControl.ElevationPath();
map.addControl(measureProfil);
{{/content}}
{{/extend}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{{#extend "ol-sample-bundle-getconfig-layout"}}

{{#content "head"}}
<title>Sample openlayers - multikeys</title>
{{/content}}

{{#content "style"}}
<style>
div#map {
width: 100%;
height: 500px;
}
</style>
{{/content}}

{{#content "body"}}
<h2>Ajout de tous les widgets</h2>
<!-- map -->
<div id="map">
</div>
{{/content}}

{{#content "js"}}
// on cache l'image de chargement du Géoportail.
document.getElementById("map").style.backgroundImage = "none";

// Création de la map
var map = new ol.Map({
target : "map",
layers : [
new ol.layer.GeoportalWMTS({
layer : "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2"
}),
new ol.layer.GeoportalWMTS({
layer : "GEOGRAPHICALGRIDSYSTEMS.ETATMAJOR40"
}),
new ol.layer.GeoportalWMTS({
layer : "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST"
})
],
view : new ol.View({
center : [288074.8449901076, 6247982.515792289],
zoom : 13
})
});

var drawing = new ol.control.Drawing();
map.addControl(drawing);
var iso = new ol.control.Isocurve();
map.addControl(iso);
var layerImport = new ol.control.LayerImport();
map.addControl(layerImport);
var layerSwitcher = new ol.control.LayerSwitcher();
map.addControl(layerSwitcher);
var mp = new ol.control.GeoportalMousePosition();
map.addControl(mp);
var route = new ol.control.Route();
map.addControl(route);
var reverse = new ol.control.ReverseGeocode({});
map.addControl(reverse);
var search = new ol.control.SearchEngine({});
map.addControl(search);
var feature = new ol.control.GetFeatureInfo({});
map.addControl(feature);

var measureLength = new ol.control.MeasureLength();
map.addControl(measureLength);
var measureArea = new ol.control.MeasureArea();
map.addControl(measureArea);
var measureAzimuth = new ol.control.MeasureAzimuth();
map.addControl(measureAzimuth);
var measureProfil = new ol.control.ElevationPath();
map.addControl(measureProfil);

var attributions = new ol.control.GeoportalAttribution();
map.addControl(attributions);
{{/content}}
{{/extend}}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Ajout de tous les widgets</h2>
{{#content "js"}}
<script type="text/javascript">

var createMap = function () {
window.onload = function () {
// on cache l'image de chargement du Géoportail.
document.getElementById("map").style.backgroundImage = "none";

Expand Down Expand Up @@ -79,13 +79,6 @@ <h2>Ajout de tous les widgets</h2>
map.addControl(attributions);
};

Gp.Services.getConfig({
// callbackSuffix : '',
apiKey: "{{ apikey }}",
timeOut: 20000,
onSuccess: createMap
});

</script>
{{/content}}
{{/extend}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
{{#extend "partials-common-head"}}
{{/extend}}
{{#extend "partials-leaflet-common-head"}}
{{/extend}}
{{#block "vendor"}}
{{/block}}

{{#extend "partials-leaflet-bundle-getconfig-head"}}
{{/extend}}

{{#block "head"}}
{{/block}}
{{#block "style"}}
{{/block}}

</head>
<body>
<h1>Extension Géoportail pour Leaflet (mode bundle)</h1>

{{#block "body"}}
{{/block}}

<script>
var createMap = function () {
{{#block "js"}}
{{/block}}
};
Gp.Services.getConfig({
// callbackSuffix : '',
apiKey: "{{ apikey }}",
timeOut: 20000,
onSuccess: createMap,
onFailure: function (e) {
console.error(e);
}
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
{{#extend "partials-common-head"}}
{{/extend}}
{{#extend "partials-ol-common-head"}}
{{/extend}}
{{#block "vendor"}}
{{/block}}
{{#extend "partials-ol-bundle-getconfig-head"}}
{{/extend}}

{{#block "head"}}
{{/block}}
{{#block "style"}}
{{/block}}

</head>
<body>
<h1>Extension Géoportail pour OpenLayers</h1>

{{#block "body"}}
{{/block}}

<script>
var createMap = function () {
{{#block "js"}}
{{/block}}
};
Gp.Services.getConfig({
// callbackSuffix : '',
apiKey: "{{ apikey }}",
timeOut: 20000,
onSuccess: createMap
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<!-- Leaflet Library -->
<script src="{{ baseurl }}/node_modules/leaflet/dist/leaflet{{ debug }}.js"></script>
<!-- Geoportal Extension for Leaflet -->
<script src="{{ baseurl }}/dist/leaflet/GpPluginLeaflet{{ mode }}.js"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!-- Library OpenLayers -->
<!-- <script src="https://openlayers.org/en/{{ version }}/build/ol.js"></script> -->
<script src="{{ resources }}/vendor/ol/{{ version }}/ol.js"></script>
<!-- Plugin OpenLayers IGN -->
<script src="{{ baseurl }}/dist/openlayers/GpPluginOpenLayers{{ mode }}.js"></script>
4 changes: 4 additions & 0 deletions src/Common/Utils/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ var Config = {
* @returns {Boolean} True if Config is loaded, false otherwise
*/
isConfigLoaded : function () {
// config already loaded !
if (this.configuration && Object.keys(this.configuration).length !== 0) {
return true;
}
var scope = typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : {};
if (scope.Gp && scope.Gp.Config && scope.Gp.Config.layers && Object.keys(scope.Gp.Config.layers).length !== 0) {
/** ts-syntax */ (this.configuration) = scope.Gp.Config;
Expand Down
5 changes: 5 additions & 0 deletions src/Leaflet/Layers/LayerConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ var LayerConfig = {
get : function (options) {
var params = {};

if (!Config.isConfigLoaded()) {
logger.warn("WARNING CONFIG_FAILED : config not loaded ?!");
return;
}

// gestion des parametres
params = Config.configuration.getLayerParams(options.layer, options.service);

Expand Down
4 changes: 3 additions & 1 deletion src/Leaflet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ export { default as ProxyUtils } from "../Common/Utils/ProxyUtils";
export { default as ColorUtils } from "../Common/Utils/ColorUtils";
export { default as MathUtils } from "../Common/Utils/MathUtils";
export { default as Logger } from "../Common/Utils/LoggerByDefault";
export { default as Config } from "../Common/Utils/Config";

// HACK !?
export const Config = (window.Gp) ? window.Gp.Config : {};

// creation du namespace pour les extensions leaflet
L.geoportalLayer = Layers; // WMS et WMTS
Expand Down

0 comments on commit 59efde6

Please sign in to comment.