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

Vector layer conversion #33

Merged
merged 2 commits into from
Sep 18, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion examples/vectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<body>
<div id="map2d" style="width:600px;height:400px;float:left;"></div>
<div id="map3d" style="width:600px;height:400px;float:left;position:relative;"></div>
<div><input type="button" value="Enable/disable"
<div><input type="button" value="Enable/disable Cesium"
onclick="javascript:ol3d.setEnabled(!ol3d.getEnabled())" /></div>
<div><input type="button" value="Enable/disable depth test"
onclick="javascript:scene.globe.depthTestAgainstTerrain = !scene.globe.depthTestAgainstTerrain" /></div>
<script src="../ol3/build/ol.js"></script>
<script src="../cesium/Build/Cesium/Cesium.js"></script>
<script src="/@loader"></script>
Expand Down
63 changes: 41 additions & 22 deletions examples/vectors.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([700000, 200000]),
name: 'Null Island',
population: 4000,
rainfall: 500
geometry: new ol.geom.Point([700000, 200000]),
name: 'Null Island',
population: 4000,
rainfall: 500
});

var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'data/icon.png'
})),
text: new ol.style.Text({
text: 'Icon',
font: 'italic'
})
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'data/icon.png'
})),
text: new ol.style.Text({
text: 'Icon',
font: 'italic'
})
});

iconFeature.setStyle(iconStyle);
Expand Down Expand Up @@ -138,7 +138,22 @@ var vectorSource = new ol.source.GeoJSON(
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [[4e6, -2e6], [8e6, 2e6]]
'coordinates': [
[1e5, 1e5, 1],
[2e5, 2e5, 100000],
[3e5, 3e5, 1000],
[4e5, 4e5, 100000],
[5e5, 5e5, 100],
[6e5, 6e5, 100000],
[7e5, 7e5, 1]
]
}
},
{
'type': 'Feature',
'geometry': {
'type': 'LineString',
'coordinates': [[4e6, -2e6, 100000], [8e6, 2e6, 200000]]
}
},
{
Expand Down Expand Up @@ -222,11 +237,11 @@ var vectorLayer = new ol.layer.Vector({


var vectorSource2 = new ol.source.Vector({
features: [iconFeature]
features: [iconFeature]
});

var vectorLayer2 = new ol.layer.Vector({
source: vectorSource2
source: vectorSource2
});

var dragAndDropInteraction = new ol.interaction.DragAndDrop({
Expand All @@ -245,7 +260,10 @@ var map = new ol.Map({
interactions: ol.interaction.defaults().extend([dragAndDropInteraction]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
source: new ol.source.BingMaps({
key: 'Ak-dzM4wZjSqTlzveKz5u0d4IQ4bRzVI309GxmkgSVr1ewS6iPSrOvOKhA-CJlm3',
imagerySet: 'Aerial'
})
}),
vectorLayer,
vectorLayer2
Expand Down Expand Up @@ -283,19 +301,20 @@ var terrainProvider = new Cesium.CesiumTerrainProvider({
url: '//cesiumjs.org/stk-terrain/tilesets/world/tiles'
});
scene.terrainProvider = terrainProvider;
scene.globe.depthTestAgainstTerrain = true;
ol3d.setEnabled(true);

setTimeout(function() {
map.getLayers().removeAt(1);
map.getLayers().remove(vectorLayer);
setTimeout(function() {
map.getLayers().insertAt(1, vectorLayer);
}, 3000);
}, 8000);

var csLabels = new Cesium.LabelCollection();
csLabels.add({
position: Cesium.Cartesian3.fromRadians(20, 20, 0),
text: 'Pre-existing primitive'
position: Cesium.Cartesian3.fromRadians(20, 20, 0),
text: 'Pre-existing primitive'
});
scene.primitives.add(csLabels);

40 changes: 27 additions & 13 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,21 +505,35 @@ goog.require('olcs.core.OLImageryProvider');
goog.asserts.assert(geometry.getType() == 'Point');
geometry = olGeometryCloneTo4326(geometry, projection);

var image = style.getImage().getImage();
var imageStyle = style.getImage();
var image = imageStyle.getImage();
var isImageLoaded = function(image) {
return image.src != '' &&
image.naturalHeight != 0 &&
image.naturalWidth != 0 &&
image.complete;
};
goog.asserts.assert(image);
if (image instanceof Image)
goog.asserts.assert(image.complete); // converter is stateless
var color = extractColorFromOlStyle(style, false);
var position = olcs.core.ol4326CoordinateToCesiumCartesian(
ol.extent.getCenter(geometry.getExtent()));

var billboards = new Cesium.BillboardCollection();
billboards.add({
// always update Cesium externs before adding a property
image: image,
color: color,
position: position
});
var reallyCreateBillboard = function() {
var center = ol.extent.getCenter(geometry.getExtent());
var position = olcs.core.ol4326CoordinateToCesiumCartesian(center);
billboards.add({
// always update Cesium externs before adding a property
image: image,
position: position
});
};
if (image instanceof Image && !isImageLoaded(image)) {
// Cesium requires the image to be loaded
var listener = function() {
reallyCreateBillboard();
};

goog.events.listenOnce(image, 'load', listener);
} else {
reallyCreateBillboard();
}

return addTextStyle(geometry, style, billboards);
};
Expand Down