Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mappable attribution #5167

Merged
merged 5 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Change Log
* Added support for shapefile with `ShapefileCatalogItem`
* Added `GeoJsonMixin` for handling the loading of geojson data.
* Extended the `GeoJsonCatalogItem` to support loading of zip files.
* *Adde `AttributionTraits` to mappable and send it as property when creating Cesium's data sources and imagery providers. [#5167](https://github.com/TerriaJS/terriajs/pull/5167)
* [The next improvement]

#### 8.0.0-alpha.65
Expand Down
15 changes: 13 additions & 2 deletions lib/Map/MapboxVectorTileImageryProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface MapboxVectorTileImageryProviderOptions {
featureInfoFunc?: (
feature: VectorTileFeature
) => ImageryLayerFeatureInfo | undefined;
credit?: Credit | string;
}

export default class MapboxVectorTileImageryProvider
Expand All @@ -72,6 +73,7 @@ export default class MapboxVectorTileImageryProvider
) => ImageryLayerFeatureInfo | undefined;
private readonly _errorEvent = new CesiumEvent();
private readonly _ready = true;
private readonly _credit?: Credit | string;

constructor(options: MapboxVectorTileImageryProviderOptions) {
this._uriTemplate = new URITemplate(options.url);
Expand Down Expand Up @@ -126,6 +128,8 @@ export default class MapboxVectorTileImageryProvider
this._errorEvent = new CesiumEvent();

this._ready = true;

this._credit = options.credit;
}

get url() {
Expand Down Expand Up @@ -177,7 +181,13 @@ export default class MapboxVectorTileImageryProvider
}

get credit(): Credit {
return <any>undefined;
let credit = this._credit;
if (credit === undefined) {
return <any>undefined;
} else if (typeof credit === "string") {
credit = new Credit(credit);
}
return credit;
}

get defaultAlpha(): number {
Expand Down Expand Up @@ -527,7 +537,8 @@ export default class MapboxVectorTileImageryProvider
maximumNativeZoom: this._maximumNativeLevel,
maximumZoom: this._maximumLevel,
uniqueIdProp: this._uniqueIdProp,
styleFunc: styleFunc
styleFunc: styleFunc,
credit: ""
});
imageryProvider.pickFeatures = function() {
return Promise.resolve([]);
Expand Down
3 changes: 2 additions & 1 deletion lib/ModelMixins/GeojsonMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ export default function GeoJsonMixin<
clampToGround: this.clampToGround,
markerUrl: style["marker-url"] // not in SimpleStyle spec but gives an alternate to maki marker symbols
? proxyCatalogItemUrl(this, style["marker-url"])
: undefined
: undefined,
credit: this.attribution
};

if (isDefined(style["stroke-opacity"])) {
Expand Down
5 changes: 5 additions & 0 deletions lib/Models/ArcGisFeatureServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ class FeatureServerStratum extends LoadableStratum(
"clampToGround",
item.clampToGround
);
geoJsonItem.setTrait(
CommonStrata.definition,
"attribution",
item.attribution
);
let tempEsriJson: any = null;
return Promise.resolve()
.then(() => loadGeoJson(item))
Expand Down
3 changes: 2 additions & 1 deletion lib/Models/ArcGisMapServerCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,8 @@ export default class ArcGisMapServerCatalogItem
enablePickFeatures: this.allowFeaturePicking,
usePreCachedTilesIfAvailable: !dynamicRequired,
mapServerData: stratum.mapServerData,
token: stratum.token
token: stratum.token,
credit: this.attribution
});

const maximumLevelBeforeMessage = maximumScaleToLevel(
Expand Down
12 changes: 6 additions & 6 deletions lib/Models/ArcGisTerrainCatalogItem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { computed } from "mobx";
import ArcGISTiledElevationTerrainProvider from "terriajs-cesium/Source/Core/ArcGISTiledElevationTerrainProvider";
import IonResource from "terriajs-cesium/Source/Core/IonResource";
import Credit from "terriajs-cesium/Source/Core/Credit";
import AsyncMappableMixin from "../ModelMixins/AsyncMappableMixin";
import CatalogMemberMixin from "../ModelMixins/CatalogMemberMixin";
import UrlMixin from "../ModelMixins/UrlMixin";
Expand Down Expand Up @@ -32,10 +32,10 @@ export default class ArcGisTerrainCatalogItem
@computed
get mapItems() {
if (this.url === undefined) return [];
return [
new ArcGISTiledElevationTerrainProvider({
url: this.url
})
];
const item = new ArcGISTiledElevationTerrainProvider({
url: this.url
});
if (this.attribution) item.credit = new Credit(this.attribution);
return [];
}
}
12 changes: 8 additions & 4 deletions lib/Models/BingMapsCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ export default class BingMapsCatalogItem
key: this.key!
});

// open in a new window
(<any>result)._credit = new Credit(
'<a href="http://www.bing.com" target="_blank">Bing</a>'
);
if (this.attribution) {
(<any>result)._credit = this.attribution;
} else {
// open in a new window
(<any>result)._credit = new Credit(
'<a href="http://www.bing.com" target="_blank">Bing</a>'
);
}
result.defaultGamma = 1.0;

return result;
Expand Down
3 changes: 2 additions & 1 deletion lib/Models/CesiumTerrainCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export default class CesiumTerrainCatalogItem

return [
new CesiumTerrainProvider({
url: resource
url: resource,
credit: this.attribution
})
];
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/CzmlCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class CzmlCatalogItem
}
})
.then(czmlLoadInput => {
return CzmlDataSource.load(czmlLoadInput);
return CzmlDataSource.load(czmlLoadInput, { credit: this.attribution });
})
.then(czml => {
this._dataSource = czml;
Expand Down
5 changes: 5 additions & 0 deletions lib/Models/GeoRssCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class GeoRssStratum extends LoadableStratum(GeoRssCatalogItemTraits) {
"clampToGround",
item.clampToGround
);
geoJsonItem.setTrait(
CommonStrata.definition,
"attribution",
item.attribution
);
const feed: any = {};
return Promise.resolve()
.then(() => loadGeoRss(item))
Expand Down
5 changes: 5 additions & 0 deletions lib/Models/GpxCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class GpxCatalogItem extends AsyncMappableMixin(
"geoJsonData",
geoJsonData
);
this._geoJsonItem.setTrait(
CommonStrata.definition,
"attribution",
this.attribution
);
return this._geoJsonItem.loadMapItems();
});
}
Expand Down
9 changes: 6 additions & 3 deletions lib/Models/IonImageryCatalogItem.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { computed } from "mobx";
import IonImageryProvider from "terriajs-cesium/Source/Scene/IonImageryProvider";
import isDefined from "../Core/isDefined";
import IonImageryCatalogItemTraits from "../Traits/IonImageryCatalogItemTraits";
import CreateModel from "./CreateModel";
import Mappable from "./Mappable";
import isDefined from "../Core/isDefined";
import { result } from "lodash-es";

export default class IonImageryCatalogItem
extends CreateModel(IonImageryCatalogItemTraits)
Expand All @@ -30,11 +29,15 @@ export default class IonImageryCatalogItem

@computed get imageryProvider() {
if (isDefined(this.ionAssetId)) {
return new IonImageryProvider({
const provider = new IonImageryProvider({
assetId: this.ionAssetId,
accessToken: this.ionAccessToken,
server: this.ionServer
});
if (this.attribution) {
(<any>provider)._credit = this.attribution;
}
return provider;
}
}
}
3 changes: 2 additions & 1 deletion lib/Models/MapboxVectorTileCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ class MapboxVectorTileCatalogItem extends AsyncMappableMixin(
maximumNativeZoom: this.maximumNativeZoom,
maximumZoom: this.maximumZoom,
uniqueIdProp: this.idProperty,
featureInfoFunc: this.featureInfoFromFeature
featureInfoFunc: this.featureInfoFromFeature,
credit: this.attribution
});
}

Expand Down
3 changes: 2 additions & 1 deletion lib/Models/WebMapServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,8 @@ class WebMapServiceCatalogItem
},
tilingScheme: /*defined(this.tilingScheme) ? this.tilingScheme :*/ new WebMercatorTilingScheme(),
maximumLevel: maximumLevel,
rectangle: rectangle
rectangle: rectangle,
credit: this.attribution
};

if (
Expand Down
3 changes: 2 additions & 1 deletion lib/Models/WebMapTileServiceCatalogItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,8 @@ class WebMapTileServiceCatalogItem extends AsyncMappableMixin(
tileHeight: tileMatrixSet.tileHeight,
tilingScheme: new WebMercatorTilingScheme(),
format,
rectangle
rectangle,
credit: this.attribution
});
return imageryProvider;
}
Expand Down
11 changes: 11 additions & 0 deletions lib/Traits/AttributionTraits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ModelTraits from "./ModelTraits";
import primitiveTrait from "./primitiveTrait";

export default class AttributionTraits extends ModelTraits {
@primitiveTrait({
name: "Attribution",
description: "The attribution to display with the data.",
type: "string"
})
attribution?: string;
}
10 changes: 5 additions & 5 deletions lib/Traits/BingMapsCatalogItemTraits.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import primitiveTrait from "./primitiveTrait";
import mixTraits from "./mixTraits";
import RasterLayerTraits from "./RasterLayerTraits";
import MappableTraits from "./MappableTraits";
import BingMapsStyle from "terriajs-cesium/Source/Scene/BingMapsStyle";
import CatalogMemberTraits from "./CatalogMemberTraits";
import LayerOrderingTraits from "./LayerOrderingTraits";
import BingMapsStyle from "terriajs-cesium/Source/Scene/BingMapsStyle";
import MappableTraits from "./MappableTraits";
import mixTraits from "./mixTraits";
import primitiveTrait from "./primitiveTrait";
import RasterLayerTraits from "./RasterLayerTraits";

export default class BingMapsCatalogItemTraits extends mixTraits(
LayerOrderingTraits,
Expand Down
7 changes: 0 additions & 7 deletions lib/Traits/CartoMapCatalogItemTraits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,4 @@ export default class CartoMapCatalogItemTraits extends mixTraits(
type: "number"
})
maximumLevel = 25;

@primitiveTrait({
name: "Attribution",
description: "The attribution to display with the data.",
type: "string"
})
attribution?: string;
}
10 changes: 7 additions & 3 deletions lib/Traits/MappableTraits.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import ShowableTraits from "./ShowableTraits";
import AttributionTraits from "./AttributionTraits";
import mixTraits from "./mixTraits";
import ModelTraits from "./ModelTraits";
import objectTrait from "./objectTrait";
import primitiveTrait from "./primitiveTrait";
import mixTraits from "./mixTraits";
import ShowableTraits from "./ShowableTraits";

export class RectangleTraits extends ModelTraits {
@primitiveTrait({
Expand Down Expand Up @@ -34,7 +35,10 @@ export class RectangleTraits extends ModelTraits {
north?: number;
}

export default class MappableTraits extends mixTraits(ShowableTraits) {
export default class MappableTraits extends mixTraits(
ShowableTraits,
AttributionTraits
) {
@objectTrait({
type: RectangleTraits,
name: "Rectangle",
Expand Down
15 changes: 4 additions & 11 deletions lib/Traits/OpenStreetMapCatalogItemTraits.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import mixTraits from "./mixTraits";
import CatalogMemberTraits from "./CatalogMemberTraits";
import UrlTraits from "./UrlTraits";
import MappableTraits from "./MappableTraits";
import RasterLayerTraits from "./RasterLayerTraits";
import primitiveTrait from "./primitiveTrait";
import mixTraits from "./mixTraits";
import primitiveArrayTrait from "./primitiveArrayTrait";
import primitiveTrait from "./primitiveTrait";
import RasterLayerTraits from "./RasterLayerTraits";
import UrlTraits from "./UrlTraits";

export default class OpenStreetMapCatalogItemTraits extends mixTraits(
RasterLayerTraits,
Expand All @@ -27,13 +27,6 @@ export default class OpenStreetMapCatalogItemTraits extends mixTraits(
})
subdomains: string[] = [];

@primitiveTrait({
name: "Attribution",
description: "The attribution to display with the data.",
type: "string"
})
attribution?: string;

@primitiveTrait({
name: "Maximum Level",
description: "The maximum level of details to fetch",
Expand Down