5

I figured it out, didn't realise all I had to do was pass array like so: $entry->getContent()->address = array('lat' => $lat, 'lng' => $lng, 'street1' => $street1, 'zip' => $postcode);


5

Yes, it's definitely possible to cluster your markers with Smart Map. In fact, anything that you can do with the Google Maps API can also be done with Smart Map: Manipulating the map in JavaScript I'd recommend adding the Marker Clusterer JS library to your project.


5

You can only modify a craft.entries criteria model with a field (→ Add custom element criteria attribute without a field type?). So what you have to do is to create a new custom field type with your plugin, and add such a field to the entry types you want to filter. {% set entries = craft.entries.section('mySection').country('germany') %} With that ...


5

So for starters, let's clear something up for anyone visiting this thread: We're talking about JavaScript... specifically, how to manipulate a map that has already been generated. The official documentation on what kind of variables (maps/markers/info bubbles) which are created by the plugin can be found here... Beyond that, you can basically do anything ...


5

What I've done to do something very similar is to add a template variable to my BusinessLogic plugin, that takes the ElementCriteriaModel, prepared with all other parameters e.g. section, limit and SmartMap set. The plugin then translates the model into a Yii CDbCommand using buildElementsQuery, adds the additional conditions to the query and returns the ...


4

That's a tricky one... Natively, all of the options are applied to all markers equally. But you can do a little workaround using something like this pseudo-code: {% set markerIconJs %} // On page load $(function () { {% for entry in locations %} {% if entry.lightswitch %} // JavaScript: Override the default icon with ...


4

You're very close! $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->myFieldHandle = array( 'target' => 90210, 'range' => 100 ); $criteria->order = 'distance'; $results = $criteria->find(); I've never actually tested it with the Element API plugin, but in theory it should work just fine. In response ...


4

You would need to setup two criteria models, one for each Smart Map field, and query for the element IDs. Merge these IDs and have a 3rd criteria model where you pass in the IDs to the id parameter. See this question for example code: Complex logic on a ElementCriteriaModel parameter? Here's a blog post describing the technique in details: ...


4

I'd recommend loading your JS file after the smartmap.js file has been loaded. The smartMap JS object needs to exist before your code gets run. Try loading your JS using the includeJsFile tag... I believe that should place it in the correct position. {% includeJsFile "/assets/js/app.min.js" %} If that doesn't work, then you may need to wrap your code in ...


4

Author of Smart Map here... It sounds like your locations are in a section (a Structure is a type of section). The first line of your solution is exactly what you'd need to get the locations value. {% set locations = craft.entries.section('locations').limit(null) %} {{ craft.smartMap.map(locations) }} Just to clarify... Are you using the "Address (Smart ...


4

At the moment, there's no in-plugin way to handle this. However, you can probably do it out-of-plugin, once you've retrieved a larger set of results. So first, you'd get the largest possible results set: {% set params = { target: targetLocation, range: 10000, units: 'kilometers' } %} {% set entries = craft.entries.myFieldHandle(params).order(...


4

Turns out my code was pretty much working but there was another issue in there that was stopping the map marker updating. I've since resolved it. The original form is huge so here's a cut down snippet of the part that does the marker update in case anyone needs it. This cut-down version isn't tested but should be good. Incidentally, the "parent element ID" ...


4

Not sure if I totally got it but you can check the class of an object via {% if element is instance of ('craft\\elements\\Entry') %} or via switch statement {% switch className(element) %} {% case 'craft\\elements\\Entry' %}


3

According to the docs, locations has to be an array of elements or an ElementCriteriaModel if you want to display multiple markers. {% set mapEntries = craft.entries.section('markets') %} {{ craft.smartMap.map(mapEntries, options) }}


3

Smart Map can indeed do this! It's currently an undocumented feature, because I wasn't sure if/how it was going to evolve over time. However, that feature has changed very little over the past two years, so perhaps it's time to finally document it. :) UPDATE: As of Smart Map 2.3, this is now a publicly documented feature.


3

Being that the smartMapField attribute belongs to entries in the Property section, and not the entries in the Unit section, your current element criteria is a bit off (it basically assumes that the smartMapField property is found on the Unit entry models). Basically, you'll need two element criterias to accomplish what you want. The first criteria will ...


3

OK So without being too verbose about this, here is how I managed to attach information to each marker. It is important to remember that each marker has an ID which corresponds to the entry / user that it is derived from. Using javascript, I created a small function that when given a numeric ID, it creates the smartmap ID by prepending adn appending ...


3

You'd actually need to retrieve all of the entries to count them in this way. Once you've got the complete collection, it would simply be a matter of looping through them and adding everything up. 1. Get all entries in California. {% set params = { filter: { state: 'CA' } } %} {% set meetings = craft.entries.address(params).all() %} 2. ...


3

As Jalen mentioned in his answer, this functionality isn't (currently) built into Smart Map. However, it's very easy to add yourself... First, need to add the MarkerClusterer library to your map page. You can link to it normally, just as you would with any other JS library. Once you've got the library installed, you'll be able to cluster your markers with ...


2

When Craft generates a “resource URL” from a front-end request, it just takes whatever the current site URL is, adds the resourceTrigger config setting (“cpresources”), and then adds the path that was passed in (“smartmap/js/smartmap.js” for example). So if your site URL is “/en”, then that’s going to be part of the resulting resource URL. As long as there’...


2

Good question... As far as I know, the plugin's resource paths should not include the localization prefix. The resources are being called via PHP in the most direct way possible: craft()->templates->includeJsResource('smartmap/js/smartmap.js'); craft()->templates->includeCssResource('smartmap/css/smartmap.css'); I'm not entirely sure, but I ...


2

UPDATE As of Smart Map 2.3.0, this is now possible! https://www.doublesecretagency.com/plugins/smart-map/docs/filtering-entries-by-subfield-value ORIGINAL Currently, this isn't possible. However, it's a popular feature request which is rising quickly on the priority list. The current workaround (as you noted) is to simply filter the results afterward.


2

The syntax to set a custom field parameter on a Matrix Block element criteria model is like so: {% set blocks = entry.myMatrixField.mySmartMapField(params) %}


2

There are actually two problems happening here... (1) For a location to appear on a map, it's critical for the latitude & longitude to be filled in. Within the UX of the Address field, this can happen a few different ways... as you mentioned, clicking "Select Address" is one of the main ways of doing so. Additionally, the address selection modal will be ...


2

You need to tell Craft to look within the Commerce section like this: {% set entries = craft.commerce.products.address(params).order('distance').find() %}


2

As Craft defaults to only returning 100 elements, setting the limit(null) parameter to the query fixed this issue. {% set locations = craft.users.group('fullMembership').limit(null) %}


2

I believe the problem is in this line of code: var markerId = 'smartmap-mapcanvas-1.{{ entry.id }}.address'; Because you're generating markers from matrix blocks, you'll need to use the block ID instead of the entry ID. In your case, that may looks something like this: var markerId = 'smartmap-mapcanvas-1.{{ item.id }}.address';


2

You'll need to add the styling via JavaScript... smartMap.map['smartmap-mapcanvas-1'].setOptions({styles: styles}); This can't currently be done in Twig, although I may explore that option in the future.


2

I fiddled around with some fields and got this working. Not sure it's the most direct way, but hey. Progress is progress :) {% set locations = craft.entries.section('locations').limit(null) %} {# Look for each campus listed #} {% for entry in craft.entries.section('campuses').limit(null) %} {% if entry.campusAddress|length %} {% set options = { ...


2

Smart Map doesn't currently support the ability to make an Address translatable. It's on the feature request list, and will be implemented at some point in the future. In the meantime, you can use static translations to handle names of common cities & countries: City: {{ entry.location.city | t }} Country: {{ entry.location.country | t }} * The t ...


Only top voted, non community-wiki answers of a minimum length are eligible