Skip to content

Commit

Permalink
ajout zoom sur Indre, Hautes-Alpes et Nord via url parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
cdebarros committed Dec 18, 2024
1 parent 51516bd commit 53b67ad
Show file tree
Hide file tree
Showing 23 changed files with 11,390 additions and 49 deletions.
10 changes: 10 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
"glob": "system.svg",
"input": "./node_modules/@gouvfr/dsfr/dist/artwork/pictograms/system",
"output": "artwork/pictograms/system"
},
{
"glob": "technical-error.svg",
"input": "./node_modules/@gouvfr/dsfr/dist/artwork/pictograms/system",
"output": "artwork/pictograms/system"
},
{
"glob": "ovoid.svg",
"input": "./node_modules/@gouvfr/dsfr/dist/artwork/background",
"output": "artwork/background"
}
],
"styles": [
Expand Down
Binary file removed lib/geopf-extensions-openlayers-1.0.0-beta.0-292.tgz
Binary file not shown.
Binary file not shown.
35 changes: 18 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@edugouvfr/ngx-dsfr": "^1.12.6",
"@gouvfr/dsfr": "^1.11.0",
"geopf-extensions-openlayers": "./lib/geopf-extensions-openlayers-1.0.0-beta.0-292.tgz",
"geopf-extensions-openlayers": "./lib/geopf-extensions-openlayers-1.0.0-beta.1-296.tgz",
"geoportal-access-lib": "^3.4.4",
"ol": "^9.1.0"
},
Expand Down
6 changes: 5 additions & 1 deletion src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from "@angular/common/http";

import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
providers: [provideRouter(routes)]
providers: [
provideRouter(routes),
provideHttpClient()
],
};
17 changes: 17 additions & 0 deletions src/app/app.routes.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { inject } from "@angular/core";
import { Router, ActivatedRouteSnapshot, UrlTree, CanActivateFn } from "@angular/router";

export function AllowedLocation(allowedEntities: string[]): CanActivateFn {
return (route: ActivatedRouteSnapshot): boolean | UrlTree => {
const router: Router = inject(Router);
const entitiesType: string | null = route.paramMap.get(
'location'
);

if(entitiesType){
return allowedEntities.indexOf(entitiesType.toLocaleLowerCase()) !== -1 ? true : router.parseUrl('/');
}else{
return false;
}
};
}
8 changes: 8 additions & 0 deletions src/app/app.routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { NotfoundComponent } from './pages/errors/notfound/notfound.component';
import { AllowedLocation } from './app.routes.guard';

export const routes: Routes = [
{ path: '', component: HomeComponent },
{ path: ':location',
component: HomeComponent,
canActivate: [AllowedLocation(['indre', 'hautes-alpes', 'nord'])]
},
//Wild Card Route for any 404 request
{ path: '**', pathMatch: 'full', component: NotfoundComponent },
];
8 changes: 4 additions & 4 deletions src/app/carte/carte.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit, Input, ElementRef } from '@angular/core';

import Map from 'ol/Map';
import { LayerWMS as GeoportalLayerWMS, LayerWMTS as GeoportalLayerWMTS,} from "geopf-extensions-openlayers/src";
import { LayerWMS as GeoportalLayerWMS, LayerWMTS as GeoportalLayerWMTS, LayerWFS as GeoportalLayerWFS} from "geopf-extensions-openlayers/src";

@Component({
selector: 'app-carte',
Expand All @@ -18,17 +18,17 @@ export class CarteComponent implements OnInit {
ngOnInit() {
this.map.setLayers([
new GeoportalLayerWMS({
apikey:"full",
layer: "ORTHOIMAGERY.ORTHOPHOTOS",
}),
new GeoportalLayerWMS({
apikey:"full",
layer: "GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2",
}),
new GeoportalLayerWMTS({
apikey:"full",
layer: "LIMITES_ADMINISTRATIVES_EXPRESS.LATEST",
}),
new GeoportalLayerWFS({
layer: "poc_v5_carto_sp_interne_sans_z_gpkg_13-12-2024_wfs:carto_sp_interne",
})
]);

this.map.setTarget(this.elementRef.nativeElement);
Expand Down
23 changes: 23 additions & 0 deletions src/app/controls/layerselector/layerselector.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { LayerselectorComponent } from './layerselector.component';

describe('LayerselectorComponent', () => {
let component: LayerselectorComponent;
let fixture: ComponentFixture<LayerselectorComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LayerselectorComponent]
})
.compileComponents();

fixture = TestBed.createComponent(LayerselectorComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
150 changes: 150 additions & 0 deletions src/app/controls/layerselector/layerselector.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import { Component, OnInit, Input, ElementRef } from '@angular/core';

import Map from 'ol/Map';
import Control from 'ol/control/Control';

@Component({
selector: 'app-layerselector',
standalone: true,
imports: [],
template: '',
styles: [],
})
export class LayerselectorComponent implements OnInit {
@Input() map!: Map;
control!: Control;

constructor(private elementRef: ElementRef) {}

ngOnInit() {
this.control = new LayerSelectorControl({ target : this.elementRef.nativeElement, position: 'bottom-left' });
this.map.addControl(this.control);
}

}

class LayerSelectorControl extends Control {
/**
* @param {Object} [opt_options] Control options.
*/
// @ts-ignore
constructor(opt_options) {
const options = opt_options || {};

// Button
const button = document.createElement('button');
button.classList.add("GPshowOpen", "GPshowAdvancedToolPicto", "gpf-btn-icon-isocurve", "fr-btn", "fr-btn--tertiary", "gpf-btn--tertiary", "gpf-btn", "gpf-btn-icon");
button.setAttribute("aria-pressed", "false");
button.setAttribute("type", "button");
button.removeAttribute("title");
button.setAttribute("tabindex", "0");
button.setAttribute("aria-label", 'Sélectionner une couche');
button.style.float = 'left';

// tool element container
const element = document.createElement('div');
element.id = "GPLayerSelector";
element.classList.add("GPwidget", "gpf-widget", "gpf-widget-button");
element.classList.remove("ol-unselectable", "ol-control");
element.style.inset = 'unset';
element.style.position = 'unset';
element.appendChild(button);

const element2 = document.createElement('div');
element2.id = "menu-layer-selector";
element2.innerHTML = "voici mon message";
element2.style.backgroundColor = 'white';
element2.style.width = '150px';
element2.style.position = 'relative';
element2.style.left = '50px';
element2.style.bottom = '5px';
element2.style.visibility = 'hidden';
element.appendChild(element2);

// set element to target
if (options.position) {
var id = "position-container-" + options.position;
if (!document.getElementById(id)) {
// Creation manuelle du container de position
var div = document.createElement("div");
div.id = id;
div.classList.add("position");
div.classList.add(id);
element.appendChild(div);
}
// @ts-ignore
options.target = document.getElementById(id)?.appendChild(element);
}

super({
element: element,
target: options.target,
});

button.addEventListener('click', this.showSelector.bind(this), false);
}

showSelector(e: any) {
var status = (e.target.ariaPressed === "true");
e.target.setAttribute("aria-pressed", !status);

e.target.parentNode.querySelector('#menu-layer-selector').style.visibility = "visible";
// @ts-ignore
this.getMap().getView().setZoom(2);
}
}

// html
/*<div class="cc-selector">
<input checked="checked" id="visa" type="radio" name="credit-card" value="visa" />
<label class="drinkcard-cc visa" for="visa"></label>
<input id="mastercard" type="radio" name="credit-card" value="mastercard" />
<label class="drinkcard-cc mastercard"for="mastercard"></label>
</div>
// css
.cc-selector input{
margin:0;padding:0;
-webkit-appearance:none;
-moz-appearance:none;
appearance:none;
}
.image1{background-image:url(http://i.imgur.com/lXzJ1eB.png);}
.image2{background-image:url(http://i.imgur.com/SJbRQF7.png);}
.cc-selector input:active +.drinkcard-cc{opacity: .9;}
.cc-selector input:checked +.drinkcard-cc{
-webkit-filter: none;
-moz-filter: none;
filter: none;
}
.drinkcard-cc{
cursor:pointer;
background-size:contain;
background-repeat:no-repeat;
display:inline-block;
width:100px;height:70px;
-webkit-transition: all 100ms ease-in;
-moz-transition: all 100ms ease-in;
transition: all 100ms ease-in;
-webkit-filter: brightness(1.8) grayscale(1) opacity(.7);
-moz-filter: brightness(1.8) grayscale(1) opacity(.7);
filter: brightness(1.8) grayscale(1) opacity(.7);
}
.drinkcard-cc:hover{
-webkit-filter: brightness(1.2) grayscale(.5) opacity(.9);
-moz-filter: brightness(1.2) grayscale(.5) opacity(.9);
filter: brightness(1.2) grayscale(.5) opacity(.9);
}
// Extras
a:visited{color:#888}
a{color:#444;text-decoration:none;}
p{margin-bottom:.3em;}
* { font-family:monospace; }
.cc-selector-2 input{ margin: 5px 0 0 12px; }
.cc-selector-2 label{ margin-left: 7px; }
span.cc{ color:#6d84b4 }*/
2 changes: 1 addition & 1 deletion src/app/controls/scaleline/scaleline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ScaleLine from 'ol/control/ScaleLine';
selector: 'app-scaleline',
standalone: true,
template: '',
styles: ['::ng-deep .ol-scale-line{left: 50px;}']
styles: ['::ng-deep .ol-scale-line{left: 60px;}']
})
export class ScalelineComponent implements OnInit {
@Input() map!: Map;
Expand Down
10 changes: 9 additions & 1 deletion src/app/controls/search/search.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Component, OnInit, Input, ElementRef } from '@angular/core';

import Map from 'ol/Map';
import Geometry from 'ol/geom/Geometry';
import GeoJSON from 'ol/format/GeoJSON';
import Control from 'ol/control/Control';
import { SearchEngine } from "geopf-extensions-openlayers/src";
// @ts-ignore
import Gp from 'geoportal-access-lib';
import { Extent } from 'ol/extent';
import { SimpleGeometry } from 'ol/geom';

@Component({
selector: 'app-search',
Expand All @@ -20,11 +26,13 @@ export class SearchComponent implements OnInit {
this.control = new SearchEngine({
displayButtonClose: false,
displayButtonAdvancedSearch: false,
collapsible: true,
splitResults: false,
markerStyle: 'turquoiseBlue',
zoomTo: 'auto',
target: this.elementRef.nativeElement,
});

this.map.addControl(this.control);
}
}
Loading

0 comments on commit 53b67ad

Please sign in to comment.