Closed rplkabir closed 5 years ago
Hi there,
Further to @cloudwales answer, the following also works:
Mapper::map(-1.11111, 11.11111,[
'markers' => [
'symbol' => 'circle',
'icon' => /path/to/your/icon.png'',
'animation' => 'DROP'
],
]);
We are experiencing a similar issue. No matter what we do, we can't get custom icons to show up on the map. Any help would be greatly appreciated.
`Mapper::map($mapLat, $mapLon, [ 'zoom' => $mapZoom, 'scrollWheelZoom' => false, 'cluster' => false, 'async' => false, 'marker' => false, 'fullscreenControl' => false, 'streetViewControl' => false, 'mapTypeControl' => false, 'center' => $centerMap ]);
foreach ($this->centers as $trialCenter) { $content = view('centers.shared.map.information_window') ->with('center', $trialCenter->center) ->render();
Mapper::informationWindow($trialCenter->center->lat, $trialCenter->center->lon, $content, [
'open' => false,
'marker' => true,
'markers' => [
'symbol' => 'circle',
'icon' => asset('img/maps/blue-pin.png'),
'autoClose' => true
],
]);
}`
And the icon is always blank.
Thanks!
Hi @sparkcures, move the items from within the "markers" array to base array. Alternatively move the markers array into the map array.
Mapper::informationWindow($trialCenter->center->lat, $trialCenter->center->lon, $content, [
'open' => false,
'marker' => true,
'symbol' => 'circle',
'icon' => asset('img/maps/blue-pin.png'),
'autoClose' => true
]);
}
Perfect! Thank you.
I am using version 3. with Laravel 8 and also could not render with icon
as string
. The reason for my error I previously stated is incorrect. The code base has changed but it is the the other way around. My confusion is due to me not publishing the new versions views and using the old versions views on top of the new version 3.. In previous versions the icon
key accepted an array
with two keys nl. string
url
and array
size
i.e.
Mapper::informationWindow($trialCenter->center->lat, $trialCenter->center->lon, $content, [
'open' => false,
'marker' => true,
'icon' => [
'url' => asset('img/maps/blue-pin.png'),
'size' => [58,88], // width,height
],
'autoClose' => true
]);
}
In version 3.* the icon
array is assessed in a blade @switch
, but the url
is defaulted while symbol
resides within the icon
array and IF you do not set url
and scaledSize
of the icon
array the icons do not render, unless you set icon
as string:
@if (isset($options['icon']))
icon: @if (is_array($options['icon']))
{
@foreach ($options['icon'] as $key => $value)
@switch($key)
@case('symbol')
path: google.maps.SymbolPath.{!! $value !!},
@break;
@case('size')
@case('scaledSize')
@if (is_array($value))
{!! $key !!}: new google.maps.Size({!! $value[0] !!}, {!! $value[1] !!}),
@else
{!! $key !!}: new google.maps.Size({!! $value !!}, {!! $value !!}),
@endif
@break;
@case('anchor')
@case('origin')
@case('labelOrigin')
@if (is_array($value))
{!! $key !!}: new google.maps.Point({!! $value[0] !!}, {!! $value[1] !!}),
@else
{!! $key !!}: new google.maps.Point({!! $value !!}, {!! $value !!}),
@endif
@break;
@case('fillOpacity')
@case('rotation')
@case('scale')
@case('strokeOpacity')
@case('strokeWeight')
{!! $key !!}: {!! json_encode((int) $value) !!},
@break
@default
{!! $key !!}: {!! json_encode((string) $value) !!},
@break
@endswitch
@endforeach
}
@else
{!! json_encode((string) $options['icon']) !!}
@endif
@endif
In previous version this was true:
BUT, DO NOT set the symbol
key with icon
key. This is very important, the code excludes the icon
key if symbol
is set. If symbol
is set the scale
key should be set. No symbol
it looks for icon
. Here is a snippet of the marker.blade
that renders the map.
@if ($options['symbol'])
icon: {
path: google.maps.SymbolPath.{!! $options['symbol'] !!},
scale: {!! $options['scale'] !!}
}
@else
icon:
@if (is_array($options['icon']) && isset($options['icon']['url']))
{
url: {!! json_encode((string) $options['icon']['url']) !!},
@if (isset($options['icon']['size']))
@if (is_array($options['icon']['size']))
scaledSize: new google.maps.Size({!! $options['icon']['size'][0] !!}, {!! $options['icon']['size'][1] !!})
@else
scaledSize: new google.maps.Size({!! $options['icon']['size'] !!}, {!! $options['icon']['size'] !!})
@endif
@endif
}
Hope this helps...