hi,
i am using Map Suite Mvc Edition . I am try to set Default CustomOverlays
{
overlays.LayerOverlay("WordMap").Layer(wordmap).IsBaseOverlay(false);
overlays.LayerOverlay("GoogleMap").Layer(googlelayer).IsBaseOverlay(false);
overlays.LayerOverlay("OpenStreetMap").Layer(openstreetmap).IsBaseOverlay(false);
overlays.LayerOverlay("BingMap").Layer(bingmap).IsBaseOverlay(false);
overlays.YahooOverlay("YahooMap").YahooMapType(YahooMapType.Regular).IsBaseOverlay(true).JavaScriptLibraryUri(new Uri(ConfigurationManager.AppSettings["YahooUri"]));
overlays.GoogleOverlay("Google Satellite Map").GoogleMapType(GoogleMapType.Hybrid).IsBaseOverlay(false);
}
I want to set Default LayerOverlay When user select any map that should be set as default when page load
How to Set default LayerOverlay when page load
Hi Pankit,
Do you meant you want to switch default base overlay when you click on the OverlaySwitch?
If so you can view our BackgroundMap HowDoISample, it should be helpful for that.
Regards,
Don
I want to set some thing like
overlays.LayerOverlay("OpenStreetMap").Layer(openstreetmap).IsBaseOverlay(false).Setdefault(true);
when page is load I want to set OpenStreetMap is seleted is there any method like Setdefault(true) or somthing
I want to set as default when i select any map . Like when i select the yahoo map overlays then when i go to next page where map should be open as yahoo means session should be maintain when i select any map in all pages.
I hope you get question!!
Hi Pankit,
In Map Suite Web/Mvc Edition, the IsBaseOverlay property is used to set the default base layer for the map and each map only one Overlay can be assign as baseOverlay. For instance, once we set the openstreetmap as baseoverlay, then the other overlays like Google, Bing etc should set as false on its IsBaseOverlay property.
Since you just want to set the default layer when the page load, using the below codes should be fine:
{
overlays.LayerOverlay(“WordMap”).Layer(wordmap).IsBaseOverlay(false);
overlays.LayerOverlay(“GoogleMap”).Layer(googlelayer).IsBaseOverlay(false);
overlays.LayerOverlay(“OpenStreetMap”).Layer(openstreetmap).IsBaseOverlay(True);
overlays.LayerOverlay(“BingMap”).Layer(bingmap).IsBaseOverlay(false);
overlays.YahooOverlay(“YahooMap”).YahooMapType(YahooMapType.Regular).IsBaseOverlay(false).JavaScriptLibraryUri(new Uri(ConfigurationManager.AppSettings[“YahooUri”]));
overlays.GoogleOverlay(“Google Satellite Map”).GoogleMapType(GoogleMapType.Hybrid).IsBaseOverlay(false);
}
Any questions don’t hesitate to let us know.
Thanks,
Troy
hi,
when i set it false it also remove from list please check the screen short with code and out put
Hi Pankit,
Sorry to see the screenshots looks indistinct, would you please attached it again and also please give us more details on your issue? Does you mean you still want the layers which are marked invisibility in the SwitcherTool and keep them with unchecked so that you can make them visible after you check it?
Thanks,
Troy
Hello,
when i select any of this overlays from list redo-buttons that should bee selected after post back
overlays.LayerOverlay(“WordMap”).Layer(wordmap).IsBaseOverlay(true).IsVisible(false);
overlays.LayerOverlay(“GoogleMap”).Layer(googlelayer).IsBaseOverlay(true).IsVisible(false);
overlays.LayerOverlay(“OpenStreetMap”).Layer(openstreetmap).IsBaseOverlay(true).IsVisible(false);
overlays.GoogleOverlay(“Google Satellite Map”).GoogleMapType(GoogleMapType.Hybrid).IsBaseOverlay(true);
Hi Pankit,
Would you please try the below codes to see if it is fit for you?
Razor:
<
script
language
=
“javascript”
type
=
“text/javascript”
>
function baselayerChanged(newlayer) {
Map1.ajaxCallAction(’@ViewContext.RouteData.Values[“Controller”].ToString()’, ‘ChangeBaseLayer’, { ‘baselayerid’: newlayer.baseLayer }, function () { });
}
function OnMapCreated(Map) {
var baseLayerID = ‘@Session[“baselayerid”]’;
var map = Map.getOpenLayersMap();
var baseLayer = map.getLayer(baseLayerID);
map.setBaseLayer(baseLayer);
}
</
script
>
<
div
class
=
“twelve columns”
id
=
“main”
>
<
div
id
=
“map”
>
@{
string baseLayerID = Session[“baselayerid”].ToString();
Html.ThinkGeo().Map(“Map1”, new System.Web.UI.WebControls.Unit(100, System.Web.UI.WebControls.UnitType.Percentage), 510)
.CurrentExtent(-14639183.0384644, 7524757.1810634, -7399085.82811318, 2358849.98232628)
.MapUnit(GeographyUnit.Meter)
.MapTools(mapTools =>
{
mapTools.OverlaySwitcherMapTool().Enabled(true);
mapTools.PanZoomBarMapTool().Enabled(true);
})
.OnClientBaseOverlayChanged(“baselayerChanged”)
.CustomOverlays(overlays =>
{
WorldMapKitLayer wordmap = new WorldMapKitLayer() { Projection = WorldMapKitProjection.SphericalMercator };
GoogleMapsLayer googlelayer = new GoogleMapsLayer();
OpenStreetMapLayer openstreetmap = new OpenStreetMapLayer();
overlays.LayerOverlay(“WordMap”).Layer(wordmap).IsBaseOverlay(true).IsVisible(true);
overlays.LayerOverlay(“GoogleMap”).Layer(googlelayer).IsBaseOverlay(true).IsVisible(true);
overlays.LayerOverlay(“OpenStreetMap”).Layer(openstreetmap).IsBaseOverlay(true).IsVisible(true);
overlays.GoogleOverlay(“Google Satellite Map”).GoogleMapType(GoogleMapType.Hybrid).IsBaseOverlay(true);
}
)
.Render();}
</
div
>
</
div
>
Controller:
public ActionResult DisplayASimpleMap()
{
if (Session[“baselayerid”] == null)
{
Session[“baselayerid”] = “GoogleMap”;
}
return View();
}
[MapActionFilter]
public void ClickEvent(Map map, GeoCollection<
object
> args)
{
PointShape position = new PointShape(Convert.ToDouble(args[0]), Convert.ToDouble(args[1]));
}
[MapActionFilter]
public void ChangeBaseLayer(GeoCollection<
object
> args)
{
Session[“baselayerid”] = args[0].ToString();
}
Hope it helps.
Thanks,
Troy
Hello,
I am getting error getOpenLayersMap is not a Function , i am using MapSuiteCore.dll(7.0.0.0),MVCEdition.dll(7.0.0.0)
Hi Pankit,
I’m sorry I didn’t test it in Map Suite 7.0. Would you please replace the Javascript codes below and have another try?
function
baselayerChanged(newlayer) {
if
(Map1.ajaxCallAction)
Map1.ajaxCallAction(
’@ViewContext.RouteData.Values[“Controller”].ToString()’
,
‘ChangeBaseLayer’
, {
‘baselayerid’
: newlayer.baseLayer },
function
() { });
}
function
OnMapCreated(map) {
var
baseLayerID =
‘@Session[“baselayerid”]’
;
var
baseLayer = map.getLayer(baseLayerID);
map.setBaseLayer(baseLayer);
}
If the issue still persist please feel free to let us know.
Regards,
Troy