-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
260dfc4
commit bdf137f
Showing
10 changed files
with
247 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,9 +37,11 @@ | |
</div> | ||
</div> | ||
|
||
<div> | ||
<span id="status"></span> | ||
| | ||
<span id="event"></span> | ||
</div> | ||
|
||
<div id="status"></div> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ol.js"></script> | ||
<script src="https://www.unpkg.com/ol-osmwaysnap/dist/bundle/index.js"></script> | ||
<script lang="js"> | ||
|
@@ -76,12 +78,27 @@ | |
document.getElementById('status').innerHTML = 'Loading from OSM…'; | ||
}); | ||
interaction.getWaySource().on('featuresloadend', () => { | ||
document.getElementById('status').innerHTML = ''; | ||
document.getElementById('status').innerHTML = 'Idle'; | ||
}); | ||
interaction.getWaySource().on('featuresloaderror', () => { | ||
document.getElementById('status').innerHTML = 'ERROR'; | ||
}); | ||
|
||
interaction.on('waysnapstartcreate', () => { | ||
document.getElementById('event').innerHTML = 'A new feature has been created.'; | ||
}); | ||
interaction.on('waysnapstartedit', () => { | ||
document.getElementById('event').innerHTML = 'A feature edition has started.'; | ||
}); | ||
interaction.on('waysnapupdate', e => { | ||
const n = e.feature.getGeometry().getCoordinates().length; | ||
document.getElementById('event').innerHTML = `The feature has been updated with vertices: ${n}`; | ||
}); | ||
interaction.on('waysnapend', e => { | ||
const n = e.feature.getGeometry().getCoordinates().length; | ||
document.getElementById('event').innerHTML = `Feature edition ended with total vertices: ${n}`; | ||
}); | ||
|
||
const wkt = new ol.format.WKT(); | ||
const geojson = new ol.format.GeoJSON(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import Event from 'ol/events/Event'; | ||
import type { Feature } from 'ol'; | ||
import type { ObjectEvent } from 'ol/Object'; | ||
import type { Types as ObjectEventTypes } from 'ol/ObjectEventType'; | ||
import type { CombinedOnSignature, EventTypes as ObservableEventTypes, OnSignature } from 'ol/Observable'; | ||
import type { LineString } from 'ol/geom'; | ||
|
||
/** | ||
* Event type for OSMWaySnapInteraction | ||
*/ | ||
export const OSMWaySnapEventType = { | ||
/** Event when OSMWaySnap interaction starts on a feature whether creation or edition. */ | ||
WAYSNAPSTART: 'waysnapstart', | ||
|
||
/** Event when OSMWaySnap interaction has created a new feature. */ | ||
WAYSNAPSTARTCREATE: 'waysnapstartcreate', | ||
|
||
/** Event when OSMWaySnap has started edition an existing feature. */ | ||
WAYSNAPSTARTEDIT: 'waysnapstartedit', | ||
|
||
/** Event when OSMWaySnap has updated the active feature. */ | ||
WAYSNAPUPDATE: 'waysnapupdate', | ||
|
||
/** Event when OSMWaySnap has finished. */ | ||
WAYSNAPEND: 'waysnapend' | ||
} as const; | ||
|
||
type OSMWaySnapEventType = typeof OSMWaySnapEventType[keyof typeof OSMWaySnapEventType]; | ||
|
||
/** | ||
* Event for OSMWaySnap interaction | ||
*/ | ||
export class OSMWaySnapEvent extends Event { | ||
/** Active feature for the event */ | ||
private _feature: Feature<LineString>; | ||
|
||
/** Active feature for the event */ | ||
public get feature(): Feature<LineString> { return this._feature }; | ||
|
||
/** | ||
* Constructor | ||
* @param type Type of event | ||
* @param feature Active feature for the event | ||
*/ | ||
constructor(type: OSMWaySnapEventType, feature: Feature<LineString>) { | ||
super(type); | ||
this._feature = feature; | ||
} | ||
} | ||
|
||
/** Type signature for OSMWaySnap interaction event dispatcher */ | ||
export type OSMWaySnapOnSignature<Return> = OnSignature<ObservableEventTypes, Event, Return> | ||
& OnSignature<ObjectEventTypes|'change:active', ObjectEvent, Return> | ||
& OnSignature<OSMWaySnapEventType, OSMWaySnapEvent, Return> | ||
& CombinedOnSignature<ObservableEventTypes|ObjectEventTypes|'change:active'|OSMWaySnapEventType, Return>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { OSMWaySnapEventType, OSMWaySnapEvent, type OSMWaySnapOnSignature } from './event'; | ||
export { default as OSMWaySnap, type OSMWaySnapOptions } from './interaction'; | ||
export { default as LineStringUtils } from './line-string-utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.