Merge pull request #95 from NASAWorldWind/bug/kml-style-resolving

Apply highlight attributes to the shapes.
This commit is contained in:
Yann Voumard 2017-03-31 09:54:54 +02:00 committed by GitHub
commit d42415ca7a
8 changed files with 29 additions and 9 deletions

View File

@ -103,6 +103,16 @@
]]></text>
</BalloonStyle>
</Style>
<StyleMap id="styleWithHighlight">
<Pair>
<key>normal</key>
<styleUrl>#downArrowIcon</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#globeIcon</styleUrl>
</Pair>
</StyleMap>
<Folder>
<name>Placemarks</name>
<visibility>1</visibility>
@ -139,7 +149,7 @@
<tilt>40.5575073395506</tilt>
<range>500.6566641072245</range>
</LookAt>
<styleUrl>#downArrowIcon</styleUrl>
<styleUrl>#styleWithHighlight</styleUrl>
<Point>
<altitudeMode>relativeToGround</altitudeMode>
<coordinates>-122.084075,37.4220033612141,50</coordinates>

View File

@ -173,9 +173,9 @@ define([
}
if (style.nodeName == KmlStyle.prototype.getTagNames()[0]) {
resolve(new KmlStyle({objectNode: style}));
resolve(new KmlStyle({objectNode: style}, {styleResolver: self._styleResolver}));
} else if (style.nodeName == KmlStyleMap.prototype.getTagNames()[0]) {
resolve(new KmlStyleMap({objectNode: style}));
resolve(new KmlStyleMap({objectNode: style}, {styleResolver: self._styleResolver}));
} else {
Logger.logMessage(Logger.LEVEL_WARNING, "KmlFile", "resolveStyle", "Style must contain either" +
" Style node or StyleMap node.");

View File

@ -80,6 +80,9 @@ define([
false,
this.prepareAttributes(kmlOptions.lastStyle.normal)
);
if(kmlOptions.lastStyle.highlight) {
this._renderable.highlightAttributes = this.prepareAttributes(kmlOptions.lastStyle.highlight);
}
this.moveValidProperties();
dc.redrawRequested = true;
}

View File

@ -125,6 +125,9 @@ define([
*/
KmlLineString.prototype.createPath = function (styles) {
this._renderable = new Path(this.prepareLocations(), this.prepareAttributes(styles.normal));
if(styles.highlight) {
this._renderable.highlightAttributes = this.prepareAttributes(styles.highlight);
}
this.moveValidProperties();
};

View File

@ -127,6 +127,9 @@ define([
*/
KmlPolygon.prototype.createPolygon = function(styles) {
this._renderable = new Polygon(this.prepareLocations(), this.prepareAttributes(styles.normal));
if(styles.highlight) {
this._renderable.highlightAttributes = this.prepareAttributes(styles.highlight);
}
this.moveValidProperties();
};

View File

@ -59,7 +59,7 @@ define([
* Resolve the information from style map and create the options with normal and highlight.
* @param resolve Callback to be called when all promises are resolved with correct style.
*/
KmlStyleMap.prototype.resolve = function(resolve) {
KmlStyleMap.prototype.resolve = function(resolve, styleResolver) {
// Create promise which resolves, when all styles are resolved.
var self = this;
var results = {};
@ -67,7 +67,7 @@ define([
var pairs = self.kmlPairs;
pairs.forEach(function(pair) {
var key = pair.kmlKey;
var style = pair.getStyle();
var style = pair.getStyle(styleResolver);
promises.push(style);
style.then(function(pStyle){
results[key] = pStyle.normal;

View File

@ -87,11 +87,11 @@ define([
/**
* @inheritDoc
*/
Pair.prototype.getStyle = function() {
Pair.prototype.getStyle = function(styleResolver) {
var self = this;
return new Promise(function (resolve, reject) {
window.setTimeout(function(){
StyleResolver.handleRemoteStyle(self.kmlStyleUrl, self.kmlStyleSelector, resolve, reject);
styleResolver.handleRemoteStyle(self.kmlStyleUrl, self.kmlStyleSelector, resolve, reject);
},0);
});
};

View File

@ -37,11 +37,12 @@ define([
// Intentionally undocumented. For internal use only
StyleResolver.prototype.handleStyleUrl = function (styleUrl, resolve, reject, filePromise) {
var self = this;
filePromise = this.handlePromiseOfFile(styleUrl, filePromise);
filePromise.then(function (kmlFile) {
kmlFile.resolveStyle(styleUrl).then(function (style) {
if (style.isMap) {
style.resolve(resolve, reject);
style.resolve(resolve, self);
} else {
resolve({normal: style, highlight: null});
}
@ -65,7 +66,7 @@ define([
// Intentionally undocumented. For internal use only
StyleResolver.prototype.handleStyleSelector = function (styleSelector, resolve, reject) {
if (styleSelector.isMap) {
styleSelector.resolve(resolve, reject);
styleSelector.resolve(resolve, this);
} else {
// Move this resolve to the end of the stack to prevent recursion.
window.setTimeout(function () {