How can I pan to a new lonlat if the new lonlat is out the current extent?
thanks,
Ayhan
How can I pan to a new lonlat if the new lonlat is out the current extent?
thanks,
Ayhan
Ayhan,
To pan to a specific location, you can pan manually by clicking on the map and holding while dragging as you can do with all the maps as is. And you just pan to the desired location. Or you can center the map to the specific location using the CenterAt function passing the Longitude and the Latitude as you can see in the code below.
double Longitude = 90;
double Latitude = 30;
Map1.CenterAt(Longitude, Latitude);
Of course, this is assuming that your map is in Decimal Degrees (Long/Lat) . If it is in another unit and projection, we will need to do some projection operation. If this is the case, you will need to tell us in more detail about your case.
Val,
we are using GeographyUnit.Meter and DistanceUnit.Meter. I am trying to do this with javascript. the code is below
for (var i = 0; i < markers.markers.length; i++) {
if (markers.markers[i].id == document.getElementById("cboxArac").value) {
try {
oldSize = markers.markers[i].icon.size;
newSize = new OpenLayers.Size(40, 40);
var Lonlat = markers.markers[i].lonlat;
_icon = markers.markers[i].icon;
tgMap.panTo(Lonlat);// here that I want to pan to new lonlat. if it is in current extend it works if not does not work.
break;
}
catch (err) {
alert(err);
break;
}
}
}
thanks,
Ayhan.
Hi, Ayhan
The way you did was right, you just need to change one place, use the PanToWorldCoordinate function instead of panTo function. Please see the code below:
for (var i = 0; i < markers.markers.length; i++) {
if (markers.markers.id == document.getElementById("cboxArac").value) {
try {
oldSize = markers.markers.icon.size;
newSize = new OpenLayers.Size(40, 40);
var Lonlat = markers.markers.lonlat;
_icon = markers.markers.icon;
Map1.PanToWorldCoordinate(Lonlat.lon, Lonlat.lat);
// here that I want to pan to new lonlat. if it is in current extend it works if not does not work.
break;
}
catch (err) {
alert(err);
break;
}
}
}
If you have more requirements, please tell me.
Thanks,
James
James,
still does not pan to the lonlat where it is out of current extend. I use inMemoryMarkerOverlay to add the markes on map, can be from InMemoryMarkerOverlay?
thanks,
Ayhan
Ayhan,
Does the map pan at all or what happens when the the long/lat is outside of the current extent?
I’m actually surprised you can get the lon/lat of the market on the client side if it’s outside of the extent (I haven’t tested to see if this is the case or not). Can you verify with an alert box that you are getting a valid long/lat for the marker that is outside of the extent?
Thanks!
James,
I send you a video file (MP4) via Support@thinkgeo.com. look at that video please.
thanks,
Ayhan
James, Did you received the video file?
Ayhan
Hi, Ayhan
Sorry for delay, this mistake was because you can’t get your marker when it’s outside the current extent.
markers = tgMap.getLayer('MarkerOverlay')
You can check your markers, you can’t find the marker which you want to use.
One way of solution this problem is that you can have a collection to save all of your marker’s lonlat, when you click the combobox, just get the lonlat value and use:
Map1.PanToWorldCoordinate(Lonlat.lon, Lonlat.lat);
Any more questions please feel free to let me know.
Thanks,
James