Skip to content

Commit

Permalink
#32 Added export to geojson for bookmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayson Ward committed Jul 11, 2017
1 parent cc36833 commit b4435dc
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 22 deletions.
62 changes: 62 additions & 0 deletions MapViewPlus/GeoJsonHelper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

import QtQuick 2.5
import ArcGIS.AppFramework 1.0
import QtQuick.Dialogs 1.2
import '../Geometry'
import '../singletons' as Singletons

Item{

Expand Down Expand Up @@ -188,12 +190,72 @@ Item{
return qmlGeometry;
}

//--------------------------------------------------------------------------

function toGeoJSON(geometry){
var g = JSON.parse(geometry);
var gType;
var gCoords;

if (g.hasOwnProperty("type")) {

if(g.type === Singletons.Constants.kMultipath) {
gType = "LineString";
gCoords = [];
for(var x = 0; x < g.geometry.length; x++){
gCoords.push([g.geometry[x].coordinate.longitude, g.geometry[x].coordinate.latitude]);
}
}

if(g.type === Singletons.Constants.kPolygon){
gType = "Polygon";
gCoords = [[]];
for(var y = 0; y < g.geometry.length; y++){
gCoords[0].push([g.geometry[y].coordinate.longitude, g.geometry[y].coordinate.latitude]);
}
}
}

var geoJson = {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"properties": {},
"geometry": {
"type": gType,
"coordinates": gCoords
}
}]
};

return geoJson;
}

function exportToGeoJSON(geometry,name){
var geoJson = toGeoJSON(geometry);
fileDialog.geoJsonToExport = geoJson;
fileDialog.geoJsonName = name.replace(/[^a-zA-Z0-9]/g,"_").toLocaleLowerCase();
fileDialog.open();
}

// COMPONENTS //////////////////////////////////////////////////////////////

FileFolder {
id: geoJsonFileFolder
}

FileDialog {
id: fileDialog
property var geoJsonToExport
property string geoJsonName
selectFolder: true
onAccepted: {
geoJsonFileFolder.path = AppFramework.resolvedPath(fileDialog.fileUrl);
geoJsonFileFolder.writeJsonFile("%1.geojson".arg(geoJsonName), geoJsonToExport);
fileDialog.close();
}
}

//--------------------------------------------------------------------------

CoordinateConverter{
Expand Down
180 changes: 163 additions & 17 deletions MapViewPlus/MapViewPlus.qml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import QtQuick 2.6
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.1
//import QtQuick.Dialogs 1.2
import QtLocation 5.3
import QtPositioning 5.3
import QtGraphicalEffects 1.0
Expand All @@ -28,6 +27,7 @@ import ArcGIS.AppFramework.Sql 1.0
//------------------------------------------------------------------------------
import "../Portal"
import "../singletons" as Singletons
import "../Controls" as Controls
import "../"
//------------------------------------------------------------------------------

Expand Down Expand Up @@ -256,7 +256,6 @@ Item {
ListView {
anchors.fill: parent
id: bookmarksListView

model: userBookmarks
spacing: sf(2)
delegate: bookmarkDelegate
Expand Down Expand Up @@ -364,7 +363,7 @@ Item {
anchors.margins: sf(4)
spacing: 0

Item{
Item {
Layout.fillHeight: true
Layout.preferredWidth: parent.height
Layout.rightMargin: sf(8)
Expand All @@ -376,7 +375,7 @@ Item {
icon: (!drawingMenu.drawing) ? ( (!drawingMenu.drawingExists) ? _icons.warning : _icons.checkmark ) : _icons.happy_face
}
}
Item{
Item {
Layout.fillHeight: true
Layout.fillWidth: true
Text {
Expand Down Expand Up @@ -958,17 +957,132 @@ Item {

Dialog {
id: addBookmarkDialog
title: "Title"
modal: true
standardButtons: Dialog.Ok | Dialog.Cancel
width: sf(200)
height: sf(200)
height: sf(130)

TextField {
id: bookmarkTitle
width: parent.width
height: sf(20)
placeholderText: qsTr("Enter a title")
ColumnLayout {
anchors.fill: parent
spacing: 0

Item {
Layout.fillWidth: true
Layout.preferredHeight: sf(30)
RowLayout {
anchors.fill: parent
spacing: sf(8)
Item {
Layout.fillHeight: true
Layout.preferredWidth: height
IconFont {
anchors.centerIn: parent
icon: _icons.add_bookmark
color: Singletons.Colors.mainButtonBackgroundColor
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
Text {
anchors.fill: parent
text: qsTr("Enter a title")
verticalAlignment: Text.AlignVCenter
font.pointSize: Singletons.Config.baseFontSizePoint
font.family: notoRegular
}
}
}
}

Item {
Layout.fillWidth: true
Layout.preferredHeight: sf(30)

Controls.StyledTextField {
id: bookmarkTitle
anchors.fill: parent
placeholderText: qsTr("Enter a title")
}
}

Item {
Layout.fillHeight: true
}
Rectangle {
Layout.fillWidth: true
Layout.preferredHeight: sf(1)
Layout.bottomMargin: sf(8)
color: Singletons.Colors.mediumGray
}

Item {
Layout.preferredHeight: sf(30)
Layout.fillWidth: true
RowLayout {
anchors.fill: parent
spacing: sf(8)

Item {
Layout.fillHeight: true
Layout.fillWidth: true
Button {
id: cancelBm
anchors.fill: parent

background: Rectangle {
anchors.fill: parent
color: Singletons.Config.buttonStates(parent, "clear")
radius: app.info.properties.mainButtonRadius
border.width: parent.enabled ? app.info.properties.mainButtonBorderWidth : 0
border.color: "#fff"
}

Text {
color: app.info.properties.mainButtonBackgroundColor
anchors.centerIn: parent
textFormat: Text.RichText
text: Singletons.Strings.cancel
font.pointSize: Singletons.Config.smallFontSizePoint
font.family: notoRegular
}

onClicked: {
addBookmarkDialog.reject();
}
}
}
Item {
Layout.fillHeight: true
Layout.fillWidth: true
Button {
id: addBM
anchors.fill: parent
enabled: bookmarkTitle.text > ""

background: Rectangle {
anchors.fill: parent
color: Singletons.Config.buttonStates(parent)
radius: app.info.properties.mainButtonRadius
border.width: parent.enabled ? app.info.properties.mainButtonBorderWidth : 0
border.color: "#fff"
}

Text {
color: app.info.properties.mainButtonFontColor
anchors.centerIn: parent
textFormat: Text.RichText
text: Singletons.Strings.create
font.pointSize: Singletons.Config.smallFontSizePoint
font.family: notoRegular
}

onClicked: {
addBookmarkDialog.accept();
}
}
}
}
}
}

onAccepted: {
Expand All @@ -987,8 +1101,10 @@ Item {
}
}

onRejected: addBookmarkDialog.close();

onRejected: {
bookmarkTitle.clear();
addBookmarkDialog.close();
}
}

//--------------------------------------------------------------------------
Expand All @@ -1007,12 +1123,17 @@ Item {
Button {
Layout.fillHeight: true
Layout.fillWidth: true
background: Rectangle {
color: "#fff"
}
Text {
anchors.fill: parent
verticalAlignment: Text.AlignVCenter
text: name
font.family: notoRegular
font.pointSize: Singletons.Config.smallFontSizePoint
elide: Text.ElideRight
color: Singletons.Colors.boldUIElementFontColor
}
onClicked: {
var inBookmark = JSON.parse(tpk_app_geometry);
Expand All @@ -1023,12 +1144,37 @@ Item {
Button {
Layout.fillHeight: true
Layout.preferredWidth: height
ToolTip.text: qsTr("Download as geojson")
ToolTip.visible: hovered
background: Rectangle {
color: "#fff"
}

IconFont {
anchors.centerIn: parent
icon: _icons.download
iconSizeMultiplier: .8
color: parent.hovered ? app.info.properties.mainButtonBorderColor : app.info.properties.mainButtonBackgroundColor
}

onClicked: {
geoJsonHelper.exportToGeoJSON(tpk_app_geometry, name);
}
}
Button {
Layout.fillHeight: true
Layout.preferredWidth: height
ToolTip.text: Singletons.Strings.deleteBookmark
ToolTip.visible: hovered
background: Rectangle {
color: "#fff"
}

IconFont {
anchors.centerIn: parent
icon: _icons.trash_bin
iconSizeMultiplier: .8
color: app.info.properties.mainButtonBorderColor
color: parent.hovered ? app.info.properties.mainButtonBorderColor : app.info.properties.mainButtonBackgroundColor
}

onClicked: {
Expand All @@ -1050,7 +1196,6 @@ Item {
g = getMutlipathGeometry();
}
else if (drawEnvelope) {
// g = getEnvelopeGeometry();
g = getPolygonGeometry();
}
else if (drawPolygon) {
Expand Down Expand Up @@ -1210,7 +1355,6 @@ Item {
}

if (typeOfPath === "final") {

_updateDrawingHistory("add",
{
"type": Singletons.Constants.kMultipath,
Expand Down Expand Up @@ -1400,6 +1544,8 @@ Item {
}
}

//--------------------------------------------------------------------------

function _loadBookmarks(){
userBookmarks = appDatabase.read("SELECT * FROM 'bookmarks' WHERE user IS '%1'".arg(portal.user.email));
}
Expand Down
2 changes: 1 addition & 1 deletion appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"urlScheme": "arcgis-tilepackage",
"version": {
"major": 1,
"micro": 11,
"micro": 12,
"minor": 2
}
}
8 changes: 4 additions & 4 deletions iteminfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@
"largeThumbnail": null,
"licenseInfo": "\n<p style='-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;'><br /></p>",
"listed": false,
"modified": 1499669629000,
"modified": 1499742288000,
"name": "561a8441825441349a3b1ad23fdaea75.zip",
"numComments": 26,
"numComments": 27,
"numRatings": 0,
"numViews": 115,
"numViews": 118,
"owner": "appstudio_apps",
"ownerFolder": null,
"properties": null,
"protected": false,
"proxyFilter": null,
"screenshots": [
],
"size": 828119,
"size": 828251,
"snippet": "Tile package creation tool.",
"spatialReference": null,
"tags": [
Expand Down
Loading

0 comments on commit b4435dc

Please sign in to comment.