Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make drawlayer into a vectorlayer to fix #63 #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/draw/drawhandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function setActive(drawType) {
function onTextEnd(feature, textVal) {
// Remove the feature if no text is set
if (textVal === '') {
drawLayer.getFeatureStore().removeFeature(feature);
drawLayer.getSource().removeFeature(feature);
} else {
feature.set(annotationField, textVal);
}
Expand Down Expand Up @@ -128,7 +128,7 @@ function onDrawEnd(evt) {

function setDraw(tool, drawType) {
let geometryType = tool;
drawSource = drawLayer.getFeatureStore();
drawSource = drawLayer.getSource();
activeTool = tool;

if (activeTool === 'Text') {
Expand Down Expand Up @@ -156,7 +156,7 @@ function onDeleteSelected() {
const features = select.getFeatures();
let source;
if (features.getLength()) {
source = drawLayer.getFeatureStore();
source = drawLayer.getSource();
features.forEach((feature) => {
source.removeFeature(feature);
});
Expand All @@ -165,9 +165,8 @@ function onDeleteSelected() {
}

function onSelectAdd(e) {
let feature;
if (e.target) {
feature = e.target.item(0);
const feature = e.target.item(0);
const featureStyle = feature.getStyle() || Style.createStyleRule(defaultDrawStyle.draw[1]);
featureStyle.push(selectionStyle);
feature.setStyle(featureStyle);
Expand Down Expand Up @@ -215,7 +214,7 @@ function removeInteractions() {

function getState() {
if (drawLayer) {
const source = drawLayer.getFeatureStore();
const source = drawLayer.getSource();
const geojson = new Origo.ol.format.GeoJSON();
const features = source.getFeatures();
const json = geojson.writeFeatures(features);
Expand All @@ -231,9 +230,16 @@ function restoreState(state) {
// TODO: Sanity/data check
if (state.features && state.features.length > 0) {
if (drawLayer === undefined) {
drawLayer = Origo.featurelayer(null, map);
drawLayer = new Origo.ol.layer.Vector({
group: 'none',
name: 'drawplugin',
visible: true,
zIndex: 7,
source: new Origo.ol.source.Vector()
});
map.addLayer(drawLayer);
}
const source = drawLayer.getFeatureStore();
const source = drawLayer.getSource();
source.addFeatures(state.features);
source.getFeatures().forEach((feature) => {
if (feature.get(annotationField)) {
Expand Down Expand Up @@ -270,14 +276,18 @@ function toggleDraw(e) {

function onEnableInteraction(e) {
if (e.detail.interaction === 'draw' && !isActive()) {
const drawStyle = Style.createStyleRule(defaultDrawStyle.draw);

if (drawLayer === undefined) {
drawLayer = Origo.featurelayer(null, map);
drawLayer.setStyle(drawStyle);
drawLayer = new Origo.ol.layer.Vector({
group: 'none',
name: 'drawplugin',
visible: true,
zIndex: 7,
source: new Origo.ol.source.Vector()
});
map.addLayer(drawLayer);
}
select = new Origo.ol.interaction.Select({
layers: [drawLayer.getFeatureLayer()],
layers: [drawLayer],
style: null,
hitTolerance: 5
});
Expand Down