简体   繁体   English

将自定义地图样式添加到jQuery Store Locator插件

[英]Adding Custom Map Styles to jQuery Store Locator Plugin

I'm working on a store locator for a client site that uses the jQuery Store Locator plugin ( https://github.com/bjorn2404/jQuery-Store-Locator-Plugin ). 我正在为使用jQuery Store Locator插件( https://github.com/bjorn2404/jQuery-Store-Locator-Plugin )的客户端站点的商店定位器工作。

I'm trying to incorporate some custom map styles: 我正在尝试合并一些自定义地图样式:

stylers: [
    { 'saturation': '-62' },
    { 'gamma': '0.5' }
  ]

I thought I could put them into the mapSettings parameter, but they're not being recognized. 我以为我可以将它们放入mapSettings参数中,但是它们未被识别。 I've tried every bracket variation I can think of, to no avail. 我尝试了所有我能想到的方括号变体,但均无济于事。

I'm thinking now that I need to go into the jquery.storelocator.js, and add it there, but I'm having trouble finding where to put it (if that's even the best solution). 我现在在想,我需要进入jquery.storelocator.js并将其添加到其中,但是我很难找到放置它的位置(即使那是最好的解决方案)。

Any ideas? 有任何想法吗?

UPDATE Here is the code as I have tried to implement it: 更新以下是我尝试实现的代码:

<script>
$(function() {
    $('#map-container').storeLocator({
        'dataType': 'json',
        'dataLocation': '/data/locations.php',
        'slideMap' : true,
        'mapSettings' : { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP, stylers : [{'saturation' :'-62'}] }
    });
});
</script>

You can make an array eg gmapStyles containing styles for map and call it in mapSettings object. 您可以创建一个包含gmap样式的数组,例如gmapStyles,然后在mapSettings对象中调用它。 Look at the gmapStyles array in below function. 查看下面函数中的gmapStyles数组。 and My map is looking like this http://voddemo.akkastech.com/category/2 我的地图看起来像这样http://voddemo.akkastech.com/category/2

<script>
    function newStoreLocatorInit(element= jQuery('#bh-sl-map-container'), type, ls){
        if(element.length > 0){
            var gmapStyles = [
                {"elementType": "labels","stylers": [{"visibility": "off"}]},
                {"featureType": "administrative","elementType": "geometry","stylers": [{"visibility": "off"}]},
                {"featureType": "administrative.land_parcel","stylers": [{"visibility": "off"}]},
                {"featureType": "administrative.land_parcel", "elementType": "geometry", "stylers": [{"color": "#ee99e6"}]},
                {"featureType": "administrative.neighborhood","stylers": [{"visibility": "off"}]},
                {"featureType": "landscape.man_made","elementType": "geometry","stylers": [{"color": "#dfe4e6"}]},
                {"featureType": "poi","stylers": [{"visibility": "off"} ] },
                {"featureType": "poi.park", "elementType": "geometry", "stylers": [{"color": "#a0ec96"}]},
                {"featureType": "road", "elementType": "geometry", "stylers": [{"color": "#bdc3cb"}]},
                {"featureType": "road", "elementType": "labels.icon", "stylers": [{"visibility": "off"}]},
                {"featureType": "transit", "stylers": [{"visibility": "off"}]}
            ];
            element.storeLocator({
                callbackSuccess         : function(){
                    jQuery('.at-dataloader').fadeOut(300);
                    jQuery('.bh-sl-loc-list .list').fadeIn(300);
                },
                'infowindowTemplatePath'     : '/assets/js/plugins/storeLocator/templates/infowindow-description.html',
                'listTemplatePath'           : '/assets/js/plugins/storeLocator/templates/location-list-description.html',
                taxonomyFilters : {
                    'name':'name-filter',
                    'subcategoryname':'subcategoryname-filter',
                    'location':'location-filter',
                    'subcategoryid':'subcategoryid-filter'
                },
                /*distanceAlert: -1,*/
//                    querystringParams : true,
//                    fullMapStart:true,
                disableAlphaMarkers         : true,
                dataType                    : 'json',
                slideMap                    : false,
                defaultLoc                  : true,
                defaultLat                  : '44.9207462',
                defaultLng                  : '-93.3935366',
                visibleMarkersList          : false,
                listColor1                  : '',
                listColor2                  : '',
                /*maxDistance                 : false,*/
                markerCluster               : type != "true" ? {
                    zoomOnClick             : true,
                    styles                  : [{
                        width               : 40,
                        height              : 40,
                        textSize            : 14,
                        anchor              : [60, 42],
                        textColor           : '#fff',
                        backgroundSize      : 'cover',
                        backgroundPosition  : 'top, center',
                        cssClass            : 'at-iconcluster',
                        url                 : '/images/svg/iconcluster.svg',
                    }]
                } : null,
                mapSettings                 : {
                    zoom                    : 11,
                    disableDefaultUI        : true,
                    zoomControl             : true,
                    styles                  : gmapStyles,
                    mapTypeId               : google.maps.MapTypeId.ROADMAP,
//                        minZoom                    : 10,
//                        maxZoom                    : 12,
                },
                dataLocation                : ls ,
                // dataLocation             : '/data/locations.json' ,
                markerImg                   : '/images/svg/icon01.svg',
                markerDim                   : {
                    width: 36,
                    height: 45
                },
                selectedMarkerImg           : '/images/svg/icon02.svg',
                selectedMarkerImgDim        : {
                    width: 36,
                    height: 45
                },
                infoBubble: {
                    backgroundColor         : '#fff',
                    borderRadius            : 0,
                    borderWidth             : 0,
                    closeSrc                : '/assets/img/close-icon-dark.png',
                    disableAutoPan          : false,
                    shadowStyle             : 0,
                    padding                 : 0,
                    minWidth                : 370,
                    maxHeight               : 162,
                    backgroundClassName     : 'bh-sl-window',
                },
                callbackMapSet              : function(){

                },
                callbackMarkerClick     : function(){
                    setTimeout(function(){
                        ajaxCallsOnPopupNavBtnClick()
                        jQuery(".at-btnthemecontent").animatedModal({
                            color: 'rgba(222, 226, 228, 0.85)',
                            modalTarget:'at-themecontent',
                            animatedOut:'zoomOut',
                            animatedIn:'zoomIn',
                        });
                        jQuery('.at-btnthemecontent').on('click', function(){
                            jQuery('.at-mlogo').addClass('at-hideui');
                            jQuery('.at-sidebar').addClass('at-hideui');
                            jQuery('.at-toprightbox').addClass('at-hideui');
                            jQuery('.gmnoprint.gm-bundled-control').addClass('at-hideui');
                            jQuery('.at-btnfindoutmore').addClass('at-hideui');
                        });
                        jQuery('.close-at-themecontent.at-btnclose').on('click', function(){
                            jQuery('.at-mlogo').removeClass('at-hideui');
                            jQuery('.at-sidebar').removeClass('at-hideui');
                            jQuery('.at-toprightbox').removeClass('at-hideui');
                            jQuery('.gmnoprint.gm-bundled-control').removeClass('at-hideui');
                            jQuery('.at-btnfindoutmore').removeClass('at-hideui');
                        });
                    }, 1000)
                },
                callbackListClick       : function(){
                    setTimeout(function(){
                        ajaxCallsOnPopupNavBtnClick()
                        jQuery(".at-btnthemecontent").animatedModal({
                            color: 'rgba(222, 226, 228, 0.85)',
                            modalTarget:'at-themecontent',
                            animatedOut:'zoomOut',
                            animatedIn:'zoomIn',
                        });
                        jQuery('.at-btnthemecontent').on('click', function(){
                            jQuery('.at-mlogo').addClass('at-hideui');
                            jQuery('.at-sidebar').addClass('at-hideui');
                            jQuery('.at-toprightbox').addClass('at-hideui');
                            jQuery('.gmnoprint.gm-bundled-control').addClass('at-hideui');
                            jQuery('.at-btnfindoutmore').addClass('at-hideui');
                        });
                        jQuery('.close-at-themecontent.at-btnclose').on('click', function(){
                            jQuery('.at-mlogo').removeClass('at-hideui');
                            jQuery('.at-sidebar').removeClass('at-hideui');
                            jQuery('.at-toprightbox').removeClass('at-hideui');
                            jQuery('.gmnoprint.gm-bundled-control').removeClass('at-hideui');
                            jQuery('.at-btnfindoutmore').removeClass('at-hideui');
                        });
                    }, 1000)
                },
                callbackNoResults : function(){
                    alert('No locations were found with the given criteria. Please modify your selections or input.')
                },
                callbackFilters : function(){

                }

            });
        }
    }

The MapOption for setting the map style is styles , not stylers . 用于设置地图样式的MapOptionstyles ,而不是stylers Change: 更改:

$(function() {
    $('#map-container').storeLocator({
        'dataType': 'json',
        'dataLocation': '/data/locations.php',
        'slideMap' : true,
        'mapSettings' : { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP, stylers : [{'saturation' :'-62'}] }
    });
});

To: 至:

$(function() {
    $('#map-container').storeLocator({
        'dataType': 'json',
        'dataLocation': '/data/locations.php',
        'slideMap' : true,
        'mapSettings' : { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP, styles : [{stylers : [{'saturation' :'-62'}]}] }
    });
});

The answer turned out to be a syntax issue, after all. 答案毕竟是语法问题。 The mapSettings property is passed to the MapOptions class, and requires both the styles and stylers parameters: mapSettings属性传递给MapOptions类,并且需要style stylers参数:

'mapSettings' : { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP, styles : [{stylers: [{'saturation' :'-62'}]}] }

Inside the styles bracket, you can add as many custom settings as you like, so long as you use the stylers parameter as well: 在样式支架内,您可以添加任意数量的自定义设置,只要您也使用stylers参数即可:

'mapSettings' : { zoom : 12, mapTypeId: google.maps.MapTypeId.ROADMAP, styles : [
            {
                "featureType": "landscape",
                "stylers": [
                  { "saturation": -74 },
                  { "lightness": 82 },
                  { "gamma": 1.18 },
                  { "color": "#eleff2" }
                ]
            },{
                "featureType": "water",
                "stylers": [
                  { "saturation": -49 },
                  { "color": "#eleff2" },
                  { "lightness": -1 },
                  { "gamma": 1 }
                ]
            },{
                "featureType": "road",
                "stylers": [
                  { "hue": "#0099ff" },
                  { "lightness": 4 },
                  { "saturation": -78 }
                ]
            },{
                "featureType": "poi",
                "stylers": [
                  { "hue": "#0099ff" },
                  { "saturation": -38 },
                  { "lightness": 67 }
                ]
              }
            ] }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM