-
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
Showing
8 changed files
with
315 additions
and
114 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
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,99 @@ | ||
import {LitElement, html, css} from 'lit'; | ||
import { layerIntersect } from '../utils/layerintersect'; | ||
import getVisibleFeatures from '../utils/mbox-features'; | ||
import './wc-button'; | ||
|
||
class MapDatatoolIntersect extends LitElement { | ||
static get styles() { | ||
return css` | ||
:host { | ||
display: block; | ||
}` | ||
} | ||
static get properties() { | ||
return { | ||
resulttype: {type: String}, | ||
map: {type: Object}, | ||
intersectCount: {type: Number} | ||
}; | ||
} | ||
constructor() { | ||
super(); | ||
this.resulttype = 'aantal'; | ||
this.map = {}; | ||
this.intersectCount = -1; | ||
} | ||
connectedCallback() { | ||
super.connectedCallback() | ||
//addEventListener('keydown', this._handleKeydown); | ||
} | ||
disconnectedCallback() { | ||
super.disconnectedCallback() | ||
//window.removeEventListener('keydown', this._handleKeydown); | ||
} | ||
shouldUpdate(changedProp) { | ||
if (changedProp.has('sprop')) { | ||
// do something with sprop change | ||
} | ||
return true; | ||
} | ||
render() { | ||
return html` | ||
<b>Intersect berekenen</b><p></p> | ||
Bereken elementen in kaartlaag 1 die een element in kaartlaag2 snijden (ergens raken)<p></p> | ||
<b>Kaartlaag 1</b><br> | ||
${this._renderLayerList()} | ||
<b>Kaartlaag 2</b><br> | ||
${this._renderLayerList()} | ||
<input type="radio" name="resulttype" value="aantal" id="aantal" ?checked="${this.resulttype==='aantal'}"><label for="aantal">Aantal</label><br> | ||
<input type="radio" name="resulttype" value="layeryes" id="layeryes" ?checked="${this.resulttype==='layeryes'}"><label for="layeryes">Uitvoerkaartlaag met elementen met een overlap</label><br> | ||
<input type="radio" name="resulttype" value="layerno" id="layerno" ?checked="${this.resulttype==='layerno'}"><label for="layerno">Uitvoerkaartlaag met elementen zonder een overlap</label><br> | ||
<wc-button class="edugisblue" @click="${e=>this._handleClick(e)}" ?disabled="${!this.buttonEnabled}">Berekenen</wc-button><br> | ||
${this.intersectCount > -1 ?html`Aantal elementen: ${this.intersectCount}`:html``} | ||
</div> | ||
` | ||
} | ||
firstUpdated() { | ||
|
||
} | ||
updated() { | ||
|
||
} | ||
_layerSelected(e) { | ||
const selections = this.shadowRoot.querySelectorAll('select'); | ||
this.buttonEnabled = (selections.length === 2 && (selections[0].value != selections[1].value) && (selections[0].value !== '') && selections[1].value !== ''); | ||
this.sourceLayerid = this.buttonEnabled ? selections[0].value : undefined; | ||
this.targetLayerid = this.buttonEnabled ? selections[1].value : undefined; | ||
this.intersectCount = -1; | ||
this.update(); | ||
} | ||
_renderLayerList() { | ||
const layers = this.map.getStyle().layers.filter(layer=>layer.metadata && !layer.metadata.reference && !layer.metadata.isToolLayer && ['fill','line','circle','symbol'].includes(layer.type)); | ||
if (layers.length < 2) { | ||
return html`${layers.length} kaartlagen aanwezig (minimmaal 2 nodig)`; | ||
} | ||
return html`<div class="styled-select"><select @change="${e=>this._layerSelected(e)}"> | ||
<option value="" disabled selected>Selecteer kaartlaag</option> | ||
${layers.map(layer=>html`<option value=${layer.id}>${layer.metadata.title?layer.metadata.title:layer.id}</option>`)} | ||
</select><span class="arrow"></span></div>` | ||
} | ||
async _calculateIntersect() { | ||
if (this.sourceLayerid && this.targetLayerid) { | ||
const sourceFeatures = await getVisibleFeatures(this.map, this.sourceLayerid); | ||
const targetFeatures = await getVisibleFeatures(this.map, this.targetLayerid); | ||
const intersectLayer = layerIntersect({type: "FeatureCollection", features:sourceFeatures}, {type:"FeatureCollection", features:targetFeatures}); | ||
this.intersectCount = intersectLayer.features.reduce((total, feature)=>{ | ||
return feature.properties.intersect?total+1:total | ||
}, 0); | ||
this.update(); | ||
} | ||
} | ||
_handleClick(e) { | ||
if (!this.buttonEnabled) { | ||
return; | ||
} | ||
this._calculateIntersect(); | ||
} | ||
} | ||
|
||
customElements.define('map-datatool-intersect', MapDatatoolIntersect); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,22 @@ | ||
export function cloneJSON(obj) { | ||
// basic type deep copy | ||
if (obj === null || obj === undefined || typeof obj !== 'object') { | ||
return obj | ||
} | ||
// array deep copy | ||
if (obj instanceof Array) { | ||
var cloneA = []; | ||
for (var i = 0; i < obj.length; ++i) { | ||
cloneA[i] = cloneJSON(obj[i]); | ||
} | ||
return cloneA; | ||
} | ||
// object deep copy | ||
var cloneO = {}; | ||
for (var i in obj) { | ||
cloneO[i] = cloneJSON(obj[i]); | ||
} | ||
return cloneO; | ||
} | ||
|
||
export default cloneJSON; |
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,37 @@ | ||
import Flatbush from 'flatbush'; | ||
import cloneJSON from '../utils/clonejson'; | ||
|
||
function flatBushIndex(layer) { | ||
const flatbushIndex = new Flatbush(layer.features.length); | ||
for (const feature of layer.features) { | ||
const bbox = turf.bbox(feature); | ||
flatbushIndex.add(bbox[0], bbox[1], bbox[2], bbox[3]); | ||
} | ||
flatbushIndex.finish(); | ||
return flatbushIndex; | ||
} | ||
|
||
export function layerIntersect(layer1, layer2) { | ||
if (layer1 && layer1.type && layer1.type === "FeatureCollection" && layer2 && layer2.type && layer2.type === "FeatureCollection") { | ||
// create index on layer2 | ||
const layerIndex = flatBushIndex(layer2); | ||
layer1 = cloneJSON(layer1); | ||
for (const feature of layer1.features) { | ||
const bbox = turf.bbox(feature); | ||
const intersectCandidates = layerIndex.search(bbox[0], bbox[1], bbox[2], bbox[3]); | ||
for (const candidate of intersectCandidates) { | ||
const feature2 = layer2.features[candidate]; | ||
if (turf.booleanIntersects(feature, feature2)) { | ||
feature.properties.intersect = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
for (const feature of layer1.features) { | ||
if (!feature.properties.intersect) { | ||
feature.properties.intersect = false; | ||
} | ||
} | ||
return layer1; | ||
} |
Oops, something went wrong.