Skip to content

Commit

Permalink
Add change style to new points with right click
Browse files Browse the repository at this point in the history
  • Loading branch information
ThierryNormand committed Aug 28, 2023
1 parent e59e294 commit b8e77ac
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 108 deletions.
113 changes: 93 additions & 20 deletions package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"fast-text-encoding": "^1.0.4",
"file-saver": "^2.0.2",
"flexsearch": "0.7.21",
"geostyler-openlayers-parser": "^4.2.1",
"hammerjs": "^2.0.8",
"html2canvas": "^1.4.1",
"jspdf": "^2.5.1",
Expand Down Expand Up @@ -107,9 +108,9 @@
"@angular-eslint/eslint-plugin-template": "14.1.2",
"@angular-eslint/schematics": "14.1.2",
"@angular-eslint/template-parser": "14.1.2",
"@angular/platform-browser-dynamic": "^14.3.0",
"@angular/cli": "^14.2.10",
"@angular/compiler-cli": "^14.3.0",
"@angular/platform-browser-dynamic": "^14.3.0",
"@babel/core": "^7.18.10",
"@babel/preset-env": "^7.18.10",
"@compodoc/compodoc": "^1.1.19",
Expand Down
84 changes: 78 additions & 6 deletions src/app/pages/portal/portal.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,12 @@ import {
MapExtent,
moveToOlFeatures,
FeatureMotion,
ConfigFileToGeoDBService
ConfigFileToGeoDBService,
FeatureDataSource
} from '@igo2/geo';

import * as olGeom from 'ol/geom';

import {
ToolState,
MapState,
Expand All @@ -101,8 +104,9 @@ import { HttpClient, HttpParams } from '@angular/common/http';
import { WelcomeWindowComponent } from './welcome-window/welcome-window.component';
import { WelcomeWindowService } from './welcome-window/welcome-window.service';
import { MatPaginator } from '@angular/material/paginator';
import { ObjectUtils } from '@igo2/utils';
import { ObjectUtils, uuid } from '@igo2/utils';
import olFormatGeoJSON from 'ol/format/GeoJSON';
import { KEY_FORMAT_JWK } from '@azure/msal-browser/dist/utils/BrowserConstants';

Check failure on line 109 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

'KEY_FORMAT_JWK' is defined but never used

Check failure on line 109 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

'KEY_FORMAT_JWK' is defined but never used

@Component({
selector: 'app-portal',
Expand Down Expand Up @@ -394,6 +398,16 @@ export class PortalComponent implements OnInit, OnDestroy {
title: 'Change style',
handler: () => this.changeStyle()
},
{
id: 'Change new points style',
title: 'Change new points style',
handler:() => this.changePointsStyle()
},
{
id: 'addLayer',
title: 'addLayer Point',
handler: () => this.addLayerWithPoint(this.contextMenuCoord)
},
{
id: 'coordinates',
title: 'coordinates',
Expand Down Expand Up @@ -649,6 +663,38 @@ export class PortalComponent implements OnInit, OnDestroy {
this.sidenavMediaAndOrientation$$.unsubscribe();
}

changePointsStyle() {
const lastLayer = this.map.getLayerById('layerWithPoints');

const pointGeoStyle: any = {
"name": "Basic star fill",
"rules": [
{
"name": "Rule 2",
"symbolizers": [
{
"kind": "Mark",
"wellKnownName": "star",
"color": "#ff0000",
"radius": 15
}
]
}
]
};

const olParser2 = new OpenLayersParser;
olParser2.writeStyle(pointGeoStyle)
.then((output) => {
console.log("output", output);
(lastLayer.ol as any).setStyle(output.output)

Check failure on line 690 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 690 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
console.log("output", output.output)

Check failure on line 691 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 691 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
})
.catch(error => console.log(error));
console.log("lastLayer", lastLayer)

Check failure on line 694 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 694 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon

}

changeStyle() {
const lastLayer = this.map.layers
.filter(l => l.showInLayerList)
Expand All @@ -662,8 +708,10 @@ export class PortalComponent implements OnInit, OnDestroy {
"symbolizers": [
{
"kind": "Mark",
"wellKnownName": "circle",
"wellKnownName": "triangle",
"color": "#ff8000",
"strokeColor": "#000000",
"rotate": 90,
"radius": 30
},
{
Expand All @@ -677,15 +725,16 @@ export class PortalComponent implements OnInit, OnDestroy {
}
]
};

const olParser = new OpenLayersParser();
olParser.writeStyle(geoStylerStyle)
.then((output) => {
console.log(output);
console.log("output", output);
(lastLayer.ol as any).setStyle(output.output)

Check failure on line 733 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 733 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
console.log(output.output)
console.log("output", output.output)

Check failure on line 734 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 734 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
})
.catch(error => console.log(error));
console.log(lastLayer)
console.log("lastLayer", lastLayer)

Check failure on line 737 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 737 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
}

/**
Expand Down Expand Up @@ -957,6 +1006,29 @@ export class PortalComponent implements OnInit, OnDestroy {
coord.map((c) => c.toFixed(6)).join(', ') : coord.reverse().map((c) => c.toFixed(6)).join(', ');
}

addLayerWithPoint(coord: [number, number]) {
let layer = this.map.getLayerById('layerWithPoints') as VectorLayer;
if (!layer) {
layer = new VectorLayer({
title: 'Layer de points créé afin de changer le style.',
isIgoInternalLayer: true,
id: `layerWithPoints`,
zIndex: 200,
source: new FeatureDataSource(),
igoStyle: undefined,
showInLayerList: true,
exportable: true,
browsable: false,
workspace: { enabled: true }
});
this.map.addLayer(layer);
}
const geometry4326 = new olGeom.Point(coord);
const geometryMapProjection = geometry4326.transform('EPSG:4326',this.map.projection);
const feature = new olFeature({ id: uuid(), geometry: geometryMapProjection });
layer.dataSource.ol.addFeature(feature)

Check failure on line 1029 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Missing semicolon

Check failure on line 1029 in src/app/pages/portal/portal.component.ts

View workflow job for this annotation

GitHub Actions / build (18.x)

Missing semicolon
}

updateMapBrowserClass() {
const header = this.queryState.store.entities$.value.length > 0;
if (this.hasExpansionPanel && this.workspaceState.workspaceEnabled$.value) {
Expand Down
Loading

0 comments on commit b8e77ac

Please sign in to comment.