Skip to content

Commit

Permalink
#29 Added Polygon support
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayson Ward committed Jan 17, 2017
1 parent 8faff61 commit b273565
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 37 deletions.
59 changes: 36 additions & 23 deletions MapViewPlus/GeoJsonHelper.qml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Item{
features = json.features[0];
}

// Esri geojson
// Esri geojson has crs property -----------------------------------

if(json.hasOwnProperty("crs")){
var sr = json.crs.properties.name;
Expand All @@ -88,7 +88,7 @@ Item{
}
}

// Esri json
// Esri json has spatialReference property -------------------------

if(json.hasOwnProperty("spatialReference")){
if(json.spatialReference.wkid === 102100 || json.spatialReference.wkid === 3857 || json.spatialReference.latestWkid === 3857){
Expand All @@ -97,16 +97,37 @@ Item{
}
}

// Normalize type, for convenience normalize to esri types -----

if(features.geometry.hasOwnProperty("type")){
if(features.geometry.type === "Polygon"){
returnGeometry.type = "esriGeometryPolygon";
}
if(features.geometry.type === "LineString"){
returnGeometry.type = "esriGeometryPolyline";
}
}

if(json.hasOwnProperty("geometryType")){
returnGeometry.type = json.geometryType;
}


if(features.hasOwnProperty("geometry")){

if(features.geometry.hasOwnProperty("coordinates")){
returnGeometry.coordinates = features.geometry.coordinates;
returnGeometry.coordinates = (returnGeometry.type === "esriGeometryPolygon") ? features.geometry.coordinates[0]: features.geometry.coordinates;
}
else if(features.geometry.hasOwnProperty("paths")){
if(features.geometry.paths.length > 0){
returnGeometry.coordinates = features.geometry.paths[0];
}
}
else if(features.geometry.hasOwnProperty("rings")){
if(features.geometry.rings.length > 0){
returnGeometry.coordinates = features.geometry.rings[0];
}
}
else{
returnGeometry.coordinates = [];
}
Expand All @@ -122,22 +143,21 @@ Item{
returnGeometry.coordinates = newCoordsInLngLat;
}

// returnGeometry.extent = geomUtilities.getExtent(returnGeometry.coordinates);

if(features.geometry.hasOwnProperty("type")){
if(features.geometry.type === "Polygon"){
error("TPK only handles polyline geometry currently.");
returnGeometry.type = "esriGeometryPolygon";
}
if(features.geometry.type === "LineString"){
returnGeometry.coordinatesForQML = _prepareGeometryForQMLMapPolyline(returnGeometry.coordinates);
returnGeometry.type = "esriGeometryPolyline";
}

// Fix coords for QML based on type ----------------------------

/*
if(returnGeometry.type === "esriGeometryPolygon"){
returnGeometry.coordinatesForQML = _prepareGeometryForQMLMapPolygon(returnGeometry.coordinates);
}
if(json.hasOwnProperty("geometryType")){
returnGeometry.type = json.geometryType;
if(returnGeometry.type === "esriGeometryPolyline"){
returnGeometry.coordinatesForQML = _prepareGeometryForQMLMapPolyline(returnGeometry.coordinates);
}
*/

returnGeometry.coordinatesForQML = _prepareGeometryForQMLMap(returnGeometry.coordinates);

}

Expand All @@ -150,7 +170,7 @@ Item{

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

function _prepareGeometryForQMLMapPolyline(coords){
function _prepareGeometryForQMLMap(coords){

var qmlGeometry = [];

Expand All @@ -175,13 +195,6 @@ Item{
return qmlGeometry;
}

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

function _prepareGeometryForQMLMapPolygon(coords){
// if length is 5 and first coord matches last coord then it is an envelope/Rectangle
}


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

FileFolder {
Expand Down
93 changes: 84 additions & 9 deletions MapViewPlus/MapViewPlus.qml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Item {

property string geometryType: ""
property bool drawEnvelope: geometryType === "envelope" ? true : false
property bool drawPolygon: geometryType === "polygon" ? true : false
property bool drawMultipath: geometryType === "multipath" ? true : false

readonly property alias map: previewMap.map
Expand Down Expand Up @@ -558,6 +559,15 @@ Item {

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

MapPolygon{
id:drawnPolygon
color: drawingExtentFillColor
border.width: 2 * AppFramework.displayScaleFactor
border.color: drawnExtentOutlineColor
}

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

MapQuickItem {
id: clearExtentMapItem
visible: false
Expand Down Expand Up @@ -601,11 +611,21 @@ Item {
id: geoJsonHelper

onSuccess: {
drawingStarted();
pathCoordinates = geometry.coordinatesForQML;
//mapViewPlus.map.center = QtPositioning.coordinate(geometry.extent.center.latitude, geometry.extent.center.longitude);
//mapViewPlus.map.visibleRegion = QtPositioning.rectangle(QtPositioning.coordinate(geometry.extent.ymin, geometry.extent.xmin), QtPositioning.coordinate(geometry.extent.ymax, geometry.extent.xmax))
addMultipathToMap("final");
geometryType = "multipath";
if(geometry.type !== ""){
if(geometry.type === "esriGeometryPolygon"){
geometryType = "polygon";
addPolygonToMap("final");
}

if(geometry.type === "esriGeometryPolyline"){
geometryType = "multipath";
addMultipathToMap("final");
}
}

//addMultipathToMap("final");
mapViewPlus.map.fitViewportToMapItems();
}
}
Expand All @@ -623,6 +643,11 @@ Item {
console.log("drawEnvelope ", drawEnvelope)
g = getEnvelopeGeometry();
}
else if(drawPolygon){
console.log("drawPolygon ", drawPolygon)
g = getPolygonGeometry();
}

else{
console.log('no geometry');
g = null;
Expand Down Expand Up @@ -664,13 +689,33 @@ Item {
"geometries" : envelope
}

//return extent;
console.log(JSON.stringify(envelopeGeometry));
return envelopeGeometry;
}

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

function getPolygonGeometry(){

var esriPolygonObject = {
"geometryType": "esriGeometryPolygon",
"geometries" : [{
"rings":[[]],
"spatialReference": {
"wkid": mapSpatialReference
}
}]
};

for(var i = 0; i < pathCoordinates.length; i++){
esriPolygonObject.geometries[0].rings[0].push([pathCoordinates[i].coordinate.longitude, pathCoordinates[i].coordinate.latitude]);
}

return esriPolygonObject;

}

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

function getMutlipathGeometry(){

// This looks convoluted because esri polyline json is composed of multiple nested arrays
Expand All @@ -686,9 +731,9 @@ Item {

};

for(var i = 0; i < pathCoordinates.length; i++){
esriPolyLineObject.geometries[0].paths[0].push([pathCoordinates[i].coordinate.longitude, pathCoordinates[i].coordinate.latitude]);
}
for(var i = 0; i < pathCoordinates.length; i++){
esriPolyLineObject.geometries[0].paths[0].push([pathCoordinates[i].coordinate.longitude, pathCoordinates[i].coordinate.latitude]);
}

return esriPolyLineObject;
}
Expand Down Expand Up @@ -771,6 +816,36 @@ Item {

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

function addPolygonToMap(typeOfPath){

clearMap();

var path = [];
for(var i = 0; i < pathCoordinates.length; i++){
path.push(pathCoordinates[i]['coordinate']);
}

drawnPolygon.path = path;

mapViewPlus.map.addMapItem(drawnPolygon);

if(typeOfPath === "final"){
userDrawnExtent = true;
clearDrawingCanvas();

mapViewPlus.map.addMapItem(clearExtentMapItem);
clearExtentMapItem.anchorPoint = Qt.point(15,15);
clearExtentMapItem.coordinate = QtPositioning.coordinate(path[0].latitude, path[0].longitude);
clearExtentMapItem.visible = true;
clearExtentMapItem.enabled = true;

drawingFinished();
}

}

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

function _fixDrawnCoordinates() {

var mapMinX = mapDrawCanvas.x
Expand Down
2 changes: 1 addition & 1 deletion appinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"urlScheme": "arcgis-tilepackage",
"version": {
"major": 1,
"micro": 91,
"micro": 92,
"minor": 0
}
}
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": 1484608427000,
"modified": 1484614600000,
"name": "561a8441825441349a3b1ad23fdaea75.zip",
"numComments": 7,
"numComments": 8,
"numRatings": 0,
"numViews": 37,
"numViews": 39,
"owner": "appstudio_apps",
"ownerFolder": null,
"properties": null,
"protected": false,
"proxyFilter": null,
"screenshots": [
],
"size": 1210145,
"size": 1210196,
"snippet": "Tile package creation tool.",
"spatialReference": null,
"tags": [
Expand Down

0 comments on commit b273565

Please sign in to comment.