jmelosegui / GooglemapMvc

The control wraps Google maps API simplifying the use of Google maps in ASP.NET MVC applications.
MIT License
116 stars 61 forks source link

Toggle Layers #107

Closed khalome closed 8 years ago

khalome commented 8 years ago

I've provided two screenshot links below to give you a better idea of what I am trying to achieve.

In my application I am passing a model of storm data to the MVC map control. I can successfully plot all the data onto a single map with custom icons, info windows etc. But I would like to add the capability to toggle on and off certain markers within a specific category from the client side. For example I might want to turn on or off the tornado markers without effecting the remaining markers and posting back to the server. I know one way to do this via mvc and the google maps api would be to pass back a different model containing each category in its own list but is there a comparable way to do this with the mvc map control? FYI I have five different storm categories but they are all contained within the same db table. I would like to add five buttons to toggle the five categories on and off after the map has rendered. I can change my model if need be.

http://stormmappingdev.azurewebsites.net/images/question1.png http://stormmappingdev.azurewebsites.net/images/question2.jpg

khalome commented 8 years ago

I guess for now I could pass one of the five categories to the marker title when binding my model to the map control. From the client side event, OnMapLoad(), I can access the markers object via javascript and save to a global variable. When a user toggles a button corresponding to the marker title I could loop through the markers and turn them on or off that way I'm just curious if there would be another way of doing it..

jmelosegui commented 8 years ago

Hi @khalome ,

From what I can see, you just expose all possible solutions for your task:

Server Side

Limiting the collection on the server (based on some parameter from the client) and then passing that to the view using the model. This will involve a postback every time you want to filter out a category. Although you could use a partial view with ajax

Client Side

Just what you said :)