-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added(editor): Introduced batch editing to group multiple feature mod…
…ifications into a single history entry. See [batch](https://heremaps.github.io/xyz-maps/docs/classes/editor.editor-1.html#batch), [startBatch](https://heremaps.github.io/xyz-maps/docs/classes/editor.editor-1.html#startBatch), [endBatch](https://heremaps.github.io/xyz-maps/docs/classes/editor.editor-1.html#endBatch), [Playground Example](https://heremaps.github.io/xyz-maps/playground/#Editor-Batch_Changes) Signed-off-by: Tim Deubler <tim.deubler@here.com>
- Loading branch information
1 parent
bd18b18
commit b697ae4
Showing
12 changed files
with
263 additions
and
15 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
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
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
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,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, user-scalable=no"> | ||
<title>XYZ Maps Example: Batch Changes</title> | ||
<style type="text/css"> | ||
#map { | ||
position: absolute; | ||
overflow: hidden; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
} | ||
pre div, span div { | ||
position: relative; | ||
display: inline-block; | ||
left: 20px; | ||
background-color: #333; | ||
color: #fff; | ||
padding: 10px; | ||
font-family: 'LFira Sans', Arial, Helvetica, sans-serif; | ||
} | ||
a.button { | ||
position: relative; | ||
display: block; | ||
color: #FFFFFF; | ||
cursor: pointer; | ||
left: 20px; | ||
height: 23px; | ||
padding: 5px 6px 0px; | ||
width: 150px; | ||
text-align: center; | ||
margin: 12px 0 0 0; | ||
background-color: #333; | ||
} | ||
a.button:hover{ | ||
background-color: #555; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="map"></div> | ||
<a id="change" class="button">Apply Batched Changes</a> | ||
<a id="undo" class="button">Undo</a> | ||
<a id="redo" class="button">Redo</a> | ||
</body> | ||
</html> |
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,79 @@ | ||
import {MVTLayer, TileLayer, SpaceProvider, GeoJSONCoordinate} from '@here/xyz-maps-core'; | ||
import {Map} from '@here/xyz-maps-display'; | ||
import {Editor, Marker} from '@here/xyz-maps-editor'; | ||
|
||
/** setup the Map **/ | ||
let backgroundLayer = new MVTLayer({ | ||
min: 1, max: 20, | ||
remote: { | ||
url: 'https://vector.hereapi.com/v2/vectortiles/base/mc/{z}/{x}/{y}/omv?apikey=' + YOUR_API_KEY | ||
} | ||
}); | ||
let myLayer = new TileLayer({ | ||
min: 14, max: 20, | ||
provider: new SpaceProvider({ | ||
space: '6CkeaGLg', | ||
credentials: { | ||
access_token: YOUR_ACCESS_TOKEN | ||
}, | ||
level: 14 | ||
}), | ||
style: { | ||
styleGroups: { | ||
Point: [{ | ||
type: 'Circle', zIndex: 0, radius: 20, fill: '#ff7220', stroke: '#ff1d00aa', strokeWidth: 5 | ||
}, { | ||
type: 'Text', zIndex: 1, text: ['get', 'counter'], fill: 'black', stroke: 'white', strokeWidth: 5, font: '22px sans-serif' | ||
}] | ||
}, | ||
assign() { | ||
return 'Point'; | ||
} | ||
} | ||
}); | ||
|
||
myLayer.addFeature({ | ||
id: 'myFeature', | ||
type: 'Feature', | ||
geometry: { | ||
type: 'Point', | ||
coordinates: [-116.85755, 33.03607] | ||
}, | ||
properties: { | ||
counter: 0 | ||
} | ||
}); | ||
|
||
// setup the Map Display | ||
const display = new Map(document.getElementById('map'), { | ||
zoomlevel: 17, | ||
center: {longitude: -116.85755, latitude: 33.03607}, | ||
|
||
// add layers to display | ||
layers: [backgroundLayer, myLayer] | ||
}); | ||
|
||
// setup the editor | ||
const editor = new Editor(display); | ||
|
||
// add the layer to the editor to enable editing of the layer | ||
editor.addLayer(myLayer); | ||
/** **/ | ||
|
||
document.querySelector<HTMLButtonElement>('#change').onclick = function() { | ||
// Batch multiple changes to create a single history step | ||
editor.batch(()=>{ | ||
const myFeature =<Marker>myLayer.search({id: 'myFeature'}); | ||
// First change: Increment the 'counter' property of the feature by | ||
myFeature.prop('counter', myFeature.prop('counter') + 1); | ||
// Second change: Adjust the feature's position slightly to the right | ||
const currentPosition = <GeoJSONCoordinate>myFeature.coord(); | ||
myFeature.coord([currentPosition[0] + 0.0001, currentPosition[1]]); | ||
}); | ||
}; | ||
|
||
document.querySelector<HTMLButtonElement>('#undo').onclick = () => editor.undo(); | ||
|
||
document.querySelector<HTMLButtonElement>('#redo').onclick = () => editor.redo(); | ||
|
||
|
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