From a distance, the legalization of recreational marijuana in California can appear like a giant collective embrace of the drug by a state that is by far its largest producer and consumer. Yet the diverging paths of Oakland and Compton, two cities with histories of illicit drugs and years of aggressive law enforcement crackdowns, highlight the continued ambivalence of many Californians toward marijuana.

It is also a lesson for states and municipalities across the country that are drawn to marijuana legalization as a source of revenue and see it as an inevitability given the failure of decades of federal efforts to stamp out cannabis. National polls suggest a majority of Americans favor legalization. But opinions can diverge sharply at the local level, and there are tensions between those who want to treat it as a business and those who see it as an opportunity for social justice.

Several states, including Connecticut, Florida, New Jersey, Ohio and Pennsylvania, are drawing up or have provisions in their marijuana laws to assist communities disproportionately affected by drug interdiction efforts.

In California, Oakland led the way in framing the legalization as both an opportunity to address past injustice and as a source of revenue. Yet dozens of other cities and towns across the state — including Bakersfield, Brentwood, Chico, Irvine, Laguna Beach, Mill Valley and Palo Alto — want nothing to do with recreational marijuana sales.

Only 14 percent of California’s 482 cities and towns allow retail sales of recreational marijuana, according to Weedmaps, a website that hosts reviews of cannabis businesses. Californians may want access to a marijuana dispensary, just not necessarily down the block from them.