I want to represent 3D models in Google Earth environmente with API and Google Plugin.
I have the code:
var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCB, failureCB);
}
function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_HIDE);
// Placemark
var placemark = ge.createPlacemark('Modello1');
placemark.setName('model');
var place2 = ge.createPlacemark('Modello2');
place2.setName('modello2');
// Placemark/Model (geometry)
var model = ge.createModel('Mod1');
placemark.setGeometry(model);
var modello2 = ge.createModel('Mod2');
place2.setGeometry(modello2);
// Placemark/Model/Link
var link = ge.createLink('File1');
link.setHref("http://myhost.org/table2/models/table2.dae");
model.setLink(link);
var link2 = ge.createLink('File2');
link2.setHref("http://myhost.org/tavolo/models/table2.dae");
modello2.setLink(link2);
// get center look at location
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// Placemark/Model/Location
var loc = ge.createLocation('');
loc.setLatitude(40.01000594412381);
loc.setLongitude(-105.2727379358738);
model.setLocation(loc);
//slightly varying coordinates...
var loc2 = ge.createLocation('');
loc2.setLatitude(40.01000594412389);
loc2.setLongitude(-105.2727379358731);
modello2.setLocation(loc2);
// add the model placemark to Earth
ge.getFeatures().appendChild(placemark);
ge.getFeatures().appendChild(place2);
// zoom into the model
lookAt.setLatitude(40.01000594412381);
lookAt.setLongitude(-105.2727379358738);
lookAt.setRange(300);
lookAt.setTilt(80);
ge.getView().setAbstractView(lookAt);
}
function failureCB(errorCode) {
}
google.setOnLoadCallback(init);
When i load different collada (.dae) files no problems appear... but it doesn't load the same Table 2 times! Why?!?
I have also tried to separate instances and files... but problem persists. I have only one table on my environment.
Is there a method to clone single model into N models ?
have you tried injecting kml t display the models using parse kml.
also try using getKml to get the kml and see if it renders properly in a stand alone kml file
Related
I'm having an issue with my Google Maps API, which I'm using withing a Flex application.
Periodically, I have to refresh it 5 or 6 times to get the map to display properly. Otherwise, I get one marker in the upper left corner and the map is greyed out. I don't even get an error message so I'm not sure what to trouble shoot.
I suspect it may have something to do with it triggering the onMapReady(event) as the map is being generated, but I don't know how to set up some type of timed listener in Flex. (I have Googled this but have only found instances in JavaScript or Jquery to do so.)
Can someone give me a tip on how to check for the maps being in an idle state using ActionScript/Flex? I think if I can get that part, I can remove the mapevent_mapready="onMapReady(event)" and just make the onMapReady(event) function run when the map is idle...or something like that. I've seen it for JavaScript but of course that won't directly work in AS and I don't know enough of either to make a proper translation.
Here's my code:
public function onMapReady(event:MapEvent):void {
var dojoGeo:Array = geoSchoolInfoAry;
var md:MarkerData = new MarkerData(dojoGeo[0],dojoGeo[1]);
var latlng:LatLng = new LatLng(md.lat,md.lng);
var markerOptions:MarkerOptions = new MarkerOptions();
markerOptions.icon = new dojoIcon();
var dojoMarker:Marker = new Marker(latlng,markerOptions);
map.addOverlay(dojoMarker);
var markerOptions2:MarkerOptions = new MarkerOptions();
markerOptions2.icon = new studentIcon();
var studentMarker:Marker = new Marker(latlng,markerOptions2);
map.addOverlay(studentMarker);
map.setCenter(new LatLng(dojoGeo[0],dojoGeo[1]), 11, MapType.NORMAL_MAP_TYPE);
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.addControl(new ScaleControl());
addSchoolMarker(md,dojoMarker);
addStudentsToMap();
}
And
<mx:HBox width="100%" height="100%">
<maps:Map xmlns:maps="com.google.maps.*" id="map" key="map key here" mapevent_mapready="onMapReady(event)" width="90%" height="90%" sensor="false" />
</mx:HBox>
Thanks for any help!
UPDATE: Using Firebug Developer tools, I discovered 2 errors. A CrossDomain.xml - Aborted and 404 Not Found error. Not exactly sure how to proceed with this since I don't know if these are just symptoms of whatever is causing the problem in the first place.
Well, I have to thank my co-worker for finding a solution.
The problem was a timing issue, with the API being called at the same time as the functions were running with the data to populate the map. So he suggested that the mapOnReady event shouldn't run until the other 2 functions were completed.
Hope it can help someone who runs into a similar issue.
Here's the code:
public function getGeoInfo_Handler(results):void
{
try
{
geoSchoolInfoAry = (results.getSchoolInfo.split(","));
geoInfoAC = new ArrayCollection(results.getInfo.split(";"));
remoteCallComplete=true;
loadMap();
}
catch (error:Error)
{
FlexException.errorHandler(error, "StudentPopMapModuleCode:getGeoInfoSchool_Handler");
}
}
public function onMapReady(event:MapEvent = null):void
{
mapReady=true;
loadMap();
}
private function loadMap():void
{
if(mapReady && remoteCallComplete)
{
var dojoGeo:Array = geoSchoolInfoAry;
var md:MarkerData = new MarkerData(dojoGeo[0], dojoGeo[1]);
var latlng:LatLng = new LatLng(md.lat, md.lng);
map.setCenter(new LatLng(dojoGeo[0], dojoGeo[1]), 11, MapType.NORMAL_MAP_TYPE);
map.addControl(new ZoomControl());
map.addControl(new MapTypeControl());
map.addControl(new ScaleControl());
var markerOptions:MarkerOptions = new MarkerOptions();
markerOptions.icon = new dojoIcon();
var dojoMarker:Marker = new Marker(latlng, markerOptions);
map.addOverlay(dojoMarker);
var markerOptions2:MarkerOptions = new MarkerOptions();
markerOptions2.icon = new studentIcon();
var studentMarker:Marker = new Marker(latlng, markerOptions2);
map.addOverlay(studentMarker);
addSchoolMarker(md, dojoMarker);
addStudentsToMap();
}
}
Hi I m trying to migrate a google maps V2 to google maps V3 project.
Here I m creating a prototype as below.It is in a seperate .js file other than the .js file containing function to initialize the map.
Ubicacion.prototype = new google.maps.Overlay();
Ubicacion.prototype.initialize = function(map) {
var alias_ = this.alias_;
var direccion_ = this.direccion_;
var fecha_ = this.fecha_;
var point_ = this.point_;
var tipo_ = this.tipo_;
var imagen_ = this.imagen_;
...
}
But I m getting "google.maps.Overlay is not a constructor". I understand by googling that it may be caused because initialization is happening before google maps is being loaded; and can be rectified by using google.setOnLoadCallback() for initizialising objects.But I m not very clear in using the same.
Can any one please guide me?This is very urgent.
There really is no such constructor.
I guess what you try to use should be google.maps.OverlayView
I'm developing an application that retrieves an image of "Bing Maps" with [Bing Api] since my webService.
My problem is the rendering of the image.
If I set my zoom greater than 11,or if I set a size too big, the result of recover my image is like "cut" into several loading and gives the impression that the image is not entirely downloaded.
Example picture below...
Have you any idea why the image looks like its back?
Here is my code used in my webService.
//call function
GetImageMap(46,6,800,800,17);
//Get Bing map Image from the web
public string GetImageMap(double latitude,double longitude,int mapSizeHeight, int mapSizeWidth, int zoomLevel)
{
string key = "asoidfz9aos78fa9w3hf9w3fh9hf7ha9wfw37fhblablablablablabla";
MapUriRequest mapUriRequest = new MapUriRequest();
// Set credentials using a valid Bing Maps key
mapUriRequest.Credentials = new ImageryService.Credentials();
mapUriRequest.Credentials.ApplicationId = key;
// Set the location of the requested image
mapUriRequest.Center = new ImageryService.Location();
mapUriRequest.Center.Latitude = latitude;
mapUriRequest.Center.Longitude = longitude;
// Set the map style and zoom level
MapUriOptions mapUriOptions = new MapUriOptions();
mapUriOptions.Style = MapStyle.Aerial;
mapUriOptions.ZoomLevel = zoomLevel;
mapUriOptions.PreventIconCollision = true;
// Set the size of the requested image in pixels
mapUriOptions.ImageSize = new ImageryService.SizeOfint();
mapUriOptions.ImageSize.Height = mapSizeHeight;
mapUriOptions.ImageSize.Width = mapSizeWidth;
mapUriRequest.Options = mapUriOptions;
//Make the request and return the URI
ImageryServiceClient imageryService = new ImageryServiceClient();
MapUriResponse mapUriResponse = imageryService.GetMapUri(mapUriRequest);
return mapUriResponse.Uri;
}
// ### END Function getImageMap
And the url query:
http://api.tiles.virtualearth.net/api/GetMap.ashx?c=46,6&dcl=1&w=800&h=800&b=a,mkt.en-US&z=17&token={token}
Result image.. :
It seems to be related to the aerial imagery and it's not technically related.
I will report it to the appropriate team.
By the way, you should use the REST Imagery API which is the official way to use the imagery from Bing, see the MSDN:
http://msdn.microsoft.com/en-us/library/ff701724.aspx
Here is a sample URL based on your example:
http://dev.virtualearth.net/REST/v1/Imagery/Map/Aerial/46,6/17?mapSize=800,800&key=YOURKEY
I am using Subgurim asp.net control for Google Maps in ASP.net.
The Problem is that I need to show an ARROWED POLYLINE betwwen my two points on map.
Following is my code , but unfortunately I am not able to apply anything for that:
GLatLng from = new GLatLng(FromLan, FromLon);
GLatLng To = new GLatLng(ToLan, ToLon);
GLatLngBounds llbound = new GLatLngBounds(from, To);
GMap2.GZoom = GMap2.getBoundsZoomLevel(llbound);
GMap2.setCenter(llbound.getCenter());
GLatLng inside = llbound.getCenter();
bool isInside = llbound.contains(inside);
GPolyline objpolyline = new GPolyline();
objpolyline.points.Add(from);
objpolyline.points.Add(To);
objpolyline.color = "red";
objpolyline.colorNet = System.Drawing.Color.Red;
objpolyline.clickable = false;
objpolyline.PolylineID = "Route";
objpolyline.geodesic = true;
//Javascript Code
//pts1.push (new GLatLng(lat111, lng222));
//var poly1 = new BDCCArrowedPolyline(pts1,"#FF0000",4,0.3,
// null,30,7,"#0000FF",2,0.5);
//map.addOverlay(poly1);
GMap2.addPolyline(objpolyline);
//GMap2.addPolyline(objpolyline);
Regards ,
Vishal
It looks to me like you are using the Google Maps API v2.
Two issues with that:
it is deprecated and could stop working in less than a year.
the Google Maps API v3 now supports "arrowed polylines" natively.
I'm trying to add a network link when someone clicks on a placemark that has been loaded via KML. What I do is attach an event handler to the globe and check to see if the user clicked on a placemark.
On the html, there is a button that when clicked, removes the network link from google earth when clicked (see trackRemoval). Everything seems to work the first time a placemark is clicked.
The problem is when the placemark is clicked a second time (after having the network link removed), the call to createNetworkLink fails. Attached is the relevant snippets of code.
Can someone see what I'm doing wrong?
var ge = new Array(2);
function clickHandler(event) {
if (event.getTarget().getType() == 'KmlPlacemark') {
event.preventDefault();
var placemark = event.getTarget();
var device = placemark.getName();
var networkLink = ge[0].createNetworkLink(device + "link");
var link = ge[0].createLink("");
networkLink.setDescription("Vechicle view for" + device);
networkLink.setName("Track for " + device);
networkLink.setFlyToView(true);
link.setHref("http://x.x.x.x/blah/blah.kml");
link.setRefreshMode(ge[0].REFRESH_ON_INTERVAL);
link.setRefreshInterval(60);
networkLink.setLink(link);
ge[0].getGlobe().getFeatures().appendChild(networkLink);
}
}
function initgeaor(instance) {
google.earth.addEventListener(instance.getGlobe(), 'click', clickHandler);
}
function trackRemoval() {
var device = this.name;
var networklink = ge[0].getElementById(device + "link");
ge[0].getGlobe().getFeatures().removeChild(networklink);
}
See https://developers.google.com/earth/documentation/reference/interface_kml_object
See the note on the method release(). From my experience this "indeterminate amount of time" is difficult to gauge. So if you remove an object from GE, and then try to add another object with the same id, GE complains and won't create the object - unless that 'indeterminate amount of time' has passed.
You may be able to use a timer after you removeChild() and release() the network link.
You could also give your new KmlNetworkLink a different id each time you create it so there's no collision. I'm not sure if this is an option for you. var networkLink = ge[0].createNetworkLink(device + "link" + idNumber);