Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
appinventor-sources
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
appinventor-sources
Commits
77150161
Commit
77150161
authored
May 16, 2019
by
Evan W. Patton
Committed by
Jeffrey Schiller
May 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor GeoJSON processing in mock map features
Change-Id: I89f5cd0b2ab49c08ea263323ce2d8a058b6cc8fb
parent
009c5f53
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
114 deletions
+118
-114
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockLineString.java
...entor/client/editor/simple/components/MockLineString.java
+1
-28
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMapFeatureBase.java
...r/client/editor/simple/components/MockMapFeatureBase.java
+64
-0
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMapFeatureBaseWithFill.java
.../editor/simple/components/MockMapFeatureBaseWithFill.java
+19
-0
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMarker.java
...pinventor/client/editor/simple/components/MockMarker.java
+33
-58
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockPolygon.java
...inventor/client/editor/simple/components/MockPolygon.java
+1
-28
No files found.
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockLineString.java
View file @
77150161
...
...
@@ -32,35 +32,8 @@ public class MockLineString extends MockMapFeatureBase {
static
MockLineString
fromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
,
JavaScriptObject
layer
)
{
MockLineString
line
=
new
MockLineString
(
parent
.
editor
);
line
.
feature
=
layer
;
String
name
=
null
;
for
(
String
key
:
properties
.
keySet
())
{
String
value
;
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKEWIDTH
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKEWIDTH
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
line
.
changeProperty
(
PROPERTY_NAME_STROKEWIDTH
,
value
);
line
.
onPropertyChange
(
PROPERTY_NAME_STROKEWIDTH
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKECOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
line
.
changeProperty
(
PROPERTY_NAME_STROKECOLOR
,
value
);
line
.
onPropertyChange
(
PROPERTY_NAME_STROKECOLOR
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_TITLE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
line
.
changeProperty
(
PROPERTY_NAME_TITLE
,
value
);
line
.
onPropertyChange
(
PROPERTY_NAME_TITLE
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_DESCRIPTION
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
line
.
changeProperty
(
PROPERTY_NAME_DESCRIPTION
,
value
);
line
.
onPropertyChange
(
PROPERTY_NAME_DESCRIPTION
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_NAME
))
{
name
=
properties
.
get
(
key
).
isString
().
stringValue
();
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_VISIBLE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
line
.
changeProperty
(
PROPERTY_NAME_VISIBLE
,
value
);
line
.
onPropertyChange
(
PROPERTY_NAME_VISIBLE
,
value
);
}
}
processFeatureName
(
line
,
parent
,
name
);
line
.
preserveLayerData
();
line
.
processFromGeoJSON
(
parent
,
properties
);
return
line
;
}
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMapFeatureBase.java
View file @
77150161
...
...
@@ -8,6 +8,8 @@ package com.google.appinventor.client.editor.simple.components;
import
com.google.appinventor.client.ComponentsTranslation
;
import
com.google.appinventor.client.editor.simple.SimpleEditor
;
import
com.google.gwt.core.client.JavaScriptObject
;
import
com.google.gwt.json.client.JSONObject
;
import
com.google.gwt.json.client.JSONValue
;
import
com.google.gwt.resources.client.ImageResource
;
import
com.google.gwt.user.client.Event
;
import
com.google.gwt.user.client.ui.SimplePanel
;
...
...
@@ -24,6 +26,8 @@ public abstract class MockMapFeatureBase extends MockVisibleComponent implements
public
static
final
String
PROPERTY_NAME_TITLE
=
"Title"
;
public
static
final
String
CSS_PROPERTY_STROKEWIDTH
=
"stroke-width"
;
public
static
final
String
CSS_PROPERTY_STROKE
=
"stroke"
;
public
static
final
String
DEFAULT_STROKE_WIDTH
=
"1"
;
public
static
final
String
DEFAULT_STROKE_COLOR
=
"&HFF000000"
;
protected
final
SimplePanel
panel
;
protected
MockMap
map
=
null
;
...
...
@@ -154,6 +158,66 @@ public abstract class MockMapFeatureBase extends MockVisibleComponent implements
}
}
/**
* Process the information from the feature's GeoJSON properties field. Subclasses may override
* this function to set default values, but _must_ call super.processFromGeoJSON() otherwise
* properties defined in superclasses will not get set.
*
* @param parent the mock feature collection that will contain the feature
* @param properties the properties object from the GeoJSON
*/
protected
void
processFromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
)
{
setStrokeWidthProperty
(
DEFAULT_STROKE_COLOR
);
setStrokeColorProperty
(
DEFAULT_STROKE_WIDTH
);
String
name
=
null
;
for
(
String
key
:
properties
.
keySet
())
{
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_NAME
))
{
name
=
properties
.
get
(
key
).
isString
().
stringValue
();
}
else
{
processPropertyFromGeoJSON
(
key
,
properties
.
get
(
key
));
}
}
processFeatureName
(
this
,
parent
,
name
);
// Use the name as the title if the properties did not include one (issue #1425)
if
(
getPropertyValue
(
PROPERTY_NAME_TITLE
).
isEmpty
())
{
changeProperty
(
PROPERTY_NAME_TITLE
,
getPropertyValue
(
PROPERTY_NAME_NAME
));
}
}
/**
* Process a key-value pair from the feature's GeoJSON properties field. Subclasses may override
* this function to process properties specific to their implementation, but _must_ call
* super.processPropertyFromGeoJSON() otherwise properties defined in superclasses will not
* get set.
* @param key a JSON key from the GeoJSON properties
* @param value the corresponding value for <code>key</code> in the properties
*/
protected
void
processPropertyFromGeoJSON
(
String
key
,
JSONValue
value
)
{
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKEWIDTH
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKEWIDTH
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_STROKEWIDTH
,
v
);
onPropertyChange
(
PROPERTY_NAME_STROKEWIDTH
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKECOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKE
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_STROKECOLOR
,
v
);
onPropertyChange
(
PROPERTY_NAME_STROKECOLOR
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_VISIBLE
))
{
String
v
=
value
.
toString
().
equalsIgnoreCase
(
"false"
)
?
"False"
:
"True"
;
changeProperty
(
PROPERTY_NAME_VISIBLE
,
v
);
onPropertyChange
(
PROPERTY_NAME_VISIBLE
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_TITLE
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_TITLE
,
v
);
onPropertyChange
(
PROPERTY_NAME_TITLE
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_DESCRIPTION
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_DESCRIPTION
,
v
);
onPropertyChange
(
PROPERTY_NAME_DESCRIPTION
,
v
);
}
}
// JSNI Methods
public
static
native
double
distanceBetweenPoints
(
JavaScriptObject
map
,
MockMap
.
LatLng
point1
,
MockMap
.
LatLng
point2
)
/*-{
var pt1 = [point1.@com.google.appinventor.client.editor.simple.components.MockMap.LatLng::latitude,
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMapFeatureBaseWithFill.java
View file @
77150161
...
...
@@ -6,12 +6,15 @@
package
com.google.appinventor.client.editor.simple.components
;
import
com.google.appinventor.client.editor.simple.SimpleEditor
;
import
com.google.gwt.json.client.JSONObject
;
import
com.google.gwt.json.client.JSONValue
;
import
com.google.gwt.resources.client.ImageResource
;
import
com.google.gwt.widgetideas.graphics.client.Color
;
public
abstract
class
MockMapFeatureBaseWithFill
extends
MockMapFeatureBase
{
public
static
final
String
PROPERTY_NAME_FILLCOLOR
=
"FillColor"
;
public
static
final
String
CSS_PROPERTY_FILL
=
"fill"
;
public
static
final
String
DEFAULT_FILL_COLOR
=
"&HFF448800"
;
protected
String
fillColor
=
"#FF0000"
;
...
...
@@ -37,6 +40,22 @@ public abstract class MockMapFeatureBaseWithFill extends MockMapFeatureBase {
setFillColor
(
fillColor
);
}
protected
void
processFromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
)
{
changeProperty
(
PROPERTY_NAME_FILLCOLOR
,
DEFAULT_FILL_COLOR
);
super
.
processFromGeoJSON
(
parent
,
properties
);
}
protected
void
processPropertyFromGeoJSON
(
String
key
,
JSONValue
value
)
{
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_FILLCOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_FILL
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_FILLCOLOR
,
v
);
onPropertyChange
(
PROPERTY_NAME_FILLCOLOR
,
v
);
}
else
{
super
.
processPropertyFromGeoJSON
(
key
,
value
);
}
}
protected
native
void
setFillColor
(
String
color
)
/*-{
var feature = this.@com.google.appinventor.client.editor.simple.components.MockMapFeatureBase::feature;
if (feature) {
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockMarker.java
View file @
77150161
...
...
@@ -8,7 +8,6 @@ package com.google.appinventor.client.editor.simple.components;
import
java.util.Collections
;
import
java.util.List
;
import
com.google.appinventor.client.ComponentsTranslation
;
import
com.google.appinventor.client.Ode
;
import
com.google.appinventor.client.editor.simple.SimpleEditor
;
import
com.google.appinventor.client.output.OdeLog
;
...
...
@@ -18,6 +17,7 @@ import com.google.appinventor.shared.rpc.project.FileDescriptorWithContent;
import
com.google.gwt.core.client.JavaScriptObject
;
import
com.google.gwt.core.shared.GWT
;
import
com.google.gwt.json.client.JSONObject
;
import
com.google.gwt.json.client.JSONValue
;
import
com.google.gwt.user.client.Event
;
import
com.google.gwt.user.client.rpc.AsyncCallback
;
import
com.google.gwt.user.client.ui.Image
;
...
...
@@ -53,67 +53,42 @@ public class MockMarker extends MockMapFeatureBaseWithFill {
static
MockMarker
fromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
,
JavaScriptObject
layer
)
{
MockMarker
marker
=
new
MockMarker
(
parent
.
editor
);
marker
.
feature
=
layer
;
String
name
=
null
;
boolean
hadImageAsset
=
false
;
for
(
String
key
:
properties
.
keySet
())
{
String
value
;
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKEWIDTH
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKEWIDTH
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_STROKEWIDTH
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_STROKEWIDTH
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKECOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_STROKECOLOR
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_STROKECOLOR
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_FILLCOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_FILL
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_FILLCOLOR
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_FILLCOLOR
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_ANCHORHORIZONTAL
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_ANCHORHORIZONTAL
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_ANCHORHORIZONTAL
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_ANCHORVERTICAL
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_ANCHORVERTICAL
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_ANCHORVERTICAL
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_WIDTH
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_WIDTH
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_WIDTH
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_HEIGHT
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_HEIGHT
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_HEIGHT
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_NAME
))
{
name
=
properties
.
get
(
key
).
isString
().
stringValue
();
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_IMAGE_ASSET
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_IMAGE_ASSET
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_IMAGE_ASSET
,
value
);
hadImageAsset
=
true
;
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_VISIBLE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_VISIBLE
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_VISIBLE
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_TITLE
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_TITLE
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_TITLE
,
value
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_DESCRIPTION
))
{
value
=
properties
.
get
(
key
).
isString
().
stringValue
();
marker
.
changeProperty
(
PROPERTY_NAME_DESCRIPTION
,
value
);
marker
.
onPropertyChange
(
PROPERTY_NAME_DESCRIPTION
,
value
);
}
}
processFeatureName
(
marker
,
parent
,
name
);
if
(!
hadImageAsset
)
{
marker
.
setImageAsset
(
null
);
}
marker
.
preserveLayerData
();
marker
.
processFromGeoJSON
(
parent
,
properties
);
return
marker
;
}
protected
void
processFromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
)
{
setImageAsset
(
null
);
super
.
processFromGeoJSON
(
parent
,
properties
);
}
protected
void
processPropertyFromGeoJSON
(
String
key
,
JSONValue
value
)
{
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_ANCHORHORIZONTAL
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_ANCHORHORIZONTAL
,
v
);
onPropertyChange
(
PROPERTY_NAME_ANCHORHORIZONTAL
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_ANCHORVERTICAL
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_ANCHORVERTICAL
,
v
);
onPropertyChange
(
PROPERTY_NAME_ANCHORVERTICAL
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_HEIGHT
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_HEIGHT
,
v
);
onPropertyChange
(
PROPERTY_NAME_HEIGHT
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_WIDTH
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_WIDTH
,
v
);
onPropertyChange
(
PROPERTY_NAME_WIDTH
,
v
);
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_IMAGE_ASSET
))
{
String
v
=
value
.
isString
().
stringValue
();
changeProperty
(
PROPERTY_NAME_IMAGE_ASSET
,
v
);
onPropertyChange
(
PROPERTY_NAME_IMAGE_ASSET
,
v
);
}
else
{
super
.
processPropertyFromGeoJSON
(
key
,
value
);
}
}
@Override
public
void
addToMap
(
MockMap
map
)
{
if
(
panel
.
getWidget
()
!=
null
)
{
...
...
appinventor/appengine/src/com/google/appinventor/client/editor/simple/components/MockPolygon.java
View file @
77150161
...
...
@@ -34,35 +34,8 @@ public class MockPolygon extends MockPolygonBase {
static
MockPolygon
fromGeoJSON
(
MockFeatureCollection
parent
,
JSONObject
properties
,
JavaScriptObject
layer
)
{
MockPolygon
polygon
=
new
MockPolygon
(
parent
.
editor
);
polygon
.
feature
=
layer
;
String
name
=
null
;
boolean
hadFillColor
=
false
,
hadStrokeColor
=
false
,
hadStrokeWidth
=
false
;
for
(
String
key
:
properties
.
keySet
())
{
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKEWIDTH
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKEWIDTH
))
{
polygon
.
setStrokeWidthProperty
(
properties
.
get
(
key
).
isString
().
stringValue
());
hadStrokeWidth
=
true
;
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_STROKECOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_STROKE
))
{
polygon
.
setStrokeColorProperty
(
properties
.
get
(
key
).
isString
().
stringValue
());
hadStrokeColor
=
true
;
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_FILLCOLOR
)
||
key
.
equalsIgnoreCase
(
CSS_PROPERTY_FILL
))
{
polygon
.
getProperties
().
changePropertyValue
(
PROPERTY_NAME_FILLCOLOR
,
properties
.
get
(
key
).
isString
().
stringValue
());
hadFillColor
=
true
;
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_NAME
))
{
name
=
properties
.
get
(
key
).
isString
().
stringValue
();
}
else
if
(
key
.
equalsIgnoreCase
(
PROPERTY_NAME_VISIBLE
))
{
polygon
.
setVisibleProperty
(
properties
.
get
(
key
).
isString
().
stringValue
());
}
}
if
(!
hadFillColor
)
{
polygon
.
getProperties
().
changePropertyValue
(
PROPERTY_NAME_FILLCOLOR
,
"&HFF448800"
);
}
if
(!
hadStrokeColor
)
{
polygon
.
getProperties
().
changePropertyValue
(
PROPERTY_NAME_STROKECOLOR
,
"&HFF000000"
);
}
if
(!
hadStrokeWidth
)
{
polygon
.
getProperties
().
changePropertyValue
(
PROPERTY_NAME_STROKEWIDTH
,
"1"
);
}
processFeatureName
(
polygon
,
parent
,
name
);
polygon
.
preserveLayerData
();
polygon
.
processFromGeoJSON
(
parent
,
properties
);
return
polygon
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment